Hey guys,
I am trying to do a query that will show employers who work in two different agencies for the same month. I'm finding this a bit tricky due to the table records.
Each employee has multiple records in my history table. A new record is created for each month so it could look like this:
SSN Employer# DATE
3234 00234 01-01-2011
3234 00234 02-01-2011
However, if they work for more than one employer:
SSN Employer# DATE
3234 00234 01-01-2011
3234 00556 01-01-2011
The employee gets more than one record for the same date since the employer# is unique.
I tried this query:
Problem is the query pulls in anyone that has more than one employer# after July 1. I need my query to only show more than one employer# within the SAME month.
Can anyone help?
I am trying to do a query that will show employers who work in two different agencies for the same month. I'm finding this a bit tricky due to the table records.
Each employee has multiple records in my history table. A new record is created for each month so it could look like this:
SSN Employer# DATE
3234 00234 01-01-2011
3234 00234 02-01-2011
However, if they work for more than one employer:
SSN Employer# DATE
3234 00234 01-01-2011
3234 00556 01-01-2011
The employee gets more than one record for the same date since the employer# is unique.
I tried this query:
Code:
SELECT distinct A.MBR_SSN_NBR
FROM DSNP.PR01_T_MBR_HIST A
WHERE A.MBR_HIST_SVC_CR_DT >= '2010-07-01'
group by a.mbr_ssn_nbr
having count(distinct a.agty_id_cd) > 1
Problem is the query pulls in anyone that has more than one employer# after July 1. I need my query to only show more than one employer# within the SAME month.
Can anyone help?