sql 分頁 後台分頁技術

2021-09-26 07:08:23 字數 1388 閱讀 3302

select stunumber,stuname,

case

when stumath>=

90then

'優'when stumath>=

80then

'良'when stumath>=

70then

'中'else

'差'end

as 數學成績

from tbstudent

--第一種用法

--case語句就是構造乙個新的列

--一列上的資料型別必須一樣 必須要有end

--類似於if.....else..

--第二種用法 類似與switch case

--子查詢高階應用

--分頁查詢

select

top(5)

*from tbstudent

select

top(5)

*from tbstudent

where stuid notin(

select

top(

5) stuid from tbstudent)

--m是頁數,n是一頁有幾條

select

top(n)

*from tbstudent

where stuid notin(

select

top(

(m-1

)*n) stuid from tbstudent)

--第二種分頁

select

*from

(select

*,row_number(

)over

(order

by stuid asc

)as rownumber from tbstudent

)as tb1

where tb1.rownumber between0*

5+1and1*

5--當子查詢的結果集作為主查詢的資料來源時,必須給子查詢的結果集起別名

在mysql中我們想實現分頁的話我們可以使用limit函式

/*當沒有指定位置偏移量時,只取4條時,可以這樣寫*/

select

*from yourtablename limit

4;

/*當指定了位置偏移量時,從第3條起取4條時,可以這樣寫*/

/*因為索引是從0開始計數的,所以第3條對應的索引就是2*/

select

*from yourtablename limit2,

4;

我們可以通過這種方式設定偏移量的方式實現後台分頁,我們limit後面的兩個引數變成變數就可以達到控制分頁的條數。

SQL 後台分頁(C ,mysql)

以前資料量不多,一般直接在前端分頁 後來隨著大資料時代的到來,同時考慮前端的效能問題,後台分頁漸漸提上議程。搞起 歸根到底都是sql語句問題,後台service主要是處理了中間的邏輯問題。這裡要注意的是 這個層面解決的問題主要是引數傳遞問題,比如當前頁數,總頁數,每頁資料條數,總記錄數等 這個就看個...

sql 分頁技術

create table tb page pid int primary key identity 1,1 pname varchar 100 drop table tb page declare count int,num int,sql varchar max pname varchar 100...

EasyUI分頁(前台分頁和後台分頁)

分頁包括前台分頁和後台分頁兩種,針對資料量比較小的,比如說單位,角色等,可以使用前台分頁,而針對日誌檔案這些,需要後台分頁。先說說前台分頁吧 function pagerfilter data var dg this var opts dg.datagrid options var pager dg...