select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number=1
select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number=2
select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number=3
select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number=4
select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number>=5
如何把这5条sql语句变成一条,我要的结果是 =1=2=3=4大于5的用户分别说多少,不是要总数的亲们
select
A=(select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number=1)
,B=(select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number=2)
,C=(select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number=3)
,D=(select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number=4)
,E=(select count(*) from (SELECT HY_GUID,COUNT(*) number FROM dbo.BI_GYDD GROUP BY HY_GUID) a where number>=5)
用你的表不好测,我换成我库里的表了
select sum(t21), sum(t22)
from (select decode(t.answer_id, 361, 1, 0) t21,
decode(t.answer_id, 363, 1,0) t22
from tb_satisfy_answer t
group by t.answer_id) t2;
思路:吧满足条件的标1,不满足条件的标2 在做sum,就是你要的结果。
楼上的可以满足要求,但是效率......