gpt4 book ai didi

MySql 当 table.column = table.column 时选择 table.column

转载 作者:行者123 更新时间:2023-11-29 03:29:05 26 4
gpt4 key购买 nike

假设我的数据库中有一张地铁 map ,其中每条线路的每个站点都是一行。如果我想知道我的线路在哪里互连:

mysql> SELECT LineA.stop_id FROM LineA, LineB WHERE LineA.stop_id = LineB.stop_id;
+---------+
| stop_id |
+---------+
| 1100 |
| 1300 |
+---------+

如何将此结果加入我的站点表以便检索站点名称?

这里是表格:

        stations
+----------------+---------+
| name | stop_id |
+----------------+---------+
| Nation | 1100 |
| Republic | 1300 |
| Main_st | 1065 |
| Airport | 1204 |
+----------------+---------+

LineA
+----------------+---------+
| id | stop_id |
+----------------+---------+
| 1 | 1100 |
| 2 | 1300 |
| 3 | 1204 |
+----------------+---------+

LineB
+----------------+---------+
| id | stop_id |
+----------------+---------+
| 1 | 1100 |
| 2 | 1300 |
| 3 | 1265 |
+----------------+---------+

最佳答案

你离答案很近了:试试这个

select B.* from (SELECT LineA.stop_id FROM LineA, LineB WHERE LineA.stop_id = LineB.stop_id) as A
INNER JOIN stations as B on A.stop_id=B.stop_id

关于MySql 当 table.column = table.column 时选择 table.column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32708574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com