SQL Server records How to write several pages of top n data

Source: Internet
Author: User

Data sheet: Bus_visitorstatics

1, open the window function realization:

 SELECT  *FROM     ( SELECT    * ,                      Row_number ()  OVER  ( partition by visitordate order by count desc  )  AS  ' num '           FROM       BUS_VisitorStatics        )  as tb1where &NBSP;&NBSP;&NBSP;TB1.NUM&NBSP;&LT;=&NBSP;10&NBSP;2, LINQ implementation:dbcontext dd = new  Szadminentities ();  list = dd. Set<bus_visitorstatics> (). OrderByDescending (P => p.count). ToList (); var result = from n in list                          group n  by n.visitordate                              into g                               orderby g.Key                               select new                              {                                   date = g.key,                                   datelist = g.orderbydescending (p = > p.count). Take (Ten),                              };var wordlist =  New list<bus_visitorstatics> ();             foreach  (Var item in result)              {                 if  (Item.dateList.Count ()  > 0)                  {                     foreach  (var o in item.datelist)                      {                          var mod = new bus_visitorstatics ();                          mod. visitordate = item.date;                         mod. count = o.count;                         mod. keyword = o.keyword;        &Nbsp;               wordlist. ADD (MoD);                     }                 }            } return  WORDLIST;&NBSP;3, plain SQL implementation: Select  *from    bus_visitorstatics as awhere     ( select    count (*)            FROM      BUS_VisitorStatics AS b           where     a.visitordate = b. visitordate                     and a.count < b.count        )  < 10order by a. Visitordate ,a.count desc

SQL Server records how many pages to fetch top N data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.