SELECT
,ACCT_NUM
,DATA_DT
,CUST_NM
,STRT_DT
FROM FACT_MAIN AS FMAIN
INNER JOIN DIM_MAIN AS DMAIN
ON DMAIN.DIM_ID = FMAIN.DIM_ID
inner JOIN DIM_ACCT AS DACCT
ON DACCT.DIM_ID = FMAIN.DIM_ID
LEFT OUTER JOIN FACT_CUST AS FCUST
ON FMAIN.DIM_ID = FCUST.DIM_ID
INNER JOIN DIM_CUST_ADR AS DCADR
ON DCADR.CUST_DIM_ID = FCUST.CUST_DIM_ID
WHERE
FMAIN.DATA_DT = 20090131
AND FCUST.DATA_DT = 20090131
AND DMAIN.BOOKED_DT BETWEEN '20090101' AND '20090131'
AND DCADR.STRT_DT = (SELECT max(STRT_DT) FROM DIM_CUST_ADR AS ADR
WHERE ADR.CUST_DIM_ID = DCADR.CUST_DIM_ID )
|