SELECT count(b.category) FROM ods_bill_foo d AS a LEFT JOIN manual_food_category AS b ON a.foodName = b.foodName WHERE b.category = ( '主食' AND '烧烤' AND '小菜' AND '小吃' AND '饮品' AND '卤味' ) AND a.reportdate BETWEEN '2023-04-01' AND '2023-04-02' HAVING count( b.category ) = 1 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS a LEFT JOIN manual_food_category AS b ON a.foodName = b.foodName WHERE b.c' at line 4 时间: 0.017s
时间: 2024-03-20 20:40:53 浏览: 51
根据你提供的 SQL 语句,我发现有一个语法错误。在 where 子句中,不能使用多个 AND 来判断一个字段是否等于多个值。正确的写法应该是使用 IN 或者多个 OR 来进行判断,例如:
```
SELECT COUNT(b.category)
FROM ods_bill_foo AS a
LEFT JOIN manual_food_category AS b ON a.foodName = b.foodName
WHERE b.category IN ('主食', '烧烤', '小菜', '小吃', '饮品', '卤味')
AND a.reportdate BETWEEN '2023-04-01' AND '2023-04-02'
HAVING COUNT(b.category) = 1
```
或者
```
SELECT COUNT(b.category)
FROM ods_bill_foo AS a
LEFT JOIN manual_food_category AS b ON a.foodName = b.foodName
WHERE (b.category = '主食' OR b.category = '烧烤' OR b.category = '小菜' OR b.category = '小吃' OR b.category = '饮品' OR b.category = '卤味')
AND a.reportdate BETWEEN '2023-04-01' AND '2023-04-02'
HAVING COUNT(b.category) = 1
```
希望能够帮助到你。
阅读全文