在下面的SQL中。我传递输入参数Job_Owner。它可以是'A'或'B'或'C'。现在,如果A通过,我必须得到
如果作业所有者为“B”,则获取以下详细信息
如果我为Job_owner A运行SQL,我将得到如下输出
BAY_GROUP | COUNT(*) | AGCOUNT | AYCOUNT| ARCOUNT|BGCOUNT | BYCOUNT|
Bay1 16 8 5 3 0 0
Bay3 1 1 0 0 0 0
BRCOUNT|CGCOUNT | CYCOUNT| CRCOUNT|
0 0 0 0
0 0 0 0
但我希望输出如下
BAY_GROUP | COUNT(*) | AGCOUNT | AYCOUNT| ARCOUNT
Bay1 16 8 5 3
Bay3 1 1 0 0
SELECT BAY_GROUP , COUNT(*),
sum(case when (JOB_OWNER = 'A' AND A_ASSIGN_DT > sysdate-21) then 1 else 0 end) AGCount,
sum(case when (JOB_OWNER = 'A' AND (A_ASSIGN_DT < sysdate-21 AND A_ASSIGN_DT > sysdate-28)) then 1 else 0 end) AYCount,
sum(case when (JOB_OWNER = 'A' AND A_ASSIGN_DT < sysdate-28) then 1 else 0 end) ARCount,
sum(case when (JOB_OWNER = 'B' AND B_ASSIGN_DT > sysdate-21) then 1 else 0 end) BGCount,
sum(case when (JOB_OWNER = 'B' AND (B_ASSIGN_DT > sysdate-21 AND B_ASSIGN_DT > sysdate-28)) then 1 else 0 end) BYCount,
sum(case when (JOB_OWNER = 'B' AND B_ASSIGN_DT < sysdate-28) then 1 else 0 end) BRCount,
sum(case when (JOB_OWNER = 'C' AND C_ASSIGN_DT > sysdate-21) then 1 else 0 end) CGCount,
sum(case when (JOB_OWNER = 'C' AND (C_ASSIGN_DT < sysdate-21 AND C_ASSIGN_DT > sysdate-28)) then 1 else 0 end) CYCount,
sum(case when (JOB_OWNER = 'C' AND C_ASSIGN_DT < sysdate-28) then 1 else 0 end) CRCount
FROM XX_YY_ZZ WHERE
BAY_GROUP IS NOT NULL
AND JOBSTATUS = 'InProcess'
AND ORG = '17'
AND JOB_OWNER in ('A')
GROUP BY BAY_GROUP
答案 0 :(得分:0)
我看到它的方式,这应该为您提供参数化JOB_OWNER
的输出。
SELECT JOB_OWNER,BAY_GROUP,COUNT(*),
sum(case when (A_ASSIGN_DT > sysdate-21) then 1 else 0 end) GCount,
sum(case when (A_ASSIGN_DT < sysdate-21 AND A_ASSIGN_DT > sysdate-28) then 1 else 0 end) YCount,
sum(case when (A_ASSIGN_DT < sysdate-28) then 1 else 0 end) RCount
FROM XX_YY_ZZ WHERE
BAY_GROUP IS NOT NULL
AND JOBSTATUS = 'InProcess'
AND ORG = '17'
AND JOB_OWNER in ('A')
GROUP BY JOB_OWNER,BAY_GROUP
唯一的区别是参数将是第一列而不是列前缀,如果你能接受它。