An orders table:
orders (
order_id INTEGER, -- unique
amount INTEGER
)
Assign each order to a quartile from 1 (highest amounts) to 4 (lowest
amounts) by splitting the orders into 4 groups of as-equal-as-possible size,
highest amounts first. Break ties on amount by order_id ASC. When the row
count does not divide evenly by 4, earlier quartiles get the extra rows.
Return columns: order_id, amount, quartile.
Order by quartile ASC, then amount DESC, then order_id ASC.