Title / Description
Code WITH RECURSIVE bubble_sort AS ( SELECT id, value, ROW_NUMBER() OVER (ORDER BY id) AS rn, FALSE AS swapped FROM numbers UNION ALL SELECT n1.id, n1.value, n1.rn, CASE WHEN n1.value > n2.value THEN TRUE ELSE bubble_sort.swapped END FROM bubble_sort JOIN numbers n1 ON bubble_sort.rn = n1.rn JOIN numbers n2 ON bubble_sort.rn + 1 = n2.rn WHERE bubble_sort.swapped = TRUE ) SELECT id, value FROM bubble_sort ORDER BY rn;
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code