文章詳情頁
sql server數(shù)據(jù)庫中選出指定范圍的行的sql語句寫法
瀏覽:146日期:2023-11-03 08:18:32
在數(shù)據(jù)庫查詢的時候,我們有時有這樣的需求,就是要找出數(shù)據(jù)表里指定范圍行內(nèi)的數(shù)據(jù)記錄,比如說要找出數(shù)據(jù)表里第10行到第20行的這10條數(shù)據(jù),那么我們怎么來實現(xiàn)呢?
按照通常的方法是實現(xiàn)不了的,我們得借助于臨時表以及一個函數(shù)來實現(xiàn)
代碼如下:
Select no=Identity(int,1,1),* Into #temptable From; dbo.teacher_info order by teacher_name--利用Identity函數(shù)生成記錄序號
Select * From #temptable Where no>=10 And no < 20
Drop Table #temptable--用完后刪除臨時表
這樣我們就實現(xiàn)了我們的目的
排行榜
