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;<=&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