Hi guys,
I still can't seem to grasp the concept of combining queries together. UNION doesn't work in this case. I have these queries:
query 1
query 2
The only difference between the two is the dates. I want my query to have one column for Total and one for New Retirees.
Can someone show me how to combine these using derived tables? I gave it a shot , but I don't know how to reference Alias named fields in the main query. Thanks!
I still can't seem to grasp the concept of combining queries together. UNION doesn't work in this case. I have these queries:
query 1
Code:
SELECT AGTY_SYS_CD, count(*) AS "TOTAL RETIREES"
FROM DSNP.PR01_T_RECIP_SYS
WHERE RECIP_RETIR_DT <= '2010-02-01'
AND BENEF_STAT_CD IN ('AC', 'DP')
AND RECIP_TYPE_CD = '10'
AND BENEF_SEQ_NBR = 1
GROUP BY AGTY_SYS_CD
order by 2 desc
query 2
Code:
SELECT AGTY_SYS_CD, count(*) AS "NEW RETIREES"
FROM DSNP.PR01_T_RECIP_SYS
WHERE RECIP_RETIR_DT BETWEEN '2010-02-01' and '2010-02-28'
AND BENEF_STAT_CD IN ('AC', 'DP')
AND RECIP_TYPE_CD = '10'
AND BENEF_SEQ_NBR = 1
GROUP BY AGTY_SYS_CD
ORDER BY 2 DESC
The only difference between the two is the dates. I want my query to have one column for Total and one for New Retirees.
Can someone show me how to combine these using derived tables? I gave it a shot , but I don't know how to reference Alias named fields in the main query. Thanks!