【发布时间】:2013-12-31 06:59:00
【问题描述】:
我的 sql 查询返回特定周给定员工的正确结果
例如。我的员工名单是 (emp1 , emp2 , emp3 , emp4)
如果 emp4 在那一周没有做任何工作,则根本不会返回该员工的行。
我的查询如下:
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 值
【问题讨论】:
-
你应该删除old version of your question以避免重复。
-
@YaroslavShabalin 嘿,你能帮帮我吗\
-
如果您有单独的表来存储员工姓名,那么您可以将其外部连接到查询中的表中。
emp4应该在该表中,并将在结果查询中。 -
@YaroslavShabalin,我知道如果有另一个带有员工姓名的表可以做到,但在我的情况下我该怎么做,检查我的查询
-
你怎么知道提到的员工根本存在?在某个地方应该有关于他的信息。你从哪里得到
IN子句的列表?