select article, SHORTNAME, Itemprice, Itempricenotax, DOCID, createdat from (select sp.article, crd.SHORTNAME, Itemprice, Itempricenotax, DOCID, createdat,
row_number() over ( order by s.createdat desc) rn
from supermag.smcard crd, supermag.smspec sp, supermag.smdocuments s
where sp.article = '&article'
and sp.article = crd.article
and sp.doctype in ('WI')
and s.createdat <= trunc(sysdate+1)
and s.id = sp.docid
group by sp.article, crd.SHORTNAME, Itemprice, Itempricenotax, DOCID, createdat
having DOCID like 'ПН%' or docid like 'АП%'
order by 6 desc)
where rn =1
select article, SHORTNAME, Itemprice, Itempricenotax, DOCID, createdat from (select sp.article, crd.SHORTNAME, round(Itemprice), round(Itempricenotax), DOCID, createdat, row_number() over ( order by s.createdat desc) rn from supermag.smcard crd, supermag.smspec sp, supermag.smdocuments s where sp.article = '&article' and sp.article = crd.article and sp.doctype in ('WI') and s.id = sp.docid group by sp.article, crd.SHORTNAME, Itemprice, Itempricenotax, DOCID, createdat having DOCID like 'ПН%') where rn =1
having DOCID like 'ПН%'
select article, SHORTNAME, round(Itemprice), round(Itempricenotax), DOCID, createdat, rn from (select sp.article, crd.SHORTNAME, Itemprice, Itempricenotax, DOCID, createdat, row_number() over ( order by createdat desc) rn from supermag.smcard crd, supermag.smspec sp, supermag.smdocuments s where sp.article = '&article' and sp.article = crd.article and sp.doctype in ('WI') and s.doctype = sp.doctype and s.id = sp.docid and opcode = 0 ) where rn =1
(partition by createdat order by createdat desc)
select article, SHORTNAME, round(Itemprice), round(Itempricenotax), DOCID, createdat, rn from (select sp.article, crd.SHORTNAME, Itemprice, Itempricenotax, DOCID, createdat, row_number() over ( partition by sp.article order by s.createdat desc) rn from supermag.smcard crd, supermag.smspec sp, supermag.smdocuments s -- where sp.article = '&article' --and sp.article = crd.article where s.doctype = sp.doctype and crd.idclass in (select idclass from sacardclass where tree = '1.26.1.1') and sp.doctype in ('WI') and s.id = sp.docid and opcode = 0 ) where rn =1