I have a table with historical option prices, and I would like to select for each day the contract(s) that have the closest expiration date. Below is a min examples:
Date ExpDate Unique Contract ID
1/1/2022 2/1/2022 1
1/1/2022 3/1/2022 2
2/1/2022 3/1/2022 3
2/1/2022 4/1/2022 4
For this table I would like to obtain this:
Date ExpDate Unique Contract ID
1/1/2022 2/1/2022 1
2/1/2022 3/1/2022 3
Not sure if this could be done with maybe a group by
? The query below isn't working as it won't allow me to select all the columns for some reason:
SELECT *, MIN(ExpDate)
FROM table_name
GROUP BY Date