在同一个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)