ROW_NUMBER()
window function to assign a row number to each row based on the ascending order of first_col
. This will be a Common Table Expression (CTE) named first_col_ordered
.ROW_NUMBER()
window function to assign a row number to each row based on the descending order of second_col
. This will be another CTE named second_col_ordered
.first_col_ordered
and second_col_ordered
on their respective row numbers.first_col
from first_col_ordered
and second_col
from second_col_ordered
to get the final result set.first_col_ordered
to ensure the rows are returned in the correct order.erDiagram Data { int first_col int second_col }