SQL server從入門精通----3種分頁

來源:互聯網
上載者:User

標籤:

--分頁語句--max id分頁select top 4 * from District where id>(select ISNULL(max(id),0) from (select top 2 id from District order by Id) a)--not id 分頁select top 4 * from District where id not in(select top 2 id from District )--ROW_NUMBER分頁select * from (select  ROW_NUMBER() over(order by id) as number,* from District) a where number<=6 and number>=3--row_number over 講解--就是給查詢到的資料從1編號--文法一select ROW_NUMBER() over(order by id desc),* from District  --以id降序查詢在編號,當然去到desc預設是升序--文法二select ROW_NUMBER() over(partition by name order by id),* from District --以name列分組在以id升序查詢編號--注意:over裡面的分組與排序執行等級是要低於 “where,group by,order by”的執行。 ---------也就是是說會先把外面的的執行晚,在執行裡面的,這樣就會覆蓋外面的 group by,order by;--最好是用id max方法 效率最高--當然也可以用預存程序進行分頁,但相比之下效率是最低的

 

SQL server從入門精通----3種分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.