MySql left join 多表连接查询优化语句

先过滤条件然后再根据表连接 同时在表中建立相关查询字段的索引这样在大数据多表联合查询的情况下速度相当快

SELECT M.*,SS.SensorCode,SS.SensorStatus,SS.ManufacturerId,SS.Electricity,
SS.Voltage,SS.MinElectricity,SS.MinVoltage,SS.Temperature,SS.StatusUpdteDate,SS.UpdateStatus ,tp.PricingStrategyid,tps.FreeDuration,bat.BerthTypeId 
FROM
(SELECT T.* , BS.ParkStatus,BS.ChangeTime ,CA.CantonName, SE.SectionName
 FROM
(SELECT A.* ,B.BerthId,B.BerthCode,B.BerthAddress,B.BerthStatus,B.LineDirection,B.CantonId,B.SectionId 
FROM 
(SELECT AR.AreaId,AR.AreaCode,AR.AreaName FROM   SYS_Area  AS AR  WHERE 1=1   AND AR.AreaCode='110' ) A 
LEFT JOIN  SYS_Berth AS B ON B.AreaId=A.AreaId ) T
JOIN SYS_BerthStatus AS BS ON T.BerthCode=BS.BerthCode  
JOIN SYS_Canton AS CA ON T.CantonId=CA.CantonId  
JOIN SYS_Section AS SE ON T.SectionId=SE.SectionId )M

LEFT JOIN SYS_Sensor SS ON M.BerthCode=SS.BerthCode 
LEFT JOIN TRA_PricingBerth AS tp ON tp.BerthCode=M.BerthCode 
  
LEFT JOIN TRA_PricingStrategy  AS tps ON tps.PricingStrategyId=tp.PricingStrategyId 
LEFT  JOIN SYS_BerthAndType AS bat ON bat.BerthCode=M.BerthCode 
ORDER BY BerthCode ASC

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>