我正在尝试在 SSMS 2014 中执行以下查询。但是,我无法从外部查询访问使用内部查询中的 case 语句创建的列。即我无法访问 c.current。获得错误 - C 附近的语法不正确
select C.trandate,C.plan,C.current from
(SELECT d.trandate,p.plan,
case when datediff(dd,trandate,getdate()) <=30 then d.amount else 0 end as 'Current',
case when datediff(dd,trandate,getdate()) between 31 and 60 then d.amount else 0 end as '31 to 60',
case when datediff(dd,trandate,getdate()) between 331 and 360 then d.amount else 0 end as '331 to 360',
case when datediff(dd,trandate,getdate()) > 360 then d.amount else 0 end as '>360',d.residentsys
FROM [HMXals_Reporting].[dbo].[TranARDetail] d
join [HMXals_Reporting].[dbo].[plans] p
on d.transys = p.plansys
) C