简体   繁体   中英

SQL - Group by Week Ending

Can someone help me re-write this code to sum the calls by weekending Saturdays?

column headers should be as follows: Week-Ending, Agent ID, Total Calls

SELECT distinct 
cName as "Agent ID"
,CAST(dIntervalStart AS DATE) as "Date"
,SUM(nInternToExternCalls) as "Calls" 

FROM QueueStats

WHERE  
cast(dIntervalStart as date) >= '2019-12-29' and cast(dIntervalStart as date) <= '2020-12-26'

GROUP BY
AQ.cName 
,CAST(dIntervalStart AS DATE)
order by cName

Answer:

SELECT distinct cName as "Agent ID",DATEADD(DAY, -DATEDIFF(DAY, 0, [dIntervalStart]) % 7, [dIntervalStart]) as "Week-Ending",SUM(nInternToExternCalls) as "Calls"

FROM QueueStats

WHERE
cast(dIntervalStart as date) >= '2019-12-29' and cast(dIntervalStart as date) <= '2020-12-26'

GROUP BY AQ.cName,DATEADD(DAY, -DATEDIFF(DAY, 0, [dIntervalStart]) % 7, [dIntervalStart]) order by cName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM