我在尝试为新列创建别名并在 GROUP BY 子句中使用它时遇到问题:
SELECT TOP 100 Percent
count(id) AS [items_by_day],
(SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, [date]))) AS [date_part]
FROM [MyDB].[dbo].[MyTable]
GROUP BY DAY([date]), MONTH([date]), YEAR([date]), date_part
我收到以下错误:
Msg 207, Level 16, State 1, Line 5
Invalid column name 'date_part'.
如何解决问题?