題目描述
假如A公司為了調(diào)查用戶對(duì)于某產(chǎn)品的滿意情況殴蓬,設(shè)置了一套調(diào)查問卷矛物,這套問卷一共有五道題沮趣,每個(gè)題的分值均在于0~10点额,得到調(diào)研結(jié)果統(tǒng)計(jì)表questions
如下茂卦,其中id
代表用戶何什,items
代表問卷中的問題,scores
代表用戶給出的分?jǐn)?shù)等龙。
id | items | scores |
---|---|---|
1 | 1 | 8 |
1 | 2 | 9 |
1 | 3 | 7 |
1 | 4 | 4 |
1 | 5 | 3 |
2 | 1 | 10 |
2 | 2 | 10 |
2 | 3 | 10 |
2 | 4 | 10 |
2 | 5 | 10 |
3 | 1 | 3 |
3 | 2 | 2 |
3 | 3 | 1 |
3 | 4 | 2 |
3 | 5 | 3 |
問題
(1)使用sql
代碼查出給所有問題打分均相同的用戶,例如上述用戶2处渣。
(2)是用sql
代碼查出給所有問題打分均低于5分的用戶,例如上述用戶3蛛砰。
答案
(1)
select q.id
from (select id, count(distinct scores) as counting
from questions group by id)
as q where q.counting = 1;
(2)
select id from questions group by id having max(scores) < 5;