SQL Server中選出指定范圍行的SQL語句代碼
更新時間:2008年07月13日 21:14:40 作者:
SQL Server中選出指定范圍行的SQL語句代碼寫法實(shí)例
在數(shù)據(jù)庫查詢的時候,我們有時有這樣的需求,就是要找出數(shù)據(jù)表里指定范圍行內(nèi)的數(shù)據(jù)記錄,比如說要找出數(shù)據(jù)表里第10行到第20行的這10條數(shù)據(jù),那么我們怎么來實(shí)現(xiàn)呢?
按照通常的方法是實(shí)現(xiàn)不了的,我們得借助于臨時表以及一個函數(shù)來實(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--用完后刪除臨時表
這樣我們就實(shí)現(xiàn)了我們的目的。
按照通常的方法是實(shí)現(xiàn)不了的,我們得借助于臨時表以及一個函數(shù)來實(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--用完后刪除臨時表
這樣我們就實(shí)現(xiàn)了我們的目的。