没有为[table]的列[x]指定列和无效的列名

时间:2013-07-18 15:06:15

标签: sql sql-server tsql

当运行以下查询时,我得到了所需的结果,但SSMS指示“当我将鼠标悬停在表别名上时以及当我将鼠标悬停在AVG中的”总计“上时,没有为'MonthlyTotals'的第2列指定列function,它指定它是一个无效的列名。

SELECT AVG(Totals) as 'MonthlyAvg' from
(
SELECT [DATE], SUM(Assets) as 'Totals'
FROM Assets inner join Funds on Assets.FundCode = Funds.FundCode
WHERE FeeGroupID = 17
    and (([Date] >= '1/1/2013') 
    AND ([Date] <= '4/1/2013')) 
    and ((Funds.EndDt >= '4/1/2013') OR (Funds.EndDt is null))
GROUP BY [DATE]
) as MonthlyTotals

1 个答案:

答案 0 :(得分:3)

总猜,但尝试这种替代语法。

SELECT [MonthlyAvg] = AVG(Totals) from
(
SELECT [DateOf] = [DATE] , [Totals] = SUM(Assets) 
FROM Assets inner join Funds on Assets.FundCode = Funds.FundCode
WHERE FeeGroupID = 17
    and (([Date] >= '1/1/2013') 
    AND ([Date] <= '4/1/2013')) 
    and ((Funds.EndDt >= '4/1/2013') OR (Funds.EndDt is null))
GROUP BY [DATE]
) as MonthlyTotals