SELECT ts_name "Type", ts_title "Change Group", SUM (total) "Total", SUM (cancelled) "Cancelled"
FROM (SELECT p.ts_name g.ts_title COUNT (rfc.ts_id) Total,
0 Cancelled
FROM usr_rfc rfc, u_group_codes g, ts_projects p
WHERE g.ts_id = rfc.ts_group_code
AND rfc.ts_projectid = p.ts_id
AND TO_CHAR ( TO_DATE ('01-JAN-1970', 'DD-MON-YYYY')
+ (rfc.ts_submitdate / (60 * 60 * 24)),
'YYYY'
) = 2010
AND TO_CHAR ( TO_DATE ('01-JAN-1970', 'DD-MON-YYYY')
+ (rfc.ts_submitdate / (60 * 60 * 24)),
'Q'
) = 2
GROUP BY p.ts_name, g.ts_title
UNION
SELECT p.ts_name , g.ts_title , 0 Total,
COUNT (rfc.ts_id) Cancelled
FROM usr_rfc rfc, u_group_codes g, ts_projects p
WHERE g.ts_id = rfc.ts_group_code
AND rfc.ts_projectid = p.ts_id
AND rfc.ts_state IN (4, 195)
AND TO_CHAR ( TO_DATE ('01-JAN-1970', 'DD-MON-YYYY')
+ (rfc.ts_submitdate / (60 * 60 * 24)),
'YYYY'
) = 2010
AND TO_CHAR ( TO_DATE ('01-JAN-1970', 'DD-MON-YYYY')
+ (rfc.ts_submitdate / (60 * 60 * 24)),
'Q'
) = 2
GROUP BY p.ts_name, g.ts_title)
group by ts_name, ts_title
ORDER BY 1, 2
|