[英]Extract specific rows from a table in Oracle
我想寫一個查詢,將查詢表中的前3個記錄
下表是詳細信息
select * from employee_src
現在要獲得以上結果,我正在使用以下查詢
select fname,lname,ssn,salary,dno from employee_src where rownum <=3
union all
select fname,lname,ssn,salary,dno from (select fname,lname,ssn,salary,dno from employee_src order by rownum desc) where rownum <=3
在運行此查詢時,我得到以下結果
即使我得到前3行和后3行,但后3行的順序也不像原始表中那樣。 如何解決此問題。
嘗試這個。
select * from (select * from employee_src order by rownum Asc) where rownum <= 3
union all
select *, from ( select * from employee_src from dual order by rownum desc
) as employee_src_last3
where rownum <= 3
現在試試...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.