2 qq 31738715 qq_31738715 于 2017.09.13 11:12 提问

数据库sql优化问题帮忙看看指教下

select parking.*, sum(stub_group.fastStubCount)+sum(stub_group.slowStubCount) as stubCount
from parking
left join parking_stub_relation on parking.ParkingID=parking_stub_relation.parkingId
left join stub_group on (stub_group.id=parking_stub_relation.stubGroupId and parking_stub_relation.parkingStubStatus=1)
left join business_area on parking.BusinessAreaId = business_area.businessAreaId

where parking.parkingKind =1

group by parking.ParkingID
order by parking.aboveseaLevel desc

    把这条sql优化,请大神帮帮看看

2个回答

zml_moxueli
zml_moxueli   2017.09.13 14:48

看不到结构 只能猜测了
可以先把 fastStubCount 和 slowStubCount 都查出来
然后再主表查询

lkhog
lkhog   2017.09.13 18:02

不要使用* 影响效率

Csdn user default icon
上传中...
上传图片
插入图片