1
기술적으로 무엇을 요구하고 있는지 모르겠으므로 답을 찾으려고 애쓰는 데 어려움이 있습니다. 이 쿼리는 MySQL에서 작동하지만 PostgreSQL으로 전환하는 것은 다소 어려웠습니다.여러 그룹 결과 (그룹 별)
SELECT call.call_id,
SUM(CASE WHEN indicator.indicator_name = 'Appointment Set' THEN indicator_score.score_value ELSE '0' END) as "Appointment Set" ,
SUM(CASE WHEN indicator.indicator_name = 'Ask for Business' THEN indicator_score.score_value ELSE '0' END) as "Ask for Business"
FROM call
JOIN indicator_score ON indicator_score.call_id = call.call_id
JOIN indicator ON indicator.indicator_id = indicator_score.indicator_id
JOIN org_unit ON org_unit.org_unit_id = call.org_unit_id
WHERE call.org_unit_id IN (4147, 4153)
group by call.call_id, indicator_name
각 call_id
캔 두 "비즈니스에 대한 질문"과 "약속 설정"에 대한 점수가 있어야하지만 내가 무엇을 얻고 것은 점수 하나는 '0'과 다른 것입니다. 내가 무엇을 찾고
call_id | Appointment Set | Ask for Business
--------------------------------------------
3,001,144 | 0 | 89
3,001,145 | 100 | 0
이 같은 것입니다 :
call_id | Appointment Set | Ask for Business
--------------------------------------------
3,001,144 | 100 | 89
나는 또한이 구조를 시도,하지만 난 같은 결과를 얻고있다.
group by call.call_id, indicator_name
와
SELECT call.call_id,
CASE indicator.indicator_name WHEN 'Appointment Set' THEN sum(indicator_score.score_value) ELSE '0' END as Appointment_Set ,
CASE indicator.indicator_name WHEN 'Ask for Business' THEN sum(indicator_score.score_value) ELSE '0' END as Ask_for_Business
FROM call
JOIN indicator_score ON indicator_score.call_id = call.call_id
JOIN indicator ON indicator.indicator_id = indicator_score.indicator_id
JOIN org_unit ON org_unit.org_unit_id = call.org_unit_id
WHERE call.org_unit_id IN (4147, 4153)
group by call.call_id, indicator_name
문제는 당신이 두 개의 결과 행을 얻을 수 있도록'call_id'이 다른 것입니다. 동일하면 하나의 결과 행만 가져옵니다. 그래서 저는 쿼리가 예상대로 작동한다고 생각합니다. –