select A.*,price,
decode(A.PackSize,-1,nvl(G.SaleQ,0),null)as operRealiz
,decode(A.PackSize,-1,A.Quantity-nvl(G.SaleQ,0),null) OperQuantity
,decode(A.PackSize,-1,A.FreeQuantity-nvl(G.SaleQ,0),null) OperFree
from (select pr.price, crd.name,
L.ID StoreLoc,L.Name StoreLocTitle, g.Article,-1 PackSize
,nvl(G.Quantity,0) Quantity
,nvl(G.ReservedQuantity,0) ReservedQuantity
,nvl(G.IncomingQuantity,0) IncomingQuantity
,nvl(G.AwaitedQuantity,0) AwaitedQuantity
,nvl(G.FoundQuantity,0) FoundQuantity
,nvl(G.Quantity+G.FoundQuantity-(G.ReservedQuantity+G.IncomingQuantity),0) FreeQuantity
from Supermag.SMGoods G, Supermag.SVGrantedLocs L, Supermag.SMcard crd, SuperMag.SMPrices pr
where L.ID=G.StoreLoc(+)
and g.storeloc = 6 and pr.storeloc = 6 and g.article = pr.article
and g.article = crd.article
and G.Article in ( пихаем запрос откуда берем карточки )) A, (select G.LocID,sum(G.SaleQuantity-G.ReturnQuantity) SaleQ
from Supermag.SMOperGoods G
Where G.Article in ( пихаем запрос откуда берем карточки )
group by G.LocID) G
where A.StoreLoc=G.LocID(+)
order by A.StoreLocTitle,A.PackSize