什么是真正的sql语句显示类似产品列表

时间:2016-06-22 23:37:19

标签: mysql mariadb

如何在图片中显示客户“Peacock cafe bar”购买的产品(descriptionserial numberprice

我显示3个表格 tables xampp

我试过

select 
from ...
where(
    select
    from ...
    as ...
    where 
    “”
)

2 个答案:

答案 0 :(得分:1)

尝试这样的事情:你想要在他们的键上加入你的表,然后像这样过滤WHERE子句中的结果。

SELECT
   p.pr_serial
 , p.pr_descr
 , p.pr_price
FROM   Customers AS c
JOIN Buys AS b
    ON c.cust_code = b.cust_code
JOIN Products AS p
    ON b.pr_code = p.pr_code
WHERE  c.cust_name = 'Peacock cafe bar';

答案 1 :(得分:0)

我记得你应该在你的桌子上使用联合查询,例如:

select * from ProductsTable as Products
join  
(select Buys.ProCode from CustomerTable as Customer
join BuysTable as Buys
on Customer.code = Buys.custcode) as customerbuys
on Products.code = customerbuys.ProCode