我有一個SQL查詢,它給soem錯誤說「組」使用不正確。 我正在使用SQL包裝器之一creted來與db2表進行交互。SQL查詢給出一些錯誤
有人可以指導我什麼是錯的。我不能使用PIVOT所以試過這個。
with CTE as
(
select distinct(P.Hfan_id)as HFAN_ID,
Min(Case P.HFA_PARAM_NV When 'BUSI_WANT_CALL' Then P.HFAN_PARAM_TXT End) as BUSI_WANT_CALL,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILDREN1_DT' Then P.HFAN_PARAM_TXT End) as HFAN_CHILDREN1_DT,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILDREN2_DT'Then P.HFAN_PARAM_TXT End) as HFAN_CHILDREN2_DT,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILDREN3_DT'Then P.HFAN_PARAM_TXT End) as HFAN_CHILDREN3_DT,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILDREN4_DT'Then P.HFAN_PARAM_TXT End) as HFAN_CHILDREN4_DT,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILDREN5_DT'Then P.HFAN_PARAM_TXT End) as HFAN_CHILDREN5_DT,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILD1_RESPONS' Then P.HFAN_PARAM_TXT End) as HFAN_CHILD1_RESPONS,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILD2_RESPONS' Then P.HFAN_PARAM_TXT End) as HFAN_CHILD2_RESPONS,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILD3_RESPONS' Then P.HFAN_PARAM_TXT End) as HFAN_CHILD3_RESPONS,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILD4_RESPONS' Then P.HFAN_PARAM_TXT End) as HFAN_CHILD4_RESPONS,
Min(Case P.HFA_PARAM_NV When 'HFAN_CHILD5_RESPONS' Then P.HFAN_PARAM_TXT End) as HFAN_CHILD5_RESPONS,
Min(Case P.HFA_PARAM_NV When 'CODEPT_SPOUSE_MK' Then P.HFAN_PARAM_TXT End) as CODEPT_SPOUSE_MK,
Min(Case P.HFA_PARAM_NV When 'HL_SUMMERHOUSE_MK' Then P.HFAN_PARAM_TXT End) as HL_SUMMERHOUSE_MK,
Min(Case P.HFA_PARAM_NV When 'HL_STUDENT_LOAN' Then P.HFAN_PARAM_TXT End) as HL_STUDENT_LOAN ,
Min(Case P.HFA_PARAM_NV When 'HL_OTHER_LOAN' Then P.HFAN_PARAM_TXT End) as HL_OTHER_LOAN ,
Min(Case P.HFA_PARAM_NV When 'SHFAN_CPR_ID' Then P.HFAN_PARAM_TXT End) as SHFAN_CPR_ID ,
Min(Case P.HFA_PARAM_NV When 'SHL_STUDENT_LOAN' Then P.HFAN_PARAM_TXT End) as SHL_STUDENT_LOAN,
Min(Case P.HFA_PARAM_NV When 'SHL_OTHER_LOAN' Then P.HFAN_PARAM_TXT End) as SHL_OTHER_LOAN,
Min(Case P.HFA_PARAM_NV When 'HL_LOANTYPE' Then P.HFAN_PARAM_TXT End) as HL_LOANTYPE,
Min(Case P.HFA_PARAM_NV When 'HL_LOAN_AMOUNT' Then P.HFAN_PARAM_TXT End) as HL_LOAN_AMOUNT,
Min(Case P.HFA_PARAM_NV When 'HL_PROPERTY_TYPE' Then P.HFAN_PARAM_TXT End) as HL_PROPERTY_TYPE
Group by P.hfan_id, P.HFAN_PARAM_TXT, P.HFA_PARAM_NV
having
P.hfan_id in
(14835145,
14697134,
14697430,
14694884,
14694999,
14693122,
14693074)
)
Select * from P1,
S.HFAS_EMAIL,
S.HFAS_PRIV_MOB_NR,
Q.HFAS_ÆGTESTIL_TP,
R.HFAN_BØRN_HJEM_AN,
R.HFAN_TO_LÅNTAG_MK
from CTE P1
inner join hf.HF_ANSØGER_S Q
on P1.hfan_id = Q.hfan_id
inner join hf.HF_ANSØGNING_S R
on P1.hfan_id = R.hfan_id
inner join hf.HF_ANSØGER1_S S
on P1.hfan_id=S.hfan_id
錯誤 - 「組」 未正確使用。
你沒有一個'from'條款在CTE中。 –
除了缺少'from',你還使用'distinct'和'group by'。這沒什麼意義;刪除'distinct'並在你的'group by'中選擇屬性。 – HoneyBadger