关于sql语句查询 外键 多表 急!!!!!!!!!!!!!!1

2025-01-05 05:55:58
推荐回答(3个)
回答1:

路线表Trace {ID,TraceName,StartCityCode,EndCityCode}
城市表City{CityCode,CityName}
select TraceName,
(select CityName from City where CityCode=StartCityCode) as StartCityName,
(select CityName from City where CityCode=EndCityCode) as EndCityName
from Trace
where ID='指定路线'

回答2:

select r.roadName,c.fromName,d.toName from road r
left join city c on c.id = r.fromid
left join city d on d.id = r.toid

回答3:

select cityname from city where cityid= (select go_id from path where pathid=“XX”)