skystore 2018-09-17 08:49 采纳率: 0%
浏览 4924

ROW_NUMBER() OVER(order by ) 多表分页查询,查询速度比较慢,怎么解决?

例:select * from(
select , ROW_NUMBER() OVER(order by t1.photo_keyName desc) as Row from
(select table1.
,table2.car_id,table3.photo_keyName from table1 inner join table2 on table1.DS_Lack=1 and table1.DS_CarNum = table2.car_no left join table3 on table2.car_id=table3.type_id)as t1
) as t2
where t2.Row between 1 and 10

实际查询语句中,会有计算字段,会用到union, 最终查一个30条的结果集,要2,30 秒以上;

查询语句:
SELECT
TOP 20 *
FROM
(
SELECT
ROW_NUMBER () OVER (ORDER BY t.JieAnDate Desc) RowNumber, * from (Select A.PId, A.SaleNo, A.ProductName, A.SizeModel, A.CodeName, A.MethodDesc, A.Period, A.Price, A.SamNum,
A.OtherFee, Convert(numeric(12,2),ISNULL((Case when K.Pref_Price is not null Then K.Pref_Price WHEN K.Pref_Price IS NULL THEN B.Pref_Price end),0)) TestFee, A.State,
(Case when A.JieAnDate is not null Then A.JieAnDate WHEN A.JieAnDate IS NULL THEN B.AppointmentTestDate end) JieAnDate,
A.JieAnUser, A.AddressNo, A.Memo, A.JiaoFuMemo, A.Fee_Price_Number, FB1,
H.CustNameCn CustName,'未确认收入' StateName,(Case when K.ItemNo is not null Then K.ItemNo WHEN K.ItemNo IS NULL THEN A.SaleNo end) ItemNo,
Round(Convert(numeric(12,2),(Convert(numeric(12,5),ISNULL((Case when K.Pref_Price is not null Then K.Pref_Price WHEN K.Pref_Price IS NULL THEN B.Pref_Price end),0))*Convert(numeric(12,5),IsNull(B.Per,1)))),4) Price_RMB
From (
SELECT *,'' sequence FROM CRM_Sale_Order_Info WHERE SaleNo in (select SaleNo from CRM_Sale_Price_Info where DataType!='2')
union
select * from (select * , row_number() over(partition by saleNo order by PID) as sequence from CRM_Sale_Order_Info where SaleNo in (select SaleNo from CRM_Sale_Price_Info where DataType='2') ) FA where sequence =1) A
left join CRM_Sale_Price_Info B on A.SaleNo=B.SaleNo
Left Join CRM_KaiAn_Info K On A.PId=K.OrderCode
Left Join LIMS_Sale_Cust_Info H On B.CustId=H.CustId
Left Join LIMS_Sale_Cust_Contact I On B.ContactId=I.ContactId
Left Join LIMS_Sys_UserInfo J On B.UserId=J.UserId
Where A.State=10
And A.PId Not In (Select OrderCode From CRM_CaiWu_QueRen) And ISNULL(B.DataType,'1') in ('1','2')) t) queryA
WHERE
queryA.RowNumber > (1 - 1) * 20

  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2018-09-17 18:28
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器