I am attempting to find the minimum run_date in a table where there are more than 10 run dates. In other words if there are 12 run dates in the table I want the date of the 11th run_date so I can delete all the records with run dates older than that date. This is the SQL I was attempting to get this data:
select min(a.run_dt), '1' as sequence, CSUM(sequence,a.run_dt) seq from ( select run_dt from table_name group by run_dt ) a order by run_dt having seq > 10 ;
But, I am getting the following error: 5876: Ordered Analytical Functions not allowed in HAVING Clause.
Can someone recommend another way to obtain this data. The SELECT will eventually be changed to a DELETE