我找不到我想做的相关标题和描述。因此,我希望您可以从示例中了解。
结果应如下所示:
SumQuantity Productid LotQty Lot
512 40652 256.000000 2020-12-20
512 40652 256.000000 2020-12-21
即SumQuantity = sum(LotQty)。 我应该如何更改我的选择(如下)以创建那种效果?
select s.productid,sum(s.cuquantity) LotQty,la.Value Lot
from log l
left join logstock s on s.logid=l.id
left join Logstockattributes la on la.LogStockID=s.id and la.AttributeID=10
where l.receiptid=5950195
group by productid,la.value
结果是:
Productid LotQty Lot
40652 256.000000 2020-12-20
40652 256.000000 2020-12-21
样品表
Logid Productid Cuquantity Lot
1 40652 256.000000 2020-12-20
2 40652 255.000000 2020-12-21
3 40652 1.000000 2020-12-21
答案 0 :(得分:0)
您似乎想要一个窗口功能:
select s.productid, sum(s.cuquantity) as LotQty, la.Value as Lot,
sum(sum(s.cuquantity)) over () as totalLogQty
from log l left join
logstock s
on s.logid = l.id left join
Logstockattributes la
on la.LogStockID = s.id and la.AttributeID = 10
where l.receiptid = 5950195
group by productid,la.value