这是我的疑问:
SELECT COUNT(*) AS Expr1, name, appointment_date
FROM ReportingTable
GROUP BY name, appointment_date
我想按月将group_date列分组,如下所示:
SELECT COUNT(*) AS Expr1, name, appointment_date
FROM ReportingTable
GROUP BY name, MONTH(appointment_date)
但我的查询引发了以下错误:
列“appointment_date”在所选列表中无效,因为它 不包含在聚合函数或groupby子句中。
答案 0 :(得分:1)
这会有效吗?
SELECT COUNT(*) AS Expr1, name, MONTH(appointment_date) AS appointment_month
FROM ReportingTable
GROUP BY name, appointment_month