Подскажите как выбрать дату и кол-во в последней поставке
Пробовал так, ругается на S.ARTICLE
Код:
SELECT
S.ARTICLE,
(SELECT /*+ FIRST_ROWS */ * FROM (
SELECT
D.CREATEDAT
--D.ID
FROM SUPERMAG.SMDOCUMENTS D1, SUPERMAG.SMSPEC S1
WHERE
D1.ID = S1.DOCID
AND D1.DOCTYPE = S1.DOCTYPE
AND S1.ARTICLE = S.ARTICLE
AND D1.DOCTYPE = 'WI'
AND D1.CREATEDAT <= TO_DATE('10.09.13','DD.MM.YY')
AND D1.LOCATIONTO = 1
ORDER BY D1.CREATEDAT DESC
)
WHERE ROWNUM = 1
) AS LASPOST,
(SELECT /*+ FIRST_ROWS */ * FROM (
SELECT
S.QUANTITY
--D.ID
FROM SUPERMAG.SMDOCUMENTS D2, SUPERMAG.SMSPEC S2
WHERE
D2.ID = S2.DOCID
AND D2.DOCTYPE = S2.DOCTYPE
AND S2.ARTICLE = S.ARTICLE
AND D2.DOCTYPE = 'WI'
AND D2.CREATEDAT <= TO_DATE('10.09.13','DD.MM.YY')
AND D2.LOCATIONTO = 1
ORDER BY D2.CREATEDAT DESC
)
WHERE ROWNUM = 1) AS Q
FROM
SUPERMAG.SMDOCUMENTS D,
SUPERMAG.SMSPEC S
WHERE
D.ID = S.DOCID
AND D.DOCTYPE = S.DOCTYPE
AND D.ID = 'ЗП1486911'