我想得到下面的结果,根据c1 group by,符合c1='c',列2是count(*),列3是符合条件c1='c'并且n1>2的count(*),一个select显示出来,最好不要用union。
结果:
c1 sum1 sum2
--------------
c 4 2
...全文
2026打赏收藏
如何将不同条件的group by放到一个select里面?
表 c1 n1 ------ b 1 b 2 c 1 c 2 c 3 c 4 我想得到下面的结果,根据c1 group by,符合c1='c',列2是count(*),列3是符合条件c1='c'并且n1>2的count(*),一个select显示出来,最好不要用union。 结果: c1 sum1 sum2 -------------- c 4 2
select c.c1, max(a.b), max(b.c) from
(select c1, count(*) b from table1 group by c1) a,
(select c1, count(*) c from table1 where nl>2 group by c1) b,
table1 c
where a.c1(+)=c.c1 and b.c1(+)=c.c1
select tab1.aa,tab1.bb,tab2.dd from
(select c1 aa,count(*) bb from your_table group by c1) tab1,
(select c1 cc,count(*) dd from your_table where nl>2 group by c1) tab2
where tab1.aa=tab2.cc;