使用左连接,我将两个表中的数据汇总在一起。根据我引入的数据,我还使用逻辑语句创建了一个新列(AOIMonth 列)。
我的问题是,如何使用引用新 AOIMonth 列的另一个逻辑语句创建另一个列?AOIMonth 列未在表中声明,那么如何引用该列?这是我的代码:
select c.*, b.[FirstMonth], b.[LastMonth], addmonths(b.[lastmonth], c.[Product AOI]) as AOIMonth
from [Churn Custom v4] c
left join (
select[Line #1], min(Max_Month_Day) as [FirstMonth], max(Max_Month_Day) as
[LastMonth]
from [Churn Custom v4]
where [Invoiced_Flag]=1
Group by [Line #1] ) b
on c.[Line #1] = b.[Line #1]
order by c.[Max_Month_Day]
基本上,我想说,“如果 AOIMonth = xyz,那么 abc else 0” 谢谢!