Я и имел ввиду по дате, видимо не упомянул.
Ладно, всем спасибо, что-то получилось. Может быть это и не самый оптимальный запрос, но выдает нужный результат и работает быстро.
Код:
SELECT carticle AS "Артикул",
c.name AS "Наименование",
d.id AS "Накладная",
d.createdat AS "От",
d.clientindex AS "Поставщик",
ci.name AS "Наименование поставщика",
round(dc.itemprice,2) AS "Цена",
sspeed AS "Скорость продаж по сети"
FROM
supermag.smdocuments d,
supermag.smspec dc,
supermag.smcard c,
supermag.smclientinfo ci,
(select distinct
c.article AS carticle,
MAX(TO_DATE(d.createdat,'YY-MM-DD')||d.id) conc
FROM supermag.smspec dc,
supermag.smdocuments d,
supermag.sacardclass cc,
supermag.smcard c
WHERE d.docstate > 0
AND d.doctype = 'WI'
AND dc.doctype = 'WI'
AND d.id = dc.docid
AND c.article = dc.article
AND c.idclass = cc.id
AND cc.tree LIKE :smrGroup
AND TO_DATE (d.createdat) BETWEEN :smrdatestart
AND :smrdateend
GROUP BY c.article
),
(SELECT ss.article AS sarticle,
SUM(ss.salerate) AS sspeed
FROM supermag.smstocklevels ss
GROUP BY ss.article)
WHERE d.id = substr(conc,9,32)
AND d.doctype = 'WI'
AND dc.doctype = 'WI'
AND dc.docid = d.id
AND dc.article = carticle
AND c.article = carticle
AND ci.id = d.clientindex
AND sarticle = carticle