在同一个sql语句中写不同条件的count数量,和查询半年的数据

来源:互联网 发布:娜拉走后怎样 知乎 编辑:程序博客网 时间:2024/05/17 09:39

 

在同一个sql语句中写不同条件的count数量

 

select department.depName,
sum(case  when (helpInfo.infoClass=1) then 1 else 0 end ) "News" ,
sum(case  when (helpInfo.infoClass=2) then 1 else 0 end ) "JianBao" ,
COUNT(*) "allUsed",
sum(case  when (helpInfo.useWeb=1) then 1 else 0 end ) "useweb" ,
sum(case  when (helpInfo.useJianBao=1) then 1 else 0 end ) "usejianbao" ,
sum(case  when (helpInfo.useMedia=1) then 1 else 0 end ) "usemedia"
from helpInfo,infoClassTable,department where
helpInfo.infoClass=infoClassTable.infoClassID and helpInfo.depID=department.depID and

helpInfo.useInfo=2
group by department.depName

 

http://yukaiehome.javaeye.com/blog/316356

 

 

查询半年的数据

select * from helpInfo WHERE    (YEAR(addTime) = YEAR(GETDATE())) AND (MONTH(addTime) < 7)

 

http://zhidao.baidu.com/question/30344350.html