gpt4 book ai didi

mysql - 将一个表中的总和添加到第二个表

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

我有两张 table

Child_id (this is temporary table)
--------
1001
----------
1002
----------
1003
----------
1004
----------
1006

-

Child_id         Amount       (this table name is user_details)
-------------------
1001 100
--------------------
1002 250
--------------------
1003 100
--------------------
1004 150
--------------------
1008 400

现在我想将第二个表中两个 child_id 相同的总金额添加到第一个表中。例如,此表的输出为 600(添加数量 1001,1002,1003,1004)。

请你帮我做这个。

最佳答案

你可以这样做:

SELECT SUM(u.amount)
FROM tempTable t
INNER JOIN user_details u ON t.child_id = u.child_id

这将导致两个表中具有 child_id 的记录的金额总和

关于mysql - 将一个表中的总和添加到第二个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20423112/

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