如何在Oracle中找到小于1000的总和

时间:2015-08-27 06:18:29

标签: sql oracle sum

我试图通过以下查询找到小于1000的销售总额,我也提到了错误消息。
非常感谢帮助。

SELECT 
    DELI_DT,
    BILL_NO,br_cd,
    Prod,
    ROUND(SUM(SALE),2)<1000 SALE
FROM (
    SELECT 
        DELI_DT,
        b.BILL_NO,
        b.br_cd,
        b.CAT_CD||b.PRD_CD Prod,
        nvl(SUM(b.sale_net),0)-nvl(sum(RT_QTY*FLAT_RT),0) SALE
    from BILL_DET b, BILL_MAS a
    here a.BILL_NO = b.BILL_NO
    AND a.SC_CD = b.SC_CD
    and b.TYP_CD='09'
    and  a.SALE_CD NOT IN ('RS','IN','EX')
    AND DELI_DT BETWEEN '01-JUL-15' and '02-JUL-15'
    GROUP BY Deli_DT,b.BILL_NO,b.br_cd,b.CAT_CD||b.PRD_CD
)
group by DELI_DT,BILL_NO,br_cd,Prod,SALE
ORDER BY 1

错误讯息:

  

第1行的错误:ORA-00923:找不到FROM关键字

1 个答案:

答案 0 :(得分:0)

试;

SELECT 
    DELI_DT,
    BILL_NO,br_cd,
    Prod,
    ROUND(SUM(SALE),2)<1000 SALE
FROM (
    SELECT 
        DELI_DT,
        b.BILL_NO,
        b.br_cd,
        b.CAT_CD||b.PRD_CD Prod,
        nvl(SUM(b.sale_net),0)-nvl(sum(RT_QTY*FLAT_RT),0) SALE
    from BILL_DET b
    join BILL_MAS a 
        on a.BILL_NO = b.BILL_NO
        AND a.SC_CD = b.SC_CD
    where b.TYP_CD='09'
    and  a.SALE_CD NOT IN ('RS','IN','EX')
    AND DELI_DT BETWEEN '01-JUL-15' and '02-JUL-15'
    GROUP BY Deli_DT,b.BILL_NO,b.br_cd,b.CAT_CD||b.PRD_CD
)
group by DELI_DT,BILL_NO,br_cd,Prod,SALE
ORDER BY 1