-3

在 oracle 中编译代码时出错,错误是 ORA-00979: not a GROUP BY expression,我想知道如何解决这个问题,因为如果我使用 GROUP BY 和 SUM 函数 ORDER 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
4

1 回答 1

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;
于 2013-11-14T01:37:28.800 回答