拼串的方式實現根據不同的字段進行分頁(儲存過程)

2021-05-11 11:33:26 字數 676 閱讀 8846

以前老師給寫過一次 就是根據你傳入的字段 進行排序分頁 的儲存過程 現在在把它寫出來 算是溫習下把

create proc getbooksbypage

@startindex varchar(10),                                       --開始索引

@endindex varchar(10),                                        --結束索引

@orderby nvarchar(200)                                        --排序的字段

asdeclare @sql nvarchar(200)                                   --拼串後的sql 執行語句 

set @sql=n'select * from (select row_number() over (order by '+

@orderby +

n' ) as rank, * from books ) as t where rank between '+ @startindex+' and '+@endindex

exec sp_executesql @sql                                  --執行上面sql語句

go

MYSQL 根據不同欄位的彙總相同欄位的總數

需求 彙總乙個使用者不同支付方式的購買的總杯數 buy num 杯數 pay code 支付方式 pay name 支付名稱 pay status 支付狀態 ms order 訂單表 ms user 使用者表 select u.id,pay name,u.username,sum buy num a...

oracle根據不同條件給字段賦不同的值

話不多說,先貼 declare cursor my cur is select t.empno,t.deptno,t.sal from scott.emp t where t.empno 7698 for update of sal 鎖定sal這一列,不允許其他session更新sal列的資料 nu...

根據表字段值left join 不同的表

首先說下思路吧,搗鼓了好半天,網上找到解決辦法,大概兩種方法 1.在left join 的後面將兩張表union all連線為一張表,並加上 區分表關鍵字 然後根據 區分表關鍵字 篩選我們需要的資料 2.使用兩個left join,每個left join 跟上一張表,並加上 區分表關鍵字 然後在 o...