ORA-00979:不是GROUP BY

时间:2013-11-13 21:54:31

标签: oracle oracle11g

在oracle中编译代码时出错, 错误是ORA-00979:不是GROUP BY表达式, 我想知道如何解决这个问题,因为 函数ORDER BY,而不是我使用GROUP BY和 SUM不服务我。

SELECT
            INVOICE.CUS_CODE,

            CUSTOMER.CUS_BALANCE,

            SUM(LINE.LINE_UNITS * LINE.LINE_PRICE )AS "TOTAL PURCHASES"

FROM
            INVOICE, CUSTOMER, LINE

WHERE
            CUSTOMER.CUS_CODE = INVOICE.CUS_CODE  AND INVOICE.INV_NUMBER= LINE.INV_NUMBER

GROUP BY
            INVOICE.CUS_CODE

1 个答案:

答案 0 :(得分:1)

根据WW的建议,您需要将CUS_BALANCE添加到group by子句中。

试试这个,

SELECT invoice.cus_code,
       customer.cus_balance,
       sum(line.line_units * line.line_price )AS "TOTAL PURCHASES"
FROM   invoice, customer, line
WHERE  customer.cus_code = invoice.cus_code  
AND    invoice.inv_number= line.inv_number
GROUP BY invoice.cus_code, customer.cus_balance;