所有的解决方案都指向这样一个事实:如果我在代码中指定了别名,我应该使用它们而不是表名本身。我已经分配了别名,我正在尝试使用别名,但是,我仍然收到此错误。
这与使用左连接有关吗?
我的代码如下:
Select
x.MrtCategory
from
(select case
when c.hrmort='CMHC' then 'CMHC'
when c.hrmort='Genworth' then 'Genworth'
when c.hrmort=''
and a.purp in ('P16','P17')
and c.tenure in ('Freehold','Condo','Strata')
and a.secval<1000000
and a.amorty<=25
and a.class in ('Standard','Stf Benefit Rate','Stf Member Rate')
and a.totltov<80
then 'Conventional Insurable'
when c.hrmort IS NULL then 'Other'
else 'Conventional UnInsurable'
end as MrtCategory,
sum(a.amount) as 'Amount'
from
ODS_WB.dbo.lnap as a left join ODS_WB.dbo.cust as b on a.no_=b.no_ and a.surname=b.surname
left join ODS_WB.dbo.scur as c on b.rowno=c.rowno_custscur_cust and a.secval=c.secvalue and c.status='active'
where
year(a.appdate)=2020 and month(a.appdate)=6 and a.apptype='Mortgage' and a.sourcecode in ('FI',' ')) as x
group by
c.hrmort
1条答案
按热度按时间von4xj4u1#
您的分组依据在子查询之外,因此
c.hrmort
不存在。而是分组方式x.MrtCategory
并对子查询外的金额求和: