我有一个表,其列为Name,Date1,Date2。我想按人数分组diffdate。
我的查询是
Select DATEDIFF( DAY, Date2, Date1) as diffdate, count(*)
from Table
group by DATEDIFF( DAY, Date2, Date1);
错误:
消息144,级别15,状态1,第8行无法在用于GROUP BY子句的group by列表的表达式中使用聚合或子查询。
大概,您正在使用SQL Server并打算:
Select DATEDIFF(DAY, Date2, Date1) as diffdate, count(*)
from Table
group by DATEDIFF(DAY, Date2, Date1)
order by diffdate;