这个条件,如何写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.CityID
[解决办法]
harvesthouhao() ( ) 信誉:100 2007-07-19 14:49:50 得分: 0
我是这样写的,可以实现,但是表头是英文
select becityid =(select cityname from b where becityid=cityid),encityid=(select cityname as '到达地 ' from b where encityid=cityid),fltime as 出发日期 from a where becityid in (select cityid from b where cityname= '北京 ') and encityid in (select cityid from b where cityname= '上海 ')
---------------------------
select 出发地 =(select cityname from b where becityid=cityid),到达地=(select cityname from b where encityid=cityid),fltime as 出发日期 from a where becityid in (select cityid from b where cityname= '北京 ') and encityid in (select cityid from b where cityname= '上海 ')
這麼改寫。
另外,建議適用關聯的寫法。