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 31 32
| With MaTableMax as
(
select max(PK-CH1) as PK-CH1
, PK-CH3
, PK-CH2
, PK-CH7
, PK-CH5
, PK-CH6
, PK-CH4
from MaTable
group by PK-CH3
, PK-CH2
, PK-CH7
, PK-CH5
, PK-CH6
, PK-CH4
)
SELECT t1.PK-CH3, t1.PK-CH2, t1.champ1, t1.champ2, t1.PK-CH5, t1.champ3
FROM MaTable t1
JOIN MaTableMax t2
ON t2.PK-CH3 = t1.PK-CH3
and t2.PK-CH2 = t1.PK-CH2
and t2.PK-CH7 = t1.PK-CH7
and t2.PK-CH5 = t1.PK-CH5
and t2.PK-CH6 = t1.PK-CH6
and t2.PK-CH4 = t1.PK-CH4
and t2.PK-CH1 = t1.PK-CH1
WHERE t1.PK-CH7 = 'ABC'
and t1.PK-CH4 = 'A'
and t1.PK-CH6 = 'ABC'
and t1.PK-CH5 = trunc(t1.PK-CH5, 'MM')
and t1.PK-CH5 between i_date_deb and i_date_fin; |