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'
现在,在我放入COUNT(DISTINCT fruit.apple) AS "Apple"
之前,该代码正在运行。这有什么问题?
提前致谢
答案 0 :(得分:4)
您没有group by
条款。
答案 1 :(得分:0)
试试这个
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