1

这是我的查询:

SELECT COUNT(*) AS Expr1, name, appointment_date 
FROM ReportingTable 
GROUP BY name, appointment_date

我想按月对约会日期列进行分组,如下所示:

SELECT COUNT(*) AS Expr1, name, appointment_date
FROM ReportingTable
GROUP BY name, MONTH(appointment_date)

但我的查询引发以下错误:

列“appointment_date”在所选列表中无效,因为它既不包含在聚合函数也不包含在 groupby 子句中。

4

1 回答 1

1

这会起作用吗:

SELECT        COUNT(*) AS Expr1, name, MONTH(appointment_date) AS appointment_month
FROM            ReportingTable
GROUP BY name, appointment_month
于 2012-07-29T08:12:11.790 回答