2021 Sep 07 1:32 PM
Hi,
I have a couple of records that look like this:

TYPE and CODE are each two key fields
The Goal:

The ones marked in red are the records that have to be deleted.
How it works: It should delete the data records which already exist of the TYPE at least 4 times. The smallest CODE should always be deleted.
Important: CODE is a char3 field.
Does anyone know how I can do that with open sql in sap?
Thanks!
2021 Sep 07 2:06 PM
Must it be done with a single SQL statement? If it does, is that a test/exam question? What will we get if we pass the exam for you?
If it's not, why do you bother about the way to do it. Just think about an algorithm that does the work and code it. Using sub-selects you should be able to do that, but I really don't like them, so I will not think about it, sorry.
At least not until you'll show you've put some effort while thinking about it.