oracle多表查詢

2021-08-08 18:45:16 字數 873 閱讀 6712

分頁查詢

oracle的表中都有兩個偽列,可用於指定行號:

1>rownum:會根據查詢到的行記錄的改變而改變.如,smith行在第一行那麼rownum就是1,smith行在第4行,那麼rownum就是4.

2>rowid:固定行號,不會根據查詢到的行記錄的改變而改變。

如,smith行在第一行rowid就是1,在第四行還是1

固定格式

*select from (select a.*,rownum rn from (被分頁的select資料) a)

where rn>=起始行 and rn<=結束行;**

-從emp表中獲取第二頁資料(即4~6行,即rownum值在4~6之間)

select * from (select e.*, rownum rn from emp e)where rn>=4 and rn<=6;

–刪除資料完全相同的行,只保留一行(rowid用法)

delete from stu where rowid not in

(select min(rowid) from stu group by sno,sname,***,score);

多表查詢

n張表進行組合查詢,有效的篩選條件至少是n-1個。

select e.ename,e.sal,d.dname,s.grade from emp e,dept d,salgrade s

where e.deptno = d.deptno and e.sal between s.losal and s.hisal;

自連線查詢(特殊的多表查詢)

Oracle 多表查詢

sql 外連線 sql 按部門統計員工人數 部門號 部門名稱 人數 sql select d.deptno,d.dname,count e.empno 2 from dept d,emp e 3 where d.deptno e.deptno 4 group by d.deptno,d.dname ...

Oracle 多表查詢

等值和不等值連線查詢 為了避免笛卡爾集,可以在 where 加入有效的連線條件。oracle 連線多表查詢 在 where 子句中寫入連線條件。在表中有相同列時,在列名之前加上表名字首 select table1.column,table2.column from table1,table2 whe...

oracle 多表查詢

多表查詢 多表查詢,又稱表聯合查詢,即一條sql語句涉及到的表有多張,資料通過特定的連線進行聯合顯示.笛卡爾積 在數學中,兩個集合x和y的笛卡尓積 cartesian product 又稱直積,表示為x y.假設集合a 集合b 則兩個集合的笛卡爾積為。在資料庫中,如果直接查詢倆張表,那麼其查詢結果就...