[英]SQL COUNT() doesn't work in MySQL
SELECT person.id,
person.name,
COUNT(DISTINCT fruit.apple) AS "Red Apple",
fruit.*
FROM (SELECT *
FROM tree
ORDER BY color DESC) AS fruit
INNER JOIN person
ON fruit.id = person.id
WHERE person.name = 'John Smith'
Now, that code is working before I put in the COUNT(DISTINCT fruit.apple) AS "Apple"
. 现在,在我将COUNT(DISTINCT fruit.apple) AS "Apple"
放入之前,该代码可以正常工作。 what is wrong with that? 这有什么问题?
Thanks in advance 提前致谢
您没有group by
子句。
try this 尝试这个
SELECT person.id,
person.name,
COUNT(DISTINCT fruit.apple) AS "Red Apple",
fruit.*
FROM (SELECT *
FROM tree
ORDER BY color DESC) AS fruit
INNER JOIN people
ON fruit.id = person.id
WHERE person.name = 'John Smith'
GROUP BY fruit.apple
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.