在同一个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
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
相关文章推荐
- 在同一个sql语句中如何写不同条件的count数量
- 在同一个sql语句中如何写不同条件的count数量 (转)
- 在同一个sql语句中,统计不同条件的Count数量
- 转>>在同一个sql语句中如何写不同条件的count数量
- oracle心得1--oracle简介@基本sql语句@条件查询@排序数据理论与案例
- 使用一个T-SQL语句批量查询数据表占用空间及其行数
- 使用一个T-SQL语句批量查询数据表占用空间及其行数
- contentProvider实现groupby查询数据比如要用实现这么一个sql语句:SELEC
- 使用一个T-SQL语句批量查询数据表占用空间及其行数
- SQL语句技巧:查询存在一个表而不在另一个表中的数据记录
- 如何用SQL语句查询一个数据表所有字段的类型
- 当只有一个输入条件的时匹配数据库表中多个字段模糊查询的SQL语句
- mybatis分页多条件查询指定时间段数据的sql语句
- 不同数据库,查询前n条数据的SQL语句
- sql语句 一个表 用户产生两条不同类型的数据 拼接成一条数据
- sql利用在一条语句中count出不同的条件的值
- 数据库关于同一张表不同条件取出数量的横向添加sql语句
- SQL 从一个sql 语句结果中(作为AS一个表) 查询结果 ;按照count排序
- ADO带密码的数据连接、查询一个记录集、执行一SQL语句
- oracle心得1--oracle简介@基本sql语句@条件查询@排序数据理论与案例