Problems / Fill With Group Mode / Editorial
(category, color)
ROW_NUMBER() OVER (PARTITION BY category ORDER BY cnt DESC, color)
rn = 1
COALESCE(color, mode_color)
Statistical imputation in SQL is a derive-then-join pattern (compute the per-group statistic, join it under the holes) — but the deeper lesson is about *determinism as a requirement*. Built-in mode() aggregates are allowed to return either winner of a tie, which means the same query can produce different results across runs, engines, or even row orders — poison for tested pipelines. Building the mode from COUNT + ROW_NUMBER with a total ordering costs three lines and buys reproducibility; the same construction gives deterministic "argmax" for any statistic an engine won't pin down.
mode()
COUNT
ROW_NUMBER
Solve Fill With Group Mode yourself →