我有一个查询,我必须删除WITH子句,但它仍然必须返回相同的结果。我猜其中一个子句应该进入Join,另一个进入having?我的方向正确吗...
有什么建议吗
with QA_m as(
select adr_id, max(eff_ts)as EFF_TS
from addr group by adr_id)
,
QA_address as(select q.adr_id,q.EFF_TS,d.COUNTRY_ID,d.city,d.POST_CODE,d.STREET,d.UNIT_NBR,d.ADL_INFO
from QA_m q join ADDR d
on q.adr_id=d.adr_id and q.EFF_TS=d.EFF_TS)
select
c.SRGT_KEY_VAL as Customer_id,
CAST(i.EFF_TS as date) as "EFF_DT",
i.EFF_TS,
'9999-12-31' as END_DT,
'N' as DEL_IND,
'I' as CUSTOMER_TYPE,
case when ctr.NAME = 'Canada' then 'Y'
else 'N'
END as RESIDENCE_FLAG,
NVL(ctr.name,'N/A') as country,
NVL((trim(TITLE) ||' '||trim(FIRST_NAME)||' '||trim(LAST_NAME)),' ') as NAME,
NVL((trim(CITY)||' '||trim(POST_CODE)||' '||trim(STREET)||' '||trim(UNIT_NBR)||' '||trim(ADL_INFO)),' ') as ADDRESS,
case when i.BIRTH_DATE=TO_date('9999-12-31') then NULL
else TRUNC(months_between(sysdate, i.BIRTH_DATE) / 12)
end AGE,
case when substr(GENDER,1,1) = 'M' then 'M'
when substr(GENDER,1,1) = 'm' then 'M'
when substr(GENDER,1,1) = 'F' then 'F'
when substr(GENDER,1,1) = 'f' then 'F'
else NULL
end as GENDER,
NULL as VAT_NUMBER,
NULL as BRANCH,
NULL as EMPLOYEES
from IDV i
join CSTMR_SRGT_KEY c
on i.IDV_ID=c.ntrl_key_val
left join QA_address B
on i.adr_ID=b.adr_id
left join COUNTRY ctr
on ctr.COUNTRY_ID=b.COUNTRY_ID
where SRC_STM_ID = 100
and i.END_TS='9999-12-31 23:59:59.999999000'
and i.DEL_IND='N';
1条答案
按热度按时间nmpmafwu1#
这些是 * 子查询 *,所以-只需将它们放在适当的位置(请参阅说明的注解):