I'm wondering if there's an easy way to limit a query to the top n windows.
i.e. say I have something like
SELECT field1
,field2
,field3
,sum(field2) over (partition by field1) sum2
,sum(field3) over (partition by field1) sum3
FROM table1
GROUP BY field1, field2, field3
ORDER BY sum2 DESC LIMIT 100
The above query returns the top 100 records, not the top 100 windows (which makes sense)
What I want to get is the top 100 sum2 windows, even though there may be multiple rows inside that window. So I might be getting 400 records, but only the top 100 windows.
Hopefully that makes sense.