关于分页

//简单思路

select* from
(
  select *, row_number() over 

  (order by ClientID desc) rowno 

   from FMCORPORATION
) Ftable
  where Ftable.rowno > (pageindex-1)*pageindex and Ftable.rowno <= pageindex *10

go

例子:


select* from (
  select p.ProductName,p.TotalHL,p.Producer,d.DEpName,p.AuditingState, row_number() over
  ( order by FMCode desc ) PID
  from Product as p
  LEFT JOIN FMCORPORATION f on f.ClientID=p.ClientID
  LEFT JOIN department d on d.DptID=f.DptID
  where d.path like '%XX%' and AuditingState=1

//如果有条件查询请写在这层select  不然数据会不准确 会有pid不准确
) FDP
where FDP.PID > 0 and FDP.PID <= 10
go

原文地址:https://www.cnblogs.com/fuyao/p/10819807.html