日期:2014-05-19  浏览次数:20439 次

求一条统计用的SQL语句关于count,请高手帮忙!!!
表结构如下:
      id     aa     bb     cc     dd     ee
      01     0       1       51     19     10
      02     9       7       15     17     20  
      03     0       7       15     17     20  
      04   null   7       15     17     20  
      05     7       7       15     10     10  
      ...
-----------------------------------------
以下是要求统计的伪SQL代码:
  select   count(*)   as   全部数据,count(aa> 0)   as   AA大于0的数据   ,sum(bb),sum(cc),sum(dd),sum(ee)   where   条件1   and   条件2
现在的问题是,怎么样在这条数据中给“aa大于0的数据”指定条件啊还不能这样写 "count(aa> 0) ";请高手帮忙

------解决方案--------------------
select count(*) as 全部数据,(select count(*) from tb where aa> 0) as AA大于0的数据,
------解决方案--------------------
在where里加 and aa is not null 不行么?
------解决方案--------------------
sum( case when aa> 0 then 1 else 0 end) as AA大于0的数据

*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

最新版本:20070212

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
------解决方案--------------------
up