oracle sql to get min timestamp when the count of results large than a number -
in order improve performance, need sql implement following requirement.
if there table , has following column:
id timestamp value
how can min timestamp(e.g. :t1) when count of result > 100000 ?
then following sql result--count(*) > 100000
select count(*) table timestamp < :t1
my understanding of question is: find earliest timestamp in table there @ least 100,000 earlier rows.
there many ways it; main difficulty trying come efficient one.
i think analytic-function approach work well. obvious choice use count:
select min(timestamp) ( select timestamp, count(*) on (order timestamp rows between unbounded preceding , 1 preceding) earlier_rows table ) earlier_rows >= 100000
but suspect using rank or similar faster:
select min(timestamp) ( select timestamp, rank() on (order timestamp) time_rank table ) time_rank > 100000
i'm not sure off top of head, these may give different results if there duplicate timestamps.
Comments
Post a Comment