全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1688 1
2017-03-03
悬赏 20 个论坛币 未解决
表结构.png stops.png
route.png
该题目是sqlzoo上self join最后一题。该数据集有2张表,表1、stops是公交站点名字,通过stops.id和route.stop关联。
表2、route:num代表公交车号码,company代表运营公司,pos代表公交车经停站点序号,stop是公交站点号码。

需求如下:
Find the routes involving two buses that can go from Craiglockhart to Sighthill.
Show the bus no. and company for the first bus, the name of the stop for the transfer,
and the bus no. and company for the second bus。
需求结果如下:
微信截图_20170303142930.png
我自己的sql代码如下:
select distinct a.num,a.company,d.num,d.company
from route a left join route b on (a.company=b.company and a.num=b.num)
join route c on (b.stop=c.stop)
join route d on (c.company=d.company and c.num=d.num)
join stops stopa on (a.stop=stopa.id and stopa.name='Craiglockhart')
join stops stopb on (d.stop=stopb.id and stopb.name='Sighthill')

但我显示不出来中间换乘站点名字,求高手指教!感谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2017-3-4 20:35:59
哪位大神帮忙看下啊
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群