代碼正在運行,但頂級(X)TOP PRICE未被相應提取。我如何在代碼中使用Ties?
某些top(x)被忽略。Oracle PL/SQL查詢
這是我的表
STAFF_NUMBER STAFF_NAME PRICE
------------ ----------------------------------------- ----------
36 Helen Hilfg 330066
52 Octavia Chan 356885
36 Helen Hilfg 176088
4 Heidi Lee 231046
6 Jill Murphy 469844
32 Lily Roy 247549
58 John Roy 309299
這是我得到
SQL> SQL> SQL> exec p4(3)
PERSON# NAME
36 Helen Hilfg
52 Octavia Chan
4 Heidi Lee
這是我想拿到
SQL> exec p4(3);
PERSON# NAME
--------------------
36 Helen Hilfg
6 Jill Murphy
52 Octavia Chan
這裏是我的程序
CREATE OR REPLACE PROCEDURE p3(X NUMBER)
AS
staff_number NUMBER ;
staff_name VARCHAR2(30) ;
CURSOR c1 IS
SELECT staff_number,
staff_name
FROM (SELECT P.peid staff_number,
P.firstname || ' ' || P.lastname staff_name ,
D.price PRICE
FROM Contact C,
Deal D,
Person P,
Staff S
WHERE S.peid = C.peid
AND C.pno = D.pno
AND P.peid = C.peid
AND (SYSDATE - D.day < 365))
WHERE ROWNUM <= X
GROUP BY staff_name , staff_number
ORDER BY SUM(price) DESC ;
BEGIN
dbms_output.put_line(' PERSON# ' ||' '||' NAME ');
FOR R IN c1
LOOP
staff_number := R.staff_number ;
staff_name := R.staff_name ;
dbms_output.put_line(staff_number ||' '|| staff_name) ;
END LOOP ;
END;
/
代碼正在運行,但頂部(X)TOP PRICE未被相應提取。我如何在代碼中使用Ties?
某些top(x)被忽略。
什麼版本的Oracle? 9i +支持分析(IE:ROW_NUMBER),儘管技術上它們可用於8i –
Oracle數據庫10 – shakur007
從調試遊標查詢開始 - 正在爲初學者正確使用「ROWNUM」。 –