如何减少这些MySQL查询以获得最短的运行时间或减少这些查询以获得快速执行速度
SELECT relationships.bl_id
FROM relationships
LEFT JOIN business_data
ON relationships.bl_id = business_data.bl_id
LEFT JOIN business_listing
ON business_listing.id = relationships.bl_id
WHERE relationships.rel_id='10' or relationships.rel_id='367'
OR relationships.rel_id='368' or relationships.rel_id='369'
OR relationships.rel_id='370' or relationships.rel_id='371'
OR relationships.rel_id='372' or relationships.rel_id='373'
OR relationships.rel_id='374' or relationships.rel_id='375'
OR relationships.rel_id='376' or relationships.rel_id='378'
or relationships.rel_id='380' or relationships.rel_id='381'
or relationships.rel_id='384' or relationships.rel_id='385'
or relationships.rel_id='387' or relationships.rel_id='389'
or relationships.rel_id='391' or relationships.rel_id='393'
or relationships.rel_id='394' or relationships.rel_id='400'
or relationships.rel_id='402' or relationships.rel_id='404'
or relationships.rel_id='405' or relationships.rel_id='408'
or relationships.rel_id='410' or relationships.rel_id='411'
or relationships.rel_id='419' or relationships.rel_id='422'
or relationships.rel_id='424' or relationships.rel_id='426'
or relationships.rel_id='428' or relationships.rel_id='430'
or relationships.rel_id='432' or relationships.rel_id='435'
or relationships.rel_id='437' or relationships.rel_id='439'
or relationships.rel_id='441' or relationships.rel_id='442'
or relationships.rel_id='444' or relationships.rel_id='445'
or relationships.rel_id='447' or relationships.rel_id='451'
or relationships.rel_id='454' or relationships.rel_id='456'
or relationships.rel_id='458' or relationships.rel_id='459'
or relationships.rel_id='462' or relationships.rel_id='463'
or relationships.rel_id='464' or relationships.rel_id='465'
or relationships.rel_id='466' or relationships.rel_id='467'
or relationships.rel_id='468' or relationships.rel_id='469'
or relationships.rel_id='470' or relationships.rel_id='471'
or relationships.rel_id='472' or relationships.rel_id='473'
or relationships.rel_id='474' or relationships.rel_id='475'
or relationships.rel_id='476' or relationships.rel_id='477'
or relationships.rel_id='478' or relationships.rel_id='479'
or relationships.rel_id='480' or relationships.rel_id='481'
or relationships.rel_id='482' or relationships.rel_id='483'
or relationships.rel_id='484' or relationships.rel_id='485'
or relationships.rel_id='486' or relationships.rel_id='487'
or relationships.rel_id='488' or relationships.rel_id='489'
or relationships.rel_id='490' or relationships.rel_id='491'
or relationships.rel_id='492' or relationships.rel_id='493'
or relationships.rel_id='494' or relationships.rel_id='495'
or relationships.rel_id='496' or relationships.rel_id='497'
or relationships.rel_id='498' or relationships.rel_id='500'
or relationships.rel_id='501' or relationships.rel_id='502'
or relationships.rel_id='503' or relationships.rel_id='504'
or relationships.rel_id='505' or relationships.rel_id='506'
or relationships.rel_id='507' or relationships.rel_id='508'
or relationships.rel_id='509' or relationships.rel_id='510'
or relationships.rel_id='511' or relationships.rel_id='512'
or relationships.rel_id='513' or relationships.rel_id='514'
or relationships.rel_id='515' or relationships.rel_id='641'
or relationships.rel_id='642' or relationships.rel_id='643'
or relationships.rel_id='688' or relationships.rel_id='689'
or relationships.rel_id='690' or relationships.rel_id='691'
or relationships.rel_id='692' or relationships.rel_id='693'
or relationships.rel_id='694' or relationships.rel_id='695'
or relationships.rel_id='717' or relationships.rel_id='720'
or relationships.rel_id='721' or relationships.rel_id='837'
or relationships.rel_id='882' or relationships.rel_id='883'
or relationships.rel_id='900' or relationships.rel_id='901'
AND business_data.city = '12' and relationships.bl_id=business_data.bl_id
AND business_listing.status = 'publish'
order by business_data.listning_type desc limit 0 , 20
答案 0 :(得分:0)
使用此:
$ids=array(367,368,369,....);
select relationships.bl_id from relationships left join business_data on relationships.bl_id=business_data.bl_id left join business_listing on business_listing.id=relationships.bl_id where relationships.rel_id in ($ids) AND business_data.city = '12' and relationships.bl_id=business_data.bl_id AND business_listing.status = 'publish' order by business_data.listning_type desc limit 0 , 20