使用SQL查詢如何獲得2列的輸出,第一列是按asc順序排序的列,第二列是排序順序desc和是同一列。如何按順序排序和排序順序排列相同的列
例如:
emp table:
empid
1
5
9
4
查詢輸出應該
empid_1 empid_2
1 9
4 5
5 4
9 1
什麼OP試過到目前爲止
WITH emp1
AS (SELECT ROWNUM a,
empno
FROM (SELECT empno
FROM emp
ORDER BY 1 ASC)),
emp2
AS (SELECT ROWNUM b,
empno
FROM (SELECT empno
FROM emp
ORDER BY 1 DESC))
SELECT emp1.empno,
emp2.empno
FROM emp1,
emp2
WHERE emp1.a = emp2.b;
@visakh:下面是我試圖 與EMP1如( 選擇ROWNUM一個,從(通過EMPNO 1個ASC從EMP順序選擇EMPNO) ), emp2 as( select rownum b,empno from(select empno from emp order by 1 desc) )select emp1.empno,emp2.empno from emp1, – Avinash
請修改問題而不是評論。 –