In this test table, with below data. Even though how many entries are there, need to pick the first valid record for that day. Also, there is chance that for that day where rank no might increase.
A | B | STATUS | LOAD_DATE | RANKNO | |
---|---|---|---|---|---|
SAMPLE | SAMPLE | VALID | 10-Jan-22 | 3 | |
SAMPLE | SAMPLE | INVALID | 10-Jan-22 | 5 | |
SAMPLE | SAMPLE | VALID | 10-Jan-22 | 6 ** | |
SAMPLE | SAMPLE | VALID | 1-Jan-22 | 10 | |
SAMPLE | SAMPLE | INVALID | 1-Jan-22 | 12 | |
SAMPLE | SAMPLE | INVALID | 1-Jan-22 | 12 |
For Jan 10, 2022 the expected output is, line:
A | B | STATUS | LOAD_DATE | RANKNO |
---|---|---|---|---|
SAMPLE | SAMPLE | VALID | 10-Jan-22 | 6 ** |
We can do select * from test where rankno = 6
(this is for 10-jan-22) but there might be chance that for 11-jan-22 there will be only 2 records, we need to pick record with highest rankno
if I query with Load_date, it should fetch valid record with highest rankno.
SELECT A, B, Status, load_date
FROM test
WHERE status = 'VALID'
AND ....
or can we?
SELECT max(rankno)
FROM test
WHERE load_date = '10-JAN-22'