sql server 2012 新增 order by 子句的 offset fetch 语法,可以实现分页,或是其它查询需求。 官方文档:https://docs.microsoft.com/zh-cn/previous-versions/sql/sql-server-2012/ms188385v=sql.110)( 示例代码:
select
c.WarehouseGuid,c.UseOrgGuid,o.Name_CN as Lydwmc,c.BillDate,c.BillNO,c.RowNO,c.RowGuid
from STK_MaterialPick_YnDyeFab b
left join STK_MaterialPickDetail_YnDyeFab c on c.BillTypeCode = b.BillTypeCode and c.BillDate = b.BillDate and c.BillNO = b.BillNO
left join BAS_Material_YnDyeFab d on d.Guid=c.MaterialGuid
left join BAS_OrgFrame o on o.Guid=c.UseOrgGuid
where 1=1
and c.BillDate>'2017/08/01'
and b.CancelUser is null
and c.BaseQuantity>=0
order by b.BillNO desc
offset (50-1)*15 row fetch next 15 rows only --获取第50页,第页15条记录
经测试 OFFSET FETCH
查询的记录在表中越靠后(页码越大),开销会更大。