gpt4 book ai didi

MySQL:根据多个条件从多个列中选择数据

转载 作者:行者123 更新时间:2023-11-29 08:07:29 24 4
gpt4 key购买 nike

我有以下表格:

Sender
---------
ID, name, type, mobile


Receiver
-----------
ID, name, type, mobile


Ports
-----------
ID, name, city, country


Shipment
-----------
ID, Sender_ID, Receiver_ID, From_Port_ID, To_Port_ID, Date, Status

我试图在网页中使用名称而不是 ID 显示发货表内容。我可以通过以下查询获取发送者和接收者名称:

SELECT sender.name AS Sender, receiver.name AS Receiver, shipment.id 
FROM sender,receiver,shipment
WHERE shipment.sender_ID=sender.ID AND shipment.receiver_ID=receiver.ID

如何从端口表中获取端口名称?

最佳答案

尝试:

SELECT sender.name as Sender, receiver.name as Receiver, shipment.id, ports.name AS Port 
FROM sender,receiver,shipment,ports
WHERE shipment.sender_ID=sender.ID AND shipment.receiver_ID=receiver.ID AND ports.ID = shipment.From_Port_ID

关于MySQL:根据多个条件从多个列中选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22412771/

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