如何 select 查询订单中的产品列表 table sql

how to select query for product list in orders table sql

我的 tables:

orders:
id | date | customerid

orderDetail:
orderId | Quantity | productId

和客户、产品 table。

输出:

orderDetail中存在产品列表;

Example output:
productname | customername | orderid | Quantity
p1          |  c3          |  4      | 5000
p2          |  c2          |  1      | 1010
p3          |  c5          |  12     | 200

什么是查询?

不知道您的客户和产品表,但假设它们遵循与其他表类似的命名约定

SELECT p.productname, c.customername, od.orderid, od.quantity
FROM orders o
INNER JOIN customers c ON o.customerid = c.id
INNER JOIN orderdetail od ON o.id = od.orderid
INNER JOIN products p ON odproductid = p.id

在将占位符放入 < >

时不知道您的列名
SELECT
 p.productname,
 c.customername,
 od.orderid,
 od.quantity
FROM
 orderdetail od
 INNER JOIN order o ON od.orderid = o.id
 INNER JOIN customer c ON c.<customer_id_here> = o.customerid
 INNER JOIN product p ON od.productid = p.<product_id_here>