您的位置:首页 > 数据库

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

2011-03-12 17:24 661 查看
在同一个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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: