I am trying to write a query that will tell me the number of employees in multiple categories. It's been awhile since I wrote a query like this, and I just can't remember how to output multiple counts with column names.
I first tried a union
It does give me two counts, but there is no description. The output looks like this:
<no column name>
234
23567
I need the output to identify the count with the appropriate category.
Can anyone help?
I first tried a union
Code:
SELECT SUM(A.TOTAL) AS TOTAL_SCHOOL
FROM
(SELECT count(distinct a.mbr_ssn_nbr) as TOTAL
FROM DSNP.PR01_T_SYSTEM A,
DSNP.PR01_T_HISTORY B
WHERE A.MBR_SSN_NBR=B.MBR_SSN_NBR
AND A.MBR_STAT_CD IN ('A', '1')
AND B.mbr_hist_svc_cr_dt = '2013-10-31'
and b.hist_categ_cd = '10'
and left(B.AGTY_ID_CD, 1) = '3' ) AS A
UNION ALL
SELECT SUM(A.TOTAL) AS TOTAL_COUNTY
FROM
(SELECT count(distinct a.mbr_ssn_nbr) as TOTAL
FROM DSNP.PR01_T_SYSTEM A,
DSNP.PR01_T_HISTORY B
WHERE A.MBR_SSN_NBR=B.MBR_SSN_NBR
AND A.MBR_STAT_CD IN ('A', '1')
AND B.mbr_hist_svc_cr_dt = '2013-10-31'
and b.hist_categ_cd = '10'
and left(B.AGTY_ID_CD, 1) = '0' ) AS A
It does give me two counts, but there is no description. The output looks like this:
<no column name>
234
23567
I need the output to identify the count with the appropriate category.
Can anyone help?