If you want to partition by OrarioA
only:
SELECT OrarioA, OrarioB, IDOrario, IDDettaglioOrarioA, IDDettaglioOrarioB
FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY OrarioA ORDER BY OrarioB DESC, IDOrario DESC) AS rn
FROM table
) t
WHERE rn = 1
, this will result in the resultset as on picture 2
.
If you want to partition by OrarioA
and OrarioB
:
SELECT OrarioA, OrarioB, IDOrario, IDDettaglioOrarioA, IDDettaglioOrarioB
FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY OrarioA, OrarioB ORDER BY IDOrario DESC) AS rn
FROM table
) t
WHERE rn = 1
, but this won't filter out the first row in your resultset.
Quassnoi
2009-02-16 19:30:33