所以说我有三列。我需要编写一些SQL来获取总数。
第一列来自表A,数量列来自表B。
这是第一个问题的继续,所以说我有这张桌子。我将详细介绍每个领域 Second Query question table
如何为该查询编写SQl ????
答案 0 :(得分:1)
使用窗口功能:
select t.*, sum(quantity) over (partition by item) as total_quantity
from t;
答案 1 :(得分:0)
select a.Item, (Select sum(Quantity) from TableB as c where a.Item= c.Item) as TotalQty,
b.Quantity
from tableA as a
inner join TableB as b on a.Item= b.Item
这将适用于ypu </ p>
答案 2 :(得分:0)
您需要JOIN
:
select a.item, b.quantity, sum(b.quantity) over (partition by a.item) as total_qty
from table a inner join
table b
on b.item = a.item;