Skip to content

2159. Order Two Columns Independently 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
WITH
  FirstCols AS(
    SELECT
      first_col,
      ROW_NUMBER() OVER() AS `row_number`
    FROM Data
    ORDER BY 1
  ),
  SecondCols AS (
    SELECT
      second_col,
      ROW_NUMBER() OVER() AS `row_number`
    FROM Data
    ORDER BY 1 DESC
  )
SELECT
  FirstCols.first_col,
  SecondCols.second_col
FROM FirstCols
INNER JOIN SecondCols
  USING (`row_number`);