Correlated Subquery part of Select List
I see alot of examples of a correlated subquery on the right of a "WHERE" clause, but what about when it is part of the select list, as follows:
select distinct t.personnum,
t.applydate,
round(t.wfctimeinseconds/3600,2) as amount,
substr(c.customdata,1,1) as shift,
(select count(*) from vp_alltotals
where personnum = t.personnum
and applydate = t.applydate
and wfctimeinseconds = t.wfctimeinseconds
and paycodename = 'Shift Differential') as NumShiftDiff
from vp_alltotals t,
vp_personcustdata c
where
c.personnum = t.personnum;
This query is really bogging down badly when this select list includes what looks to me like a correlated subquery. Are there better ways to code this ? Use temp tables ?
Gil
|