To explain more in detail- I have two tables A & B. Employee ID is the common column between both the tables. I need to join the 2 tables to compare the FTEs in the 2 tables.
Sample table
Table A:
Emp_ID |S Period |s FTE
1 201701 0.5
1 201701 0.5
2 201702 0.7
3 201702 1
Table B
Emp_ ID |S Period |s FTE
1 201701 1
2 201702 0.5
3 201702 0.7
FTEs need to be summed and grouped by period and emp_id These 2 tables need to be joined and the result should look something like this
Emp_ID Period FTE (Table A) FTE (Table B)
1 201701 1 1
2 201702 0.7 0.5
3 201702 1 0.7
query
select * from
( select f.Employee_SK , f.period_nk
from adj.PayrollAdjustments p
cross join IA_FACT_Payroll f) pf
left join (select period_nk
, employee_sk
, sum(CalcClinical_FTE) as sum
from IA_FACT_Payroll
group
by Period_NK
, Employee_SK ) f on pf.Employee_SK = f.Employee_SK
left join ( select LibPeriodKey
,PersonnelMasterKey
, sum(clinicalFTE) as sumP
from adj.PayrollAdjustments
group by LibPeriodKey, PersonnelMasterKey) adj on pf.employee_sk = adj.personnelmasterkey