Reputation: 177
How to group data by month and week day
I know this is wrong..
select sum(x) from demo_table
group by DATEPART(month,date)
where DATENAME(weekday,date)='sunday' ;
where clause cannot be used inside group by... but this is want i need
Upvotes: 0
Views: 88
Reputation: 166626
You probably want
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 ] ]
Upvotes: 1
Reputation: 1271241
Put the where
clause before the group by
:
select sum(x)
from demo_table
where DATENAME(weekday,date)='sunday'
group by DATEPART(month,date) ;
Upvotes: 1