我尝试运行如下 SQL 查询 (mssql 2005):
select top 20 d_date, date1, date2
from reestr_calculated
where reestr_id=2
group by date2
order by date2 desc
我收到以下错误:
Column 'reestr_calculated.d_date' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
有人知道我该如何处理这个错误吗?
最佳答案
除非您使用聚合函数,否则 SELECT
中出现的所有列名称都必须出现在 GROUP BY
中。因此,将 date1 也添加到 group by 中。
关于sql - 使用 group by 进行 sql 查询时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17424343/