gpt4 book ai didi

mysql - 如何在不添加整列的情况下选择不同列的总和

转载 作者:行者123 更新时间:2023-11-30 22:41:02 25 4
gpt4 key购买 nike

a.id  c_id  p_type  paid     date
1 6 FLOUR 100.00 2015-06-22
2 7 OIL 50.00 2015-06-21
3 6 FLOUR 242.00 2015-06-24
4 6 FLOUR 392.00 2015-06-26
5 7 OIL 200.00 2015-07-29
6 7 OIL 300.00 2015-07-25

我一直在尝试只从不同的表中选择值的总和,我试过了

SELECT customer.first_name, customer.last_name, credit.quantity, 
credit.date_supplied, credit.unit_price, credit.p_type,
ROUND(SUM(account.amount_paid))
AS amount_paid, account.date_paid FROM credit, customer
LEFT OUTER JOIN account
ON account.c_id = customer.c_id ;

我想显示产品类型为面粉的列的总和,然后是油的列的总和,但我只得到表中的总和。我将不胜感激。

最佳答案

您可以按类型使用分组,然后对组使用求和。

关于mysql - 如何在不添加整列的情况下选择不同列的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31150712/

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