1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
select
req.aaref,
req.num,
tmpfin.cotis as cotis1,
tmpfin.lib as lib1,
case when req.minrow<>req.maxrow
then (select asscotis.cotis as cotis
from TABLE_TMP asscotis
where asscotis.numrow = req.maxrow)
else null
end as cotis2,
case when req.minrow<>req.maxrow
then (select libelle.lib as lib
from TABLE_TMP libelle
where libelle.numrow = req.maxrow)
else null
end as lib2
from ( select tmp.aaref, tmp.noide,
min(tmp.numrow) as minrow,
max(tmp.numrow) as maxrow
from TABLE_TMP tmp
group by tmp.aaref, tmp.noide
) as req
inner join
TABLE_TMP tmpfin
on (req.aaref=tmpfin.aaref and req.num=tmpfin.num)
where tmpfin.numrow=req.minrow |