首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql语句写法,该如何解决

2012-05-01 
sql语句写法下面这三个sql语句怎么合并成一个啊? 在一张表里面显示, 这三个sql语句的条件不同select count

sql语句写法
下面这三个sql语句怎么合并成一个啊? 在一张表里面显示, 这三个sql语句的条件不同

select count(*) 搜索任务 from hy_Info where hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) group by sys_auserid
 
select count(*) 网盟任务 from hy_Info where hy_info_menuid in(24,25,26,27,33,34,35,36,37,38,39,40,41) group by sys_auserid
 
select count(*) 流程任务 from hy_Info where hy_info_menuid in(43,45,47,48,49,50,51,52,54,55,56,57,92,96,123) group by sys_auserid


[解决办法]

SQL code
select sys_auserid,       sum(case when hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) then 1 else 0 end) [搜索任务],       sum(case when hy_info_menuid in(24,25,26,27,33,34,35,36,37,38,39,40,41) then 1 else 0 end) [网盟任务],       sum(case when hy_info_menuid in(43,45,47,48,49,50,51,52,54,55,56,57,92,96,123) then 1 else 0 end) [流程任务]from hy_Info group by sys_auserid
[解决办法]
探讨
SQL code
select sys_auserid,
sum(case when hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) then 1 else 0 end) [搜索任务],
sum(case when hy_info_menuid in(24,25,26,27,33……

[解决办法]
SQL code
select count(*) 搜索任务 from hy_Info where hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) group by sys_auseridunion select count(*) 网盟任务 from hy_Info where hy_info_menuid in(24,25,26,27,33,34,35,36,37,38,39,40,41) group by sys_auseridunion  select count(*) 流程任务 from hy_Info where hy_info_menuid in(43,45,47,48,49,50,51,52,54,55,56,57,92,96,123) group by sys_auserid 

热点排行
Bad Request.