hi have data this:
otord# otusrn ottrnc ojhttn$ ottrnd ---------------------------------------------------------------------- 123 joe aaa 100.00 07/17/15 123 joe bbb 100.00 07/16/15 i made select: want select distinct on order # , amt. want show otusrn , code part of distinct. want 123 , 100$ unique 'tag along' other columns do?
select distinct otord#, ohttn$, ottrnd replib.clspaytpl otusrn in ('andon', 'sch', 'jru', 'bert', 'tra', 'lina') , ottrnd >= 20140701
to retrieve first detail record in group joined header record can use syntax this:
with head (otord#, ojhttn$) ( select distinct otord#, ojhttn$ replib.clspaytpl otusrn in ('andon','sch','jru','bert','tra','lina') , ottrnd >= 20140701) select h.otord#, h.ojhttn$, d.otusrn, d.ottrnc, d.ottrnd head h, table (select * replib.clspaytpl otord# = h.otord# , ojhttn$ = h.ojhttn$ , otusrn in ('andon','sch','jru','bert','tra','lina) , ottrnd >= 20140701 fetch first row only) d if have real header file contains 1 record per order/amount, can use instead of cte (common table expression).
Comments
Post a Comment