重构目标例子:http://www.cnblogs.com/insus/articles/1961688.html SELECT语句中需要使用到别名,<column> OR <expression> AS <column_alias>。
重构后的代码,请参考:
WITH ASY AS
(
SELECT YEAR(birthday) AS [Year],[Salary] FROM [dbo].[Member]
)
SELECT [Year],AVG([Salary]) AS [AvgSalary]
FROM ASY
GROUP BY [YEAR]
(
SELECT YEAR(birthday) AS [Year],[Salary] FROM [dbo].[Member]
)
SELECT [Year],AVG([Salary]) AS [AvgSalary]
FROM ASY
GROUP BY [YEAR]