Select
C.ID,
C.Code,
C.Name,
sum(O.Quantity) Quantity,
sum(O.DeliveredQuantity) DeliveredQuantity,
min(O.UnitRate) UnitRate,
(Select
min(A.QUnit)
From
ReceivedOrders2 A
Where
A.Parent_ID = :OBJID and
A.RowType = 3 and
A.Store_ID = O.Store_ID and
A.StoreCard_ID = C.ID and
A.UnitRate =
(
Select
min(URO.UnitRate)
From
ReceivedOrders2 URO
Where
URO.Parent_ID = :OBJID and
URO.RowType = 3 and
URO.Store_ID = O.Store_ID and
URO.StoreCard_ID = C.ID
)
) QUnit,
O.Store_ID,
S.Code StoreCode
From
ReceivedOrders2 O
join StoreCards C on O.StoreCard_ID = C.ID
join Stores S on O.Store_ID = S.ID
Where
O.Parent_ID = :OBJID and
O.Rowtype = 3 and
S.IsLogistic = 'A'
Group by
S.Code,
O.Store_ID,
C.ID,
C.Code,
C.NameGenerated by ABRA Software a.s. 27.10.2021 16:34:11