楼主: yingj7093
1686 1

sqlzoo上self join题目求高手协助 [推广有奖]

  • 0关注
  • 0粉丝

讲师

73%

还不是VIP/贵宾

-

威望
0
论坛币
306 个
通用积分
0
学术水平
0 点
热心指数
3 点
信用等级
0 点
经验
18279 点
帖子
364
精华
0
在线时间
99 小时
注册时间
2006-2-23
最后登录
2018-9-26

楼主
yingj7093 在职认证  发表于 2017-3-3 14:33:56 |AI写论文
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')

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

关键词:SQL

沙发
yingj7093 在职认证  发表于 2017-3-4 20:35:59
哪位大神帮忙看下啊

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-20 11:39