gpt4 book ai didi

mysql - 具有多个表的复杂sql查询

转载 作者:行者123 更新时间:2023-11-29 04:51:42 27 4
gpt4 key购买 nike

我有 3 个表:

客户

ID_CUSTOMER
NAME

产品

ID_PRODUCT
PRODUCTNAME
PRICE

订单

ID_ORDER
CUSTOMER_ID
PRODUCT_ID
QUANTITY

如何选择所有订购金额超过 1 万美元的客户?

最佳答案

尝试类似的东西:

SELECT C.ID_CUSTOMER, C.Name, 
SUM(P.PRICE * O.QUANTITY) AS Total FROM Customers C
JOIN Orders O ON C.CUSTOMER_ID = O.CUSTOMER_ID
JOIN Procucts P ON P.PRODUCT_ID = O.PRODUCT_ID
GROUP BY C.ID_CUSTOMER, C.Name
HAVING SUM(P.PRICE * O.QUANTITY) >= 10000

关于mysql - 具有多个表的复杂sql查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11096042/

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