Rank results by the values in a column:

SELECT \*, RANK() OVER (PARTITION BY column1 ORDER BY column2 DESC) AS rnk
FROM table

Restrict the number of results to return only the top or bottom X results

SELECT \*, RANK() OVER (PARTITION BY column1 ORDER BY column2 DESC) AS rnk
FROM tableSELECT \*
FROM (
 SELECT \*, RANK() OVER (PARTITION BY keywords ORDER BY impressions DESC) AS rnk
 FROM a1
) AS x
WHERE rnk \<= 17
;