这个条件,如何写SQL语句???
有两个表,如下
A表 B表
字段 ID BeCityId EnCityId BUSINF 字段 ID CityID CityNAME
1 01 02 xxx 1 01 北京
2 03 02 xxx 2 02 上海
3 01 02 xxx 3 03 成都
如果才可以输出下面信息
出发地点(Becity) 达到地点(Encity) 车子信息(Businf)
北京 上海 xxx
北京 上海 xxx
------解决方案--------------------select 出发地点(Becity) = (select CityNAME from B where CityID = BeCityId), 达到地点(Encity) = (select CityNAME from B where CityID = EnCityId), 车子信息(Businf)=BUSINF from A
------解决方案--------------------用關聯效率更優
Select
B.CityNAME As 出发地点,
C.CityNAME As 达到地点,
A.BUSINF As 车子信息
From
A
Left Join
B
On A.BeCityId = B.CityID
Left Join
B C
On A.EnCityId = C.CityID
------解决方案--------------------select b.cityname as 出发地点(Becity),c.cityname as 达到地点(Encity),a.车子信息(Businf) from a join b on a.BeCityId=b.CityID join b as c on a.EnCityId=c.C