My table is like:
x
2021-03-01
2021-03-02 (for exmp. 3rd March is holiday and not including to table)
2021-03-04
2021-03-05
2021-05-03
2021-05-04
2021-05-05
2021-05-06
2021-05-07
And I should get result as 2021-03-05 for march, and 2021-05-06 for may.
So every month I should get the 4th row as date result.
Advertisement
Answer
You can use row_number()
. But the real trick are the date functions. Let me assume that your database supports year()
and month()
:
select t.*
from (select t.*,
row_number() over (partition by year(col), month(col) order by col) as seqnum
from t
) t
where seqnum = 4;