Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何对查询的3个表求和?_Mysql - Fatal编程技术网

Mysql 如何对查询的3个表求和?

Mysql 如何对查询的3个表求和?,mysql,Mysql,如果C表是custid1和prodid1,我想得到表A上的txnVolume之和?谢谢你们的帮助!干杯 尝试以下操作: A table -------------------- id bId txnVolume 1 1(b table) 10.00 2 1 5.00 3 2 7.00 4 3 2.00 B table -------------------- id cId 1 1(C table) 2 2 3 3

如果C表是custid1和prodid1,我想得到表A上的txnVolume之和?谢谢你们的帮助!干杯

尝试以下操作:

A table
--------------------
id bId        txnVolume
1  1(b table) 10.00
2  1          5.00
3  2          7.00
4  3          2.00

B table
--------------------
id cId
1  1(C table)
2  2
3  3

C table
--------------------
id cusId prodId
1  1     1
2  1     2
3  1     1
4  1     2
Select sum(coalesce(txnVolume,0))
FROM A INNER JOIN B on A.BID = B.Bid
INNER JOIN C on C.ID = B.CID
WHERE C.CustID = 1 and C.ProdID = 1
请尝试以下操作:

Select sum(coalesce(txnVolume,0))
FROM A INNER JOIN B on A.BID = B.Bid
INNER JOIN C on C.ID = B.CID
WHERE C.CustID = 1 and C.ProdID = 1

在sql中,您需要联接表。当表被连接时,它们会创建一个大表。然后可以将where子句添加到列中

select sum(txnVolume) from A
   join B on A.bID = B.id
   join C on C.cID = C.id
  where prodID = 1 and custID = 1

在sql中,您需要联接表。当表被连接时,它们会创建一个大表。然后可以将where子句添加到列中

select sum(txnVolume) from A
   join B on A.bID = B.id
   join C on C.cID = C.id
  where prodID = 1 and custID = 1

我可以很容易地为您编写此查询,但请告诉我们您的尝试。在mysql查询中如何将表“链接”在一起?请考虑:我可以很容易地为您编写此查询,但请告诉我们您的尝试。在mysql查询中如何将表“链接”在一起?请考虑:
SELECT  SUM(a.txnVolume) totals
FROM    tableA a
        INNER JOIN tablB b
            ON a.bid = b.id
        INNER JOIN tableC c
            ON b.cid = c.ID
WHERE   c.custID = 1 AND c.prodID = 1