我试图离开联接三个表,我可以做到。但是当我尝试使用MAX函数和sum函数时,出现了错误。
如果在查询中删除“ max”和“ sum”,则会显示具有更正数据的表。
select
t1.CustNo as CustomerID,
MAX(t1.HIST) as LastUpdated_Class_Date,
t1.Class as Current_Class,
t2.WERT as Final,
case when t2.VAR_NR in (11,13,15) then SUM(0+t2.WERT) else 0 END as Grade,
t1.KYC_SP_45 as Initial_Resubmission_Date,
t3.REMINDDATE as Auto_Resubmisssion_Date,
t3.MANREMINDDATE as Manual_Resubmission_Date,
t1.KYC_BANKORG as Branch_Code
FROM HKHK.KYCCUST as t1
left OUTER join HKHK.TBSVVAL as t2 on t2.CustNo = t1.CustNo and t2.HIST =t1.HIST AND t2.VAR_NR ='1'AND t1.HIST ='9999'
AND t2.INSTITUTSNR=t1.INSTITUTSNR
left join HKHK.PRESULT as t3 on t1.CustNo = t3.CustNo and t1.HIST =t2.HIST AND t1.HIST='9999'
WHERE t1.Class NOT IN (SELECT t1.Class from HKHK.KYCCUST WHERE HIST = '9999')
GROUP BY t3.CustNo
我希望输出应该是具有查询中已经描述的列名的表。但是它确实显示错误消息“在选择列表中无效,因为它既不在聚合函数中也不在GROUP BY子句中”