日期:2014-05-18  浏览次数:20510 次

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_auserid
union 
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
union  
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