Hello I have written a query for Oracle 7. It should
get max date and group by two fields. Now Based on
the max I would like also the query to return the remaining
fields for each row returned meeting that criteria.
The query is below but it is too long. You will notice
the select max part of it is the main logic.
WHat is the optimal way of writing it. Please remember it is oracle 7 you cannot use the partition over function.
See below. Thanks
select distinct c.oriontank, e.disp_tankname, d.orionprop, a.rslt_value, a.rslt_value, 0,
'', 'LMS', sysdate, user, 0 , to_date(to_char(b.smpl_dt, 'dd/mm/yyyy') || ' ' || b.smpl_tm || ':00' , 'dd/mm/yyyy hh24:mi:ss'), 0, 0
from totalplant.ip_tst_rslt a, totalplant.ip_smpl b, ps_lims_pnt_map c, ps_lims_prop_map d, ps_phd_data_map e
where a.smpl_name = b.smpl_name
and b.type = 'S'
and b.smpl_pnt_name||a.prprty_name||b.smpl_dt in
( select a.smpl_pnt_name||b.prprty_name||max(a.smpl_dt)
from totalplant.ip_smpl a, totalplant.ip_tst_rslt b, ps_lims_pnt_map c, ps_lims_prop_map d, ps_phd_data_map e
where
a.smpl_name = b.smpl_name
and a.type = 'S'
and a.smpl_pnt_name = c.smpl_pnt_name
and b.prprty_name = rtrim(d.propname)
and e.oriontank = c.oriontank
and ( a.smpl_dt < sysdate - 1 and a.smpl_dt > sysdate - 7 )
and isnum(b.rslt_value) = 0
group by a.smpl_pnt_name,b.prprty_name
)
and b.smpl_pnt_name = c.smpl_pnt_name
and a.prprty_name = rtrim(d.propname)
and e.oriontank = c.oriontank
and isnum(a.rslt_value) = 0
/
get max date and group by two fields. Now Based on
the max I would like also the query to return the remaining
fields for each row returned meeting that criteria.
The query is below but it is too long. You will notice
the select max part of it is the main logic.
WHat is the optimal way of writing it. Please remember it is oracle 7 you cannot use the partition over function.
See below. Thanks
select distinct c.oriontank, e.disp_tankname, d.orionprop, a.rslt_value, a.rslt_value, 0,
'', 'LMS', sysdate, user, 0 , to_date(to_char(b.smpl_dt, 'dd/mm/yyyy') || ' ' || b.smpl_tm || ':00' , 'dd/mm/yyyy hh24:mi:ss'), 0, 0
from totalplant.ip_tst_rslt a, totalplant.ip_smpl b, ps_lims_pnt_map c, ps_lims_prop_map d, ps_phd_data_map e
where a.smpl_name = b.smpl_name
and b.type = 'S'
and b.smpl_pnt_name||a.prprty_name||b.smpl_dt in
( select a.smpl_pnt_name||b.prprty_name||max(a.smpl_dt)
from totalplant.ip_smpl a, totalplant.ip_tst_rslt b, ps_lims_pnt_map c, ps_lims_prop_map d, ps_phd_data_map e
where
a.smpl_name = b.smpl_name
and a.type = 'S'
and a.smpl_pnt_name = c.smpl_pnt_name
and b.prprty_name = rtrim(d.propname)
and e.oriontank = c.oriontank
and ( a.smpl_dt < sysdate - 1 and a.smpl_dt > sysdate - 7 )
and isnum(b.rslt_value) = 0
group by a.smpl_pnt_name,b.prprty_name
)
and b.smpl_pnt_name = c.smpl_pnt_name
and a.prprty_name = rtrim(d.propname)
and e.oriontank = c.oriontank
and isnum(a.rslt_value) = 0
/