I have the following SQL
select c.course_code, c.course_description, ri.defin, rm.defmaybe, ro.defout
from applicant a
inner join preference p on a.ref_num = p.ref_num and p.institution_code = 'UT'
inner join course c on p.course_code = c.course_code
left join (
select ref_num, course_code, offering_id, count(*) as defin
from preference_status
where component_group = 'RS'
and component_value = 'IN'
group by 1,2,3
) as ri on a.ref_num = ri.ref_num and p.course_code = ri.course_code and p.offering_id = ri.course_code
left join (
select ref_num, course_code, offering_id, count(*) as defmaybe
from preference_status
where component_group = 'RS'
and component_value = 'MAYBE'
group by 1,2,3
) as rm on a.ref_num = rm.ref_num and p.course_code = rm.course_code and p.offering_id = rm.course_code
left join (
select ref_num, course_code, offering_id, count(*) as defout
from preference_status
where component_group = 'RS'
and component_value = 'OUT'
group by 1,2,3
) as ro on a.ref_num = ro.ref_num and p.course_code = ro.course_code and p.offering_id = ro.course_code
group by 1,2,3,4,5
order by 1
;
However, I am getting zero counts per left join in the select. I've tried different variations including adding the subquery select count(*) from
in the select with no luck either.
Any ideas would be greatly appreciated.
Although this probably won't fix your problem, there is no need for multiple subqueries:
I don't know if this will fix your problem, though.