
I have the following query:
select y.record_id, w.sample_point, w.analysis_id, w.component,y.target_samples, y.number_sampled, count( w.assigned_event) as collected
from wtm_ytf_view y,
wmm_comp_anal_samp w
where y.analysis_id = w.analysis_id
and y.analysis_version = w.analysis_version
and y.scheduled_year = w.for_year
and y.schedule = w.schedule_id
and y.record_id = w.record_id
and y.component = w.component
and y.scheduled_year = '2009'
and w.anal_status ='C'
group by y.record_id,w.sample_point,w.analysis_id,w.compone nt,y.target_samples, y.number_sampled
UNION
select y.record_id, w.sample_point, w.analysis_id, w.component,y.target_samples, y.number_sampled, count( w.date_assigned) as programmed
from wtm_ytf_view y,
wmm_comp_anal_samp w
where y.analysis_id = w.analysis_id
and y.analysis_version = w.analysis_version
and y.scheduled_year = w.for_year
and y.schedule = w.schedule_id
and y.record_id = w.record_id
and y.component = w.component
and y.scheduled_year = '2009'
and w.samp_status <>'X'
and w.anal_status <>'X'
group by y.record_id,w.sample_point,w.analysis_id,w.compone nt,y.target_samples, y.number_sampled;
But the second part of the union never populates the 'programmed' value as the selects are from the same tables...any ideas how I can get the 'programmed' value populated?
I'm after :
record_id,point,analysis,component,target,sampled, collected,programmed