यह दो नेस्टेड विंडो फ़ंक्शंस का उपयोग करके किया जा सकता है
SELECT
id
FROM (
SELECT
id,
color,
score,
((rank() OVER color_window) - 1) / 2 AS rank_window_id
FROM grouping_test
WINDOW color_window AS (PARTITION BY color ORDER BY score DESC)
) as foo
WINDOW rank_window AS (PARTITION BY (color, rank_window_id))
ORDER BY
(max(score) OVER rank_window) DESC,
color;
2
के साथ समूह आकार का पैरामीटर होने के नाते।