sql函数,其中我对另一个“where语句”中的一组数据使用“where语句”

hgqdbh6s  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(322)

我想在一行中使用两个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)

它只适用于一个和我必须使用两者或更多

disho6za

disho6za1#

与在语句中使用两个where不同,您可以使用and将条件合并到单个块中
前-

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)

相关问题