如何将不同条件的group by放到一个select里面?

南飞雁 2003-06-12 07:45:52

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
...全文
202 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
taler 2003-06-13
  • 打赏
  • 举报
回复
是的,Lastdrop(空杯)的方法最容易理解
oraclenewbie 2003-06-13
  • 打赏
  • 举报
回复
偶刚学oracle,看起来Lastdrop(空杯)的最好了,其他的偶都看不懂,是不是这样的?
Lastdrop 2003-06-13
  • 打赏
  • 举报
回复
select c1, count(*) sum1, sum(decode(sign(n1-2),1,1,0)) sum2
from yourtable
where c1='c'
group by c1
things 2003-06-12
  • 打赏
  • 举报
回复
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
BlueskyWide 2003-06-12
  • 打赏
  • 举报
回复
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;
jiezhi 2003-06-12
  • 打赏
  • 举报
回复
select c1,(select count(*) from a where c1='c') sum1,
(select count(*) from a where c1='c' and n1>2) sum2
from a where c1='c'

17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧