我试图从5个类别的SQL中的两个连接表中访问详细信息,其中一个我需要运行COUNT函数。我能够访问细节,直到我运行计数功能,之后我只能使用一个结果。我也尝试使用COUNT(*)作为... - 但这没有用。代码如下:
SELECT name, location, grade_1996, COUNT(voter_id)
FROM votes
JOIN congress_members
ON congress_members.id=politician_id
WHERE grade_current < 9;
请帮助,谢谢。
答案 0 :(得分:1)
您需要group by
。也许这就是你想要的:
SELECT name, location, grade_1996, COUNT(voter_id)
FROM votes JOIN
congress_members
ON congress_members.id=politician_id
WHERE grade_current < 9
GROUP BY name, location, grade_1996;
答案 1 :(得分:0)
您缺少GROUP BY
子句:
select name,
location,
grade_1996,
COUNT(voter_id)
from votes
join congress_members on congress_members.id = politician_id
where grade_current < 9
group by name,
location,
grade_1996;