注册 登录
编程论坛 Oracle论坛

请教关于聚合函数COUNT()

zl芊芊zl 发布于 2008-02-18 09:39, 2282 次点击
请教一个关于聚合函数count()的问题,我有下面的表格
Name    Age    Result
Hansen    30    NG
Svendson    25    NG
Kari    20    OK

我想显示以下的结果
NUM    OK    NG
3    1    2
一个显示总的数量,一个显示OK,一个显示NG,我现在的SQL是
Select count(*) from table;Select count(*) from table where Result='OK';Select count(*) from table where Result='NG';这样写出来就要至少2个SQL,不知道能不能简化一下,这样可以用一个SQL写出来吗?
因为我有好多个Table的结果需要整理,所以如果只能这样的话就要好多个SQL了,希望可以简单一点,谁能帮帮忙,谢谢啦!
1 回复
#2
misiling2008-02-18 17:39
一种笨解
select c.c1 as num ,a.a1 ng,b.b1 ok
  from (Select count(*) a1 from test_su where c='ok') a
      ,(Select count(*) b1 from test_su where c='ng') b
      ,(Select count(*) c1 from test_su ) c
1