如何按月和周工作分组数据
我知道这是错的..
select sum(x) from demo_table
group by DATEPART(month,date)
where DATENAME(weekday,date)='sunday' ;
where子句不能在组内使用... 但这是我想要的
答案 0 :(得分:1)
将where
子句放在group by
:
select sum(x)
from demo_table
where DATENAME(weekday,date)='sunday'
group by DATEPART(month,date) ;
答案 1 :(得分:1)
你可能想要
select sum(x)
from demo_table
where DATENAME(weekday,date)='sunday'
group by DATEPART(month,date)
[WITH common_table_expression]
SELECT select_list [INTO new_table]
[FROM table_source] [WHERE search_condition]
[GROUP BY group_by_expression]
[HAVING search_condition]
[ORDER BY order_expression [ASC | DESC]]