语句如下:select Month(PayDate) as Month1,isnull(Pay,0) as 'Pay' from EmployeePayInformation right join (select DISTINCT MONTH(PayDate) as Month1 from EmployeePayInformation) a on EmployeePayInformation.Month1=a.Month1
执行时报错:列名 'Month1' 无效
select Month(PayDate) as Month1,isnull(Pay,0) as 'Pay' from EmployeePayInformationselect DISTINCT MONTH(PayDate) as Month1 from EmployeePayInformation
单独运行,都能成功执行该问题怎么解决
执行时报错:列名 'Month1' 无效
select Month(PayDate) as Month1,isnull(Pay,0) as 'Pay' from EmployeePayInformationselect DISTINCT MONTH(PayDate) as Month1 from EmployeePayInformation
单独运行,都能成功执行该问题怎么解决
这样看看
select b.*
(select Month(PayDate) as Month1,isnull(Pay,0) as 'Pay' from EmployeePayInformation ) b
right join (select DISTINCT MONTH(PayDate) as Month1 from EmployeePayInformation) a on b.Month1=a.Month1
select Month1,isnull(Pay,0) as Pay from (select Month(PayDate) as Month1,Pay as Pay from EmployeePayInformation where EmployeeID='100002') a
right join (select DISTINCT MONTH(PayDate) as Month2 from EmployeePayInformation) b
on a.Month1=b.Month2两个别名要取不同的名字,如Month1,Month2
把条件改一下就行了
select Month(EmployeePayInformation.PayDate) as Month1,isnull(Pay,0) as 'Pay'
from EmployeePayInformation right join (select DISTINCT MONTH(PayDate) as Month1 from EmployeePayInformation) a
on Month(EmployeePayInformation.PayDate)=a.Month1