gpt4 book ai didi

php - 如何引用其他表列customer_id获取产品价格列的总和

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

我想要SUM特定客户的产品价格,其 id和我保存在cart中的购物车产品 table 。价格在 products table 。

表结构如下:

CART TABLE cart_id, customer_id, product_id, product_qty PRODUCTS TABLE product_id, product_cat, product_title, product_desc, product_price, product_img

我怎样才能做到这一点?我正在使用以下 mysqliphp代码,但它返回 NUll :

"SELECT SUM(`product_price`) as total FROM products
INNER JOIN cart ON products.product_price = cart.customer_id
WHERE customer_id = '$c_id'";

$result = mysqli_query($conn, $sql);

最佳答案

您的意思难道不是:

"SELECT SUM(`product_price`) as total
FROM cart
INNER JOIN product ON product.id = cart.product_id
WHERE cart.customer_id = '$c_id'";

很难说,因为我们不知道您的数据库结构,但像您那样连接表似乎没有意义

更新:了解数据库结构后更改查询

关于php - 如何引用其他表列customer_id获取产品价格列的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41279010/

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