id reply userid uflag qid
-----------------------------
1 aaa 2 0 5
2 bbb 2 0 4
3 ccc 1 0 6
4 ddd 2 0 5
5 eee 3 1 3
6 fff 2 0 3
qid是问题ID,这张表是答案表
------------------------------
我想得到这样的结果:
------------------------------
qid userid uflag answer_total
5 2 0 2
4 2 0 1
3 2 0 1
注释:answer_total每个问题下有几个答案
------------------------------
select qid,userid,uflag,answer_total = count(1)
from 表
where userid=2
group by qid,userid,uflag
qid userid uflag answer_total question_total
5 2 0 2 3
4 2 0 1 3
3 2 0 1 3
count(distinct qid) as question_totalfrom tb where userid = 2 group by qid , userid , uflag order by qid desc