Hi,
Below is a query that works just fine: -
I want to use the same query but only return X rows, by using an additional WHERE clause i.e. ROWNUM = X
The problem is I have no idea how to achieve it.
Any help or advice would be greatly appreciated.
Regards
Below is a query that works just fine: -
Code:
SELECT gr_code, ar_code, ar_description, sum_value, sum_qty,
sum_margin / sum_qty, gr_description
FROM
(SELECT GR.CODE AS gr_code, AR.CODE AS ar_code, AR.DESCRIPTION AS ar_description,
SUM(TA.PRICE + NVL(TA.DISCOUNT,0) + NVL(TA.SERVICE,0)) AS SUM_VALUE,
SUM(DECODE(AR.MEAS_UNIT,1,TA.QTY_WEIGHT,1)) AS SUM_QTY,
NVL(SUM(((TA.PRICE + NVL(TA.DISCOUNT,0) + NVL(TA.SERVICE,0)) - AR.REFERENCE_PRICE) /
(TA.PRICE + NVL(TA.DISCOUNT,0) + NVL(TA.SERVICE,0))) * 100,0) AS SUM_MARGIN,
GR.DESCRIPTION AS gr_description
FROM
TB_TRANSACTIONS TR, TB_TRANS_ARTICLES TA, TB_ARTICLES AR, TB_GROUPS GR,
TB_CASHREGS CA, TB_SHOPS SH, TB_PRICELEVELS PL
WHERE TR.BOOKKEEPING_DATE
BETWEEN TO_DATE('13.12.2002', 'dd.mm.yyyy')
AND TO_DATE('13.12.2002', 'dd.mm.yyyy')
AND TA.TRANSACTION_ID = TR.ID
AND AR.ID = TA.ARTICLE_ID
AND AR.TYPE IN (0)
AND TR.DELETE_OPERATOR_ID IS NULL
AND CA.ID = TR.CASHREG_ID
AND SH.ID = CA.SHOP_ID
AND TR.PRICELEVEL_ID = PL.ID
AND GR.ID (+) = AR.GROUP_A_ID
GROUP BY GR.CODE, AR.CODE, AR.DESCRIPTION, GR.DESCRIPTION)
ORDER BY gr_code, sum_margin / sum_qty DESC
I want to use the same query but only return X rows, by using an additional WHERE clause i.e. ROWNUM = X
The problem is I have no idea how to achieve it.
Any help or advice would be greatly appreciated.
Regards