Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
需要从表PRODUCTS和CUSTOMERS. 预期结果如下:
PRODUCTS
CUSTOMERS
CUST_NAME(来自)| PRODUCT_NAME | PRODUCT_DESC | 预计到达时间 | CUST_NAME(到)
和都来自同一个表 ( CUST_NAME(from)) 。如何查询我的 SQL 语句以从列中查询 2 个不同的值?CUST_NAME(to)CUSTOMERS
CUST_NAME(from)
CUST_NAME(to)
您需要CUSTOMER在表上连接两次,PRODUCTS因为有两列依赖于它,
CUSTOMER
SELECT b.Name as CustNameFrom, a.Product_Name, a.Product_Desc, a.ETA, c.Name as CustNameTo FROM Products a INNER JOIN Customer b ON a.cust_from = b.ID INNER JOIN Customer c ON a.cust_to = c.ID
要进一步了解有关联接的更多信息,请访问以下链接: