question

newbee avatar image
0 Votes"
newbee asked Yufeishao-msft edited

Getting monthly and weekly data from daily in sql server

Hello All,

I have a table like below.
I need to get daily,weekly and monthly calls data from this.

Could any one please help what is the query to write here


202686-image.png


sql-server-generalsql-server-transact-sql
image.png (19.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered

Use a date function like YEAR, MONTH, DATEPART and an aggregation, like

 select YEAR(date) AS Year, MONTH(date) AS Month, SUM(Calls) AS Calls
 from yourTable
 group by YEAR(date), MONTH(date)
 order by YEAR(date), MONTH(date)

for a monthly report.
See https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql?view=sql-server-ver15#DateandTimeFunctions
for details.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.