我有两个表,并对它们执行了内部联接:下面是我的查询
SELECT a.ship_id AS ship_id,
sum(a.qty) as total_qty
from table_a as a
inner join table_b on a.shp_id = b.shpid
group by a.shp_id
Sample data:
table_a
-----------------------------
product_name | qty | ship_id
-----------------------------
item_1 | 10 | 1
item_2 | 20 | 1
item_3 | 10 | 2
item_4 | 10 | 2
table_b
-------------------
ship_id | desc
-------------------
1 | desc_1
2 | desc_2
以上查询的输出如下:
--------------------
ship_id | total_qty
--------------------
1 | 60
2 | 40
预期产量:
--------------------
ship_id | total_qty
--------------------
1 | 30
2 | 20
谁能帮我弄到这个吗。
1条答案
按热度按时间jaql4c8m1#
试试下面的方法-