实践一:
select
*
from
agent_info ai
inner join
(
select
acr.relation_id agentId,
acr.city_id,
dp.`name` provinceName,
dc.`name` cityName,
concat(dp.`name`,'/',dc.`name`) cityProvinceName
from
agent_city_relation acr
left join
dic_city dc
on
acr.city_id = dc.id
left join
dic_province dp
on
dc.province_id = dp.id
where
acr.city_id in
( 15)
and
acr.type = 1
) t1
on
ai.agent_id = t1.agentId
where
ai.agent_level =1
用时:
(1)超过三个表禁止join
如果需要超过三个表的,我们可以进行拆分,拆分的规则是如果查询的字段是再第三张表中那么我们就在这次SQL语句写,如果没有则在下一个SQL中写。