SQLTeam.com | Weblogs | Forums

Problem to organize SQL query COUNT(column) in different columns

Hi team,

I have a problem organize my slq query in different columns. Does anybody know how to do that?

The query works separated but I need group them but in different columns.
SELECT
agent_name,
call_start_time AS date,
csq,
skills,
agent_state,
COUNT('agent_name') AS qtd_Apresentada
FROM dbo.sp_agent_detail_ccx WHERE type_call Like 'Inbound%'
GROUP BY call_start_time, csq, skills,agent_state,agent_name
ORDER BY call_start_time

SELECT
agent_name,
call_start_time AS date,
csq,
skills,
agent_state,
COUNT('agent_name') AS qtd_tratadas
FROM dbo.sp_agent_detail_ccx WHERE type_call Like 'Inbound ACD' and talk_time > 0 and wrapup_time > 0 and call_duration > 0
GROUP BY call_start_time, csq, skills,agent_state,agent_name
ORDER BY call_start_time

SELECT
agent_name,
call_start_time AS date,
csq,
skills,
agent_state,
COUNT('agent_name') AS qtd_Abandonadas
FROM dbo.sp_agent_detail_ccx WHERE talk_time = 0 and call_duration = 0 and wrapup_time = 0 and type_call = 'Inbound ACD'
GROUP BY call_start_time, csq, skills,agent_state,agent_name
ORDER BY call_start_time

SELECT
agent_name,
call_start_time AS date,
csq,
skills,
agent_state,
SUM(CASE WHEN type_call Like 'Inbound%' THEN 1 ELSE 0 END) AS qtd_Apresentada,
SUM(CASE WHEN type_call Like 'Inbound ACD' and talk_time > 0 and wrapup_time > 0 and 
    call_duration > 0 THEN 1 ELSE 0 END) AS qtd_tratadas,
SUM(CASE WHEN type_call = 'Inbound ACD'AND talk_time = 0 and call_duration = 0 and 
    wrapup_time = 0 THEN 1 ELSE 0 END) AS qtd_Abandonadas
FROM dbo.sp_agent_detail_ccx 
GROUP BY call_start_time, csq, skills,agent_state,agent_name
ORDER BY call_start_time
1 Like

You can add to Scott's solution:

WHERE type_call LIKE 'Inbound%'

1 Like

Thank you @ScottPletcher and @jeffw8713 . Both Works Fine.