question

Malowa avatar image
Malowa asked

Create a SELECT query that would give us the following result?

How do I create a query that would give the following result? RESULT Name Extension Lanid Calls Taken Tickets Created Rhommel 8107 bernardr-adm 35 34 Wai 8327 WongWaiK-adm 15 15 Steve 8321 SerodioS-adm 27 25 Dan 8315 lepageda-adm 35 33 Andrew 8302 DaSilvaA-adm 18 18 Murielle 8307 LecerfMu-adm 22 22
selecthomework
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Madhivanan avatar image Madhivanan commented ·
Post table structure and sample data
0 Likes 0 ·

1 Answer

·
GPO avatar image
GPO answered
In the absence of any further detail :-)... WITH tks as( SELECT tk.member_id count(*) as tickets_created FROM dbo.tickets WHERE tk.ticket_created >= @start_date and tk.ticket_created < @next_start_date GROUP BY tk.member_id ) ,clls as ( SELECT cl.member_id count(*) as calls_taken FROM dbo.Calls GROUP BY cl.member_id ) SELECT tm.name ,tm.Extension ,tm.lanid ,sum(isnull(clls.calls_taken,0)) as [Calls taken] ,sum(isnull(tks.tickets_created,0)) as [Tickets created] FROM dbo.team_members tm LEFT JOIN tks ON tm.member_id = tks.member_id LEFT JOIN clls ON tm.member_id = clls.member_id WHERE tm.active_from < @next_start_date and (tm.active_to >= @start_date OR tm.active_to is null) ...now tell me I'm wrong!
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.