A familiar question, but with Vertica. I would like to return the top 5 lines of geo_country based on sum (imps) for each tag_id. This is the query that I started:
SELECT tag_id, geo_country, SUM(imps) AS imps, RANK() OVER (PARTITION BY tag_id ORDER BY SUM(imps) DESC) AS rank FROM table1 WHERE tag_id IN (2013150,1981153) AND ymd > CURRENT_DATE - 3 GROUP BY 1, 2 LIMIT 10;
This actually returns only the rows from the first tag in the WHERE clause (2013150). I know that another tag has imps values โโthat are high enough to include it in the results.
Also, how do I implement part of Top N? I tried adding a LIMIT clause to the OVER function, but it does not look like it is a recognized parameter.
source share