資料庫複習總結(15) 子查詢(分頁)

2022-02-08 06:01:32 字數 1640 閱讀 1685

子查詢:

(1)將乙個查詢語句嵌入另乙個查詢語句中,稱這種查詢為子查詢

(2)出現在條件部分常用的運算子:= 、in 、exists(exists和in效果相同,但是exists效率高些)

(3)分頁:已知頁大小、頁索引,查詢出當前頁的資料

提示1:排名函式row_number(),結合開窗函式over(order by 列名)進行排序號

提示2:between ... and ...

例1:(in和exists)

查詢參與了考試的學生資訊 exists in

select

*from

studentinfo

where sid in(select

distinct stuid from

scoreinfo)

select

*from

studentinfo

where

exists

(select

*from scoreinfo where scoreinfo.stuid=studentinfo.sid)

view code

2、分頁

(1)提供索引

select*,

row_number()

over(order

by sid desc) as

rowindex

from studentinfo

view code

(2)舉例子

--

分頁 已知:頁大小(一頁顯示多少條資料),頁索引

資料庫分頁查詢總結

公司無聊的情況下,總結下這段時間面試中遇到到一些問題,先來說資料的分頁查詢 oracle分頁 select from select a.rownum,rn from select from table a where rownum 40 where rn 20 mysql 分頁 1 一般最基本的分頁...

資料庫複習總結(9) 聯合查詢

聯合查詢 將多個查詢的結果集合並成乙個結果集 聯合要求 結果集列數要一致 對應列的型別要一致 關鍵字 union 合併,排序 消除重複項 union all 合併 不排序 不消除重複項 except 差集 intersect 交集 用處 在查詢結果處顯示彙總 例子 select cid from c...

資料庫查詢分頁。

csdn上推薦的,轉過來的。呵呵!表中主鍵必須為標識列,id int identity 1,1 1.分頁方案一 利用not in和select top分頁 語句形式 select top 頁記錄數量 from 表名 where id not in select top 每頁行數 頁數 1 id fr...