Reputation:
I have select from table like:
SELECT DATEPART(WEEK, DayTime) as WeekNumber FROM dbo.Transactions
Result:
WeekNumber
1
1
1
2
2
3
4
4
5
4
5
3
How can I get count of rows for every number of week?
I need something like this:
WeekNumber CountOfRows
1 3
2 2
3 2
4 3
5 1
Upvotes: 0
Views: 51
Reputation: 1363
SELECT DATEPART(WEEK, DayTime) as WeekNumber, COUNT(1) as CountOfRows
FROM dbo.Transactions
GROUP BY WeekNumber;
Upvotes: 0
Reputation: 13787
You need to GROUP BY
week number and use COUNT
function
SELECT DATEPART(WEEK, DayTime), COUNT(*)
FROM dbo.Transactions
GROUP BY DATEPART(WEEK, DayTime)
Upvotes: 3