gpt4 book ai didi

mysql - 将两个表相加的结果相加

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

我不知道标题是否好,但无论如何,我想知道我们是否可以在将重复项与另一个表相加后添加表的总和,如下例所示:

表A:

  Date          BL          Client  Design      Ref1    Ref2    Ref3    Qte
14/01/2013 13011401 A VT VT1 JAUNE XL 3
14/01/2013 13011402 B VT VT2 GRIS L 62
16/01/2013 13011601 D VT VT1 GRIS L 10
19/01/2013 13011903 F VT VT2 JAUNE L 15

表B:

  Date          BL          Client  Design      Ref1    Ref2    Ref3    Qte
14/01/2013 13011401 A VT VT1 JAUNE XL 3
14/01/2013 13011402 B VT VT2 GRIS L 100
16/01/2013 13011601 D VT VT1 GRIS L 10
19/01/2013 13011903 F VT VT2 JAUNE L 15

结果:

  Date          BL          Client  Design      Ref1    Ref2    Ref3    Qte
14/01/2013 13011401 A VT VT1 JAUNE XL 6
14/01/2013 13011402 B VT VT2 GRIS L 162
16/01/2013 13011601 D VT VT1 GRIS L 20
19/01/2013 13011903 F VT VT2 JAUNE L 30

条件是(Client、Design、Ref1、Ref2、Ref3)在两个表中必须相同!

最佳答案

您可以尝试使用JOINS

SELECT 
TableA.Date,
TableA.BL,
TableA.Client,
TableA.Design,
TableA.Ref1,
TableA.Ref2,
TableA.Ref3,
TableA.Qte + TableB.Qte As Qte
FROM
TableA
JOIN
TableB ON TableA.Client = TableB.Client
AND TableA.Design = TableB.Design
AND TableA.Ref1 = TableB.Ref1
AND TableA.Ref2 = TableB.Ref2
AND TableA.Ref3 = TableB.Ref3;

关于mysql - 将两个表相加的结果相加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22011977/

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