Skip to content
Advertisement

Oracle 11g – Exclude records from set where the hour column is greater than

Consider the following, minimal example:

I’d like to exclude the record where KEY3 is 1275, because its HOUR is greater than that of the record where KEY3 is 1504.

I tried the following, but to no success (I expected KEY4 to be 1504):

So essentially, what I’d like to do, in Oracle 11g, is to keep only the records whose hour is the earliest, for the same KEY1, KEY2 pair.

How would I do this?

EDIT: Here’s a more complete example:

Desired output for the above:

SQLFiddle containing the sample data here.

Advertisement

Answer

You are close but you need a subquery to filter and the right logic for the minimum:

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