gpt4 book ai didi

mysql - 如何在单个查询中进行多个求和

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

假设我有这个表:

表 num1:

+----+-----+
| no | val |
+----+-----+
| 1 | 10 |
| 2 | 15 |
| 3 | 20 |
+----+-----+

表 num2:

+----+-----+
| no | tot |
+----+-----+
| 1 | 15 |
| 2 | 20 |
| 3 | 25 |
+----+-----+

所以,我想在单个查询中选择表 nu1.val 和表 num2.tot 的总和值

 Select sum(a.val),sum(b.tot) from num1 a, num2 b

查询不起作用请帮忙

最佳答案

在“无”列上连接这 2 个表,然后求和。

select sum(n1.val),sum(n2.tot) from num1 n1 join num2 n2 on n1.no=n2.no

关于mysql - 如何在单个查询中进行多个求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43181086/

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