I have a table with the structure :
Code | Time | Delete indicator |
---|---|---|
A1 | 2023-07-26 17:00:00 | 1 |
A1 | 2023-07-25 15:00:00 | 0 |
A2 | 2023-07-26 11:00:00 | 0 |
A2 | 2023-07-25 18:00:00 | 1 |
A3 | 2023-07-22 10:00:00 | 1 |
A3 | 2023-07-26 9:00:00 | 0 |
I want a query which gives me all codes which have the most recent updated record with delete indicator as 1. The time can between a provided specific range like 25 july to 30 july.
Expected output :
Code | Time | Delete indicator |
---|---|---|
A1 | 2023-07-26 17:00:00 | 1 |
Output has A1 with time 2023-07-26 17:00:00 because it has delete indicator as 1. Older record should not be taken into consideration
A2 is not there because its most recent record of 2023-07-26 11:00:00 has delete indicator as 0
A3 is not there because its most recent record of 2023-07-26 9:00:00 has delete indicator as 0 and older record of 22 july is anyway out of range
Tried Group by Code but it didnt work because I want all columns in output
2
Answers
This should work
Try this (for two entry comparison):
Try this (for multiple entry comparison):