Skip to content
Advertisement

remove olde records grouping by three columns and ordering by date

this is the situation:

The problem is: i need delete older records, grouping by col_2, col_3 and col_6 and ordering by col_4. To have the last element bet col_6.

the idea is have something like this:

enter image description here

I test this just for test delete olde record for ‘tabla_tmp_1’:

but does’t work.

Can somebody help me with this?

Best regards

Advertisement

Answer

Use the ROW_NUMBER analytic function to find the rows that are not the latest in each group and then you can use the ROWID pseudo-column to correlate with in the DELETE:

Which deletes 22 rows.

db<>fiddle here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement