开发者

group by user that has answered all questions

开发者 https://www.devze.com 2023-01-29 05:41 出处:网络
I have a table of scores per userID. The value of score can be a number or null. Each user has 20 entries (which defines their 20 questions) and all start off with scores of null.

I have a table of scores per userID. The value of score can be a number or null.

Each user has 20 entries (which defines their 20 questions) and all start off with scores of null.

As they answer each question, the开发者_JAVA技巧 null is replaced by a score.

I would like a query that gets all use ids that have answered all 20 questions, i.e no nulls for that user.

I would really appreciate some help.


Use GROUP BY, HAVING, and COUNT

As this is probably homework I'll try the spoiler markup (mouse over to see the answer!)

select userID from yourtable group by userID having count(score)=20


Try something similar to:

select userID from ... group by userID having count(*)=20
0

精彩评论

暂无评论...
验证码 换一张
取 消