Du warst nah. Sie benötigen den GROUP BY
, aber Sie möchten nicht GROUP BY
die Dauer-Spalte. Stattdessen möchten Sie die SUM
verwenden Funktion in der SELECT
Liste auf Ihrer proc_duration
Spalte:
select
pct.patient_id,
pct.clinic_id,
pct.service_id,
pct.program_id,
pct.protocol_id,
SUM(pct.proc_duration) AS [Total Duration]
FROM patient_clin_tran pct
join patient p
on pct.patient_id = p.patient_id and pct.episode_id = p.episode_id
join patient_custom pc
on pct.patient_id = pc.patient_id
join staff s
on pct.attending_id = s.staff_id
where pc.health_home = 'Y'
group by pct.patient_id, pct.clinic_id, pct.service_id, pct.program_id, pct.protocol_id
order by pct.patient_id, pct.clinic_id, pct.service_id, pct.program_id, pct.protocol_id