获取SQL Union中的百分比

时间:2019-03-20 16:35:33

标签: sql

帮助,我在下面的SQL查询中找到了报告“计划的作业”作为类型,并且在工会中,我具有“计划和关闭的同期工作” AS类型。 我想找到这两个百分比,可以这样做吗?

SELECT

'Scheduled Jobs' AS Type,
(SELECT MRC_DESC FROM R5MRCS WHERE MRC_CODE = EVT_MRC) AS Department,
YEAR(A.AVA_CHANGED) AS Year1,
MONTH(A.AVA_CHANGED) AS Month1,
A.AVA_CHANGED AS Date1,
B.AVA_CHANGED AS ScheduleDate1,
COUNT(A.AVA_TO) AS Count
FROM R5EVENTS
LEFT JOIN R5AUDVALUES A ON A.AVA_PRIMARYID = EVT_CODE AND A.AVA_TABLE = 'R5EVENTS'
LEFT JOIN R5AUDVALUES B ON B.AVA_PRIMARYID =  A.AVA_PRIMARYID AND B.AVA_TABLE = 'R5EVENTS' AND B.AVA_TO = 'SCH'
WHERE EVT_TYPE IN ('JOB','PPM')
AND A.AVA_TO = 'SCH'
AND B.AVA_CHANGED  BETWEEN `to_timestamp`(#prompt('SEL_FROM')#,'YYYY-MM-DD"T"HH24:MI:SS.FF3') AND `to_timestamp`(#prompt('SEL_TO')#,'YYYY-MM-DD"T"HH24:MI:SS.FF3')
GROUP BY EVT_MRC, A.AVA_CHANGED, B.AVA_CHANGED


UNION ALL

SELECT
'`Sched` and Closed Same Period Jobs' AS Type,
(SELECT MRC_DESC FROM R5MRCS WHERE MRC_CODE = EVT_MRC)  AS Department,
YEAR(A.AVA_CHANGED) AS Year1,
MONTH(A.AVA_CHANGED) AS Month1,
MAX(A.AVA_CHANGED) AS Date1,
B.AVA_CHANGED AS ScheduleDate1,
COUNT(A.AVA_TO) AS Count
FROM R5EVENTS
LEFT JOIN R5AUDVALUES A ON A.AVA_PRIMARYID = EVT_CODE AND A.AVA_TABLE = 'R5EVENTS'
LEFT JOIN R5AUDVALUES B ON B.AVA_PRIMARYID =  A.AVA_PRIMARYID AND B.AVA_TABLE = 'R5EVENTS' AND B.AVA_TO = 'SCH'
WHERE EVT_TYPE IN ('JOB','PPM')
AND A.AVA_TO = 'C'
AND A.AVA_CHANGED = (SELECT MAX(E.AVA_CHANGED) FROM R5AUDVALUES E WHERE E.AVA_PRIMARYID = A.AVA_PRIMARYID AND E.AVA_TABLE = 'R5EVENTS' AND E.AVA_TO = 'C')
AND B.AVA_CHANGED  BETWEEN `to_timestamp`(#prompt('SEL_FROM')#,'YYYY-MM-DD"T"HH24:MI:SS.FF3') AND `to_timestamp`(#prompt('SEL_TO')#,'YYYY-MM-DD"T"HH24:MI:SS.FF3')
GROUP BY EVT_MRC, A.AVA_CHANGED, B.AVA_CHANGED

0 个答案:

没有答案