Для конкретного артикула самый низкий план дает
Код:
select s.article,
coalesce(max(g.quantity), 0) -
coalesce(sum(nvl2(d.locationto,s.quantity,-s.quantity)),0) as goodstodate,
sum(CASE WHEN d.doctype = 'CS' then s.quantity else CASE WHEN d.doctype = 'CR' then s.quantity * (-1) else 0 end end) keep (dense_rank first order by d.createdat) as prodagi
from smdocuments d, smspec s
left outer join smgoods g on (s.article = g.article and g.storeloc = 7)
where d.id = s.docid and d.doctype = s.doctype
and d.doctype in ('CR', 'CS', 'WI', 'WO', 'IW')
and s.article = '0017590' and d.docstate = 3
and (d.locationto || d.locationfrom = 7 )
and d.createdat between to_date('25.01.2012', 'DD.MM.YYYY') and trunc(current_date)
group by s.article
Еще вопрос возник, впервые в теме
https://olegon.ru/showthread.php?t=2...???+?????????? столкнулся с конструкцией
Код:
d.locationto||d.locationfrom=2
Это следует понимать как Оракловый синтаксис для
Код:
d.locationto=2 or d.locationfrom=2