如何在mysql中对同一个字段进行多次计数?下面的单个计数代码可以正常工作
SELECT fruit, COUNT(DISTINCT site) AS `apple` FROM grocery where fruit like '%06201%'
然而,当我尝试过这个但是我得到语法错误
SELECT
SUM(fruit like '%06201%') AS `apple`,
SUM(fruit like '%02206%') AS `pears`,
FROM grocery
答案 0 :(得分:3)
SELECT
SUM(fruit like '%06201%') AS `apple`,
SUM(fruit like '%02206%') AS `pears`,
^
here
FROM grocery
你有两个逗号,但你只需要一个。
答案 1 :(得分:1)
在FROM
SELECT
SUM(fruit like '%06201%') AS `apple`,
SUM(fruit like '%02206%') AS `pears`
FROM grocery