下面这三个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

解决方案 »

  1.   

    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
      

  2.   

    貌似你的语句有的问题,也影响到我了.
    更改为如下:
    select 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 
      

  3.   

    select a.[搜索任务],b.[网盟任务],c.[流程任务] from  
    (select row_number() over(order by hy_info_menuid) rn,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)a
    inner join 
    (select row_number() over(order by hy_info_menuid) rn,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)b on a.rn =b.rn 
    inner join 
    (select row_number() over(order by hy_info_menuid) rn,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)c on a.rn =c.rn
      

  4.   

    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