gpt4 book ai didi

mysql - 显示每个答案计数的用户 ID 计数

转载 作者:太空宇宙 更新时间:2023-11-03 10:49:12 24 4
gpt4 key购买 nike

我有一个表格,其中包含由唯一用户回答的答案数据。所以我有这个查询。

select ta.user_id, count(ta.answer_id) count_answer_id 
from survey_answers ta
group by ta.user_id
having count(ta.answer_id) < 124
order by count_answer_id desc;



userid count of answers
3702 123
2866 120
5483 120
565 120
1292 120
621 119
2250 119
2719 119
4192 119
5539 119
354 119
1441 119
2501 115
1636 115
866 109
53 108
3091 107
329 106
285 105
997 104
1352 103
5281 103
430 102
2125 102

但我想得到这样的结果。

user count    answer count
1 123
4 120
7 119
2 115
.
.
.
.

最佳答案

select count(*) as user_count, count_answer_id 
from
(
select ta.user_id, count(ta.answer_id) count_answer_id
from survey_answers ta
group by ta.user_id
having count(ta.answer_id) < 124
) tmp
group by count_answer_id
order by count_answer_id desc

关于mysql - 显示每个答案计数的用户 ID 计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26856261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com