56,687
社区成员
发帖
与我相关
我的任务
分享
mysql> select * from station_info;
+------------+--------------+
| station_id | station_name |
+------------+--------------+
| 1 | S1 |
| 10 | S10 |
| 11 | S11 |
| 12 | S12 |
| 2 | S2 |
| 3 | S3 |
| 4 | S4 |
| 5 | S5 |
| 6 | S6 |
| 7 | S7 |
| 8 | S8 |
| 9 | S9 |
+------------+--------------+
12 rows in set (0.00 sec)
mysql> select * from route_info;
+----------+------------+-----------------+---------------+
| route_id | route_name | start_stationId | end_stationId |
+----------+------------+-----------------+---------------+
| 10 | 10 | 1 | 7 |
| 11 | 11 | 2 | 8 |
| 12 | 12 | 8 | 10 |
| 13 | 13 | 11 | 8 |
| 14 | 14 | 1 | 9 |
+----------+------------+-----------------+---------------+
5 rows in set (0.00 sec)
mysql> select * from route_station;
+----+----------+------------+----------+----------+
| id | route_id | station_id | position | upordown |
+----+----------+------------+----------+----------+
| 1 | 10 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 | 1 |
| 3 | 10 | 3 | 3 | 1 |
| 4 | 10 | 4 | 4 | 1 |
| 5 | 10 | 5 | 5 | 1 |
| 6 | 10 | 7 | 6 | 1 |
| 7 | 11 | 2 | 1 | 1 |
| 8 | 11 | 6 | 2 | 1 |
| 9 | 11 | 7 | 3 | 1 |
| 10 | 11 | 8 | 4 | 1 |
| 11 | 12 | 8 | 1 | 1 |
| 12 | 12 | 9 | 2 | 1 |
| 13 | 12 | 10 | 3 | 1 |
| 14 | 13 | 11 | 1 | 1 |
| 15 | 13 | 2 | 2 | 1 |
| 16 | 13 | 8 | 3 | 1 |
| 17 | 14 | 1 | 1 | 1 |
| 18 | 14 | 12 | 2 | 1 |
| 19 | 14 | 6 | 3 | 1 |
| 20 | 14 | 9 | 4 | 1 |
+----+----------+------------+----------+----------+
20 rows in set (0.00 sec)
mysql> select r1.route_name,
-> group_concat(s.station_name SEPARATOR '/') as station_id,
-> r2.route_name
-> from route_station rs1,
-> route_station rs2,
-> route_station a,
-> route_station b,
-> route_info r1,
-> route_info r2,
-> station_info s
-> where rs1.station_id=(select station_id from station_info where station_name='S1' )
-> and rs2.station_id=(select station_id from station_info where station_name='S8' )
-> and a.station_id=b.station_id
-> and a.route_id=rs1.route_id
-> and b.route_id=rs2.route_id
-> and rs1.route_id=r1.route_id
-> and rs2.route_id=r2.route_id
-> and a.station_id=s.station_id
-> group by r1.route_name,
-> r2.route_name;
+------------+------------+------------+
| route_name | station_id | route_name |
+------------+------------+------------+
| 10 | S7/S2 | 11 |
| 10 | S2 | 13 |
| 14 | S6 | 11 |
| 14 | S9 | 12 |
+------------+------------+------------+
4 rows in set (0.00 sec)
mysql>