简体   繁体   中英

Using COUNT in SQLite3

I am trying to access the details from two joined tables in SQL of 5 categories, for one of which I need to run the COUNT function. I am able to access the details, until I run the count function, after which I am limited to a single result. I have also tried using COUNT(*) as... - but this hasn't worked. The code is as follows:

SELECT name, location, grade_1996, COUNT(voter_id)
FROM votes
JOIN congress_members
ON congress_members.id=politician_id
WHERE grade_current < 9;

Please help, thank you.

You need a group by . Perhaps this is what you intend:

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;

You are missing the GROUP BY clause:

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;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM