首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回给定员工的行,即使sql developer中不存在数据也是如此

返回给定员工的行,即使sql developer中不存在数据也是如此
EN

Stack Overflow用户
提问于 2013-12-31 14:59:01
回答 1查看 159关注 0票数 0

我的sql查询返回特定一周内给定员工的正确结果

例如。我的员工列表是(emp1,emp2,emp3,emp4)

如果emp4在该周内没有完成任何工作,则根本不会返回该员工的行。

我的疑问如下:

代码语言:javascript
复制
select a.creator_login ,
sum (case when a.activitytype = 'NCE- Installation' then a.duration else 0 end) as NCE_Installation ,
sum (case when a.activitytype = 'NCE- Migration' then a.duration else 0 end) as NCE_Migration ,
sum (case when a.activitytype = 'NCE-Circuit Testing' then a.duration else 0 end) as NCE_Circuit_Testing ,
sum (case when a.activitytype = 'NCE-Communication - External' then a.duration else 0 end) as NCE_Communication_External,
sum (case when a.activitytype = 'NCE-Communication - Internal' then a.duration else 0 end) as NCE_Communication_Internal,
sum (case when a.activitytype = 'Exception' then a.duration else 0 end) as Exception,
sum (case when a.activitytype = 'NCE-Configuration' then a.duration else 0 end) as NCE_Configuration,
sum (case when a.activitytype = 'NCE-Design Reqt Gathering' then a.duration else 0 end) as NCE_Design_Reqt_Gathering,
sum (case when a.activitytype = 'NCE-Documentation' then a.duration else 0 end) as NCE_Documentation,
sum (case when a.activitytype = 'Notes' then a.duration else 0 end) as Notes,
sum (case when b.openingcode = 'GOC Acceptance' then a.duration else 0 end) as  GOC_Acceptance,
sum (case when a.activitytype = 'To Do' then a.duration else 0 end) as To_Do 
from vware.snap_ticketactivities a , vware.snap_troubletickets b 
where a.ticketrowid  = b.ticketrowid  
and a.creator_login in ('AMITTAL','HSHARMA','NKHAN','PKSINGH','PPATNANA','PTHAKUR','SDAS','SPATEL','VDASS','VVIGNESHWARAN','AOAK') and a.created between  trunc(sysdate-12)  and trunc(sysdate-6 )
group by a.creator_login

如果该周的员工记录不存在,则员工姓名应显示为0值

EN

回答 1

Stack Overflow用户

发布于 2013-12-31 16:49:13

试试这个:

代码语言:javascript
复制
select emp_list.creator_login,
       sum(case
             when a.activitytype = 'NCE- Installation' then
              a.duration
             else
              0
           end) as NCE_Installation,
       sum(case
             when a.activitytype = 'NCE- Migration' then
              a.duration
             else
              0
           end) as NCE_Migration,
       sum(case
             when a.activitytype = 'NCE-Circuit Testing' then
              a.duration
             else
              0
           end) as NCE_Circuit_Testing,
       sum(case
             when a.activitytype = 'NCE-Communication - External' then
              a.duration
             else
              0
           end) as NCE_Communication_External,
       sum(case
             when a.activitytype = 'NCE-Communication - Internal' then
              a.duration
             else
              0
           end) as NCE_Communication_Internal,
       sum(case
             when a.activitytype = 'Exception' then
              a.duration
             else
              0
           end) as Exception,
       sum(case
             when a.activitytype = 'NCE-Configuration' then
              a.duration
             else
              0
           end) as NCE_Configuration,
       sum(case
             when a.activitytype = 'NCE-Design Reqt Gathering' then
              a.duration
             else
              0
           end) as NCE_Design_Reqt_Gathering,
       sum(case
             when a.activitytype = 'NCE-Documentation' then
              a.duration
             else
              0
           end) as NCE_Documentation,
       sum(case
             when a.activitytype = 'Notes' then
              a.duration
             else
              0
           end) as Notes,
       sum(case
             when b.openingcode = 'GOC Acceptance' then
              a.duration
             else
              0
           end) as GOC_Acceptance,
       sum(case
             when a.activitytype = 'To Do' then
              a.duration
             else
              0
           end) as To_Do
  from (select 'AMITTAL' creator_login
          from dual
        union all
        select 'HSHARMA'
          from dual
        union all
        select 'NKHAN'
          from dual
        union all
        select 'PKSINGH'
          from dual
        union all
        select 'PPATNANA'
          from dual
        union all
        select 'PTHAKUR'
          from dual
        union all
        select 'SDAS'
          from dual
        union all
        select 'SPATEL'
          from dual
        union all
        select 'VDASS'
          from dual
        union all
        select 'VVIGNESHWARAN'
          from dual
        union all
        select 'AOAK' from dual) emp_list
  left outer join vware.snap_ticketactivities a on emp_list.creator_login =
                                                   a.creator_login
 inner join vware.snap_troubletickets b on a.ticketrowid = b.ticketrowid
 where nvl(a.created, trunc(sysdate - 12)) between trunc(sysdate - 12) and
       trunc(sysdate - 6)
 group by emp_list.creator_login;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20853243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档