我有两张table,t1,t2。我的表格和预期结果如下。我的表架构在SQLFIDLE中
t1级:
id branch_name
1 branch1
2 branch2
3 branch3
4 branch4
5 branch5
t2段:
id VBRNCH VTOBRN vqty
1 1 0 10
2 2 0 20
3 3 0 30
4 0 4 40
5 0 5 50
预期结果是:
branch_name send received
1 10 0
2 20 0
3 30 0
4 0 40
5 0 50
我试过的是:
SELECT
b1.branch_name,
i1.vqty AS send,
i2.vqty AS received
FROM t2 i1
INNER
JOIN t1 b1
ON b1.id = i1.VBRNCH
INNER JOIN t2 i2
ON b1.id = i2.VTOBRN
GROUP
BY i1.VTOBRN,
i2.VBRNCH;
但我现在没有排了。
2条答案
按热度按时间k10s72fa1#
例如
http://sqlfiddle.com/#!9/af0973/21号
kgqe7b3p2#
我想这就是你要找的问题:
此处演示