Use PostgreSQL LATERAL joins for top-N per group, correlated subqueries, and set-returning function compositions.
Describe query problem, N value for top-N, slow correlated query, time series needs, JSONB unnest requirements, and alternative approach.
Initial release
Sign in and download this prompt to leave a review.