How can I do multiple counts for the same field in mysql? The code below for a single count works fine
SELECT fruit, COUNT(DISTINCT site) AS `apple` FROM grocery where fruit like '%06201%'
However, when I have tried this but I get syntax error
SELECT
SUM(fruit like '%06201%') AS `apple`,
SUM(fruit like '%02206%') AS `pears`,
FROM grocery
SELECT
SUM(fruit like '%06201%') AS `apple`,
SUM(fruit like '%02206%') AS `pears`,
^
here
FROM grocery
You have two commata, but you only need one.
Remove extra comma before FROM
SELECT
SUM(fruit like '%06201%') AS `apple`,
SUM(fruit like '%02206%') AS `pears`
FROM grocery
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.