Sql 函数,我在另一个“where 语句”中对一组数据使用“where 语句”

Posted

技术标签:

【中文标题】Sql 函数,我在另一个“where 语句”中对一组数据使用“where 语句”【英文标题】:Sql function where I use "where statement" for a group of data in an other "where statement" 【发布时间】:2019-03-19 10:18:26 【问题描述】:

我想连续使用两个 where in 语句,我得到了这个

"""
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your mysql server version for ▶
                    `reference`.`id` as `reference_id`, `model`.`name` as `model_name`, `brand`.`name` as `brand_name`,\n
                    `target`, `case_form_factor`, `case_diameter`, `case_material`,`brand_appeal`,`editor_notation`,\n
                    `social_popularity`, `dial_color`, `strap_material`, `kind_of_movement`, `complications_level`,`women_size`,`men_size`,\n
                    `grande_complication`, `complications`, `style`, `user_style`, `price`,\n
\n
                    CONCAT("https://askme.watch/watch/detail/", `reference`.`id`) as `link`,\n
                    CASE WHEN INSTR(`watch`.`photos`, ",") > 0 THEN\n
                        SUBSTRING(`watch`.`photos`, 1, INSTR(`watch`.`photos`, ",") - 1)\n
                    ELSE\n
                        `watch`.`photos`\n
                    END  as `photo`\n
                FROM\n
                    `reference` INNER JOIN watch ON reference.`id` = watch.`ref_id_internal`\n
                    LEFT JOIN `model` ON `reference`.`model_id` = `model`.`id`\n
                    LEFT JOIN `collection` ON `model`.`collection_id` = `collection`.`id`\n
                    LEFT JOIN `brand` ON `collection`.`brand_id` = `brand`.`id`\n
                WHERE `dial_color` IN ("blue","black") WHERE `kind_of_movement` IN ("Self-Winding","Manual Winding") AND `target` = "Men" AND `price` != 0 AND `price` IS NOT NULL ORDER BY RAND() LIMIT 10)

它只适用于一个,我必须同时使用两个或多个

【问题讨论】:

请发布实际的源查询,而不是错误消息中的格式化版本。 【参考方案1】:

您可以使用 AND 将条件合并到一个块中,而不是在语句中使用两个 where

前-

WHERE `dial_color` IN ("blue","black") AND `kind_of_movement` IN ("Self-Winding","Manual Winding") AND `target` = "Men" AND `price` != 0 AND `price` IS NOT NULL ORDER BY RAND() LIMIT 10)

【讨论】:

以上是关于Sql 函数,我在另一个“where 语句”中对一组数据使用“where 语句”的主要内容,如果未能解决你的问题,请参考以下文章

在另一个 where 语句(子查询?)中使用一个 sql 查询的结果

SQL中只要用到聚合函数就一定要用到group by 吗?

WHERE 语句在应该更新数据的 SQL 中不起作用[关闭]

如何使用 HIVE 在 WHERE 语句中对 OR 子句进行分组

sql语句有关where,group by,having的问题

在一列中对具有相同数据的行进行分组,并将其相关数据汇总在另一列中 [ORACLE SQL]