在Oracle 编译新视图时提示ora-00979
1、检查group by后面所有的字段是否都在select后面了?
2、Seclect后面的字段里,除了group by后面的字段以外,是否都做了聚合函数处理?
比如以下代码就是dpet_name字段未做聚合函数处理,编译时会报ora-000979的错误。
CREATE OR REPLACE VIEW C##database.TEST_LLW_SELLS_DTL_HOUR
(ITEM_ID,ITEM_NAME,DPET_ID,DPET_NAME,CHECKOUT_DT,HOUR24,QTY,AMOUNT)
AS
SELECT
A.ITEM_ID as ITEM_ID,
max(B.ITEM_NAME) as ITEM_NAME,
A.dpet_ID as dpet_ID,
C.DEPT_NAME as dpet_NAME,
to_char(A.CHECKOUT_DT,'yyyy-mm-dd') as CHECKOUT_DT,
to_char(A.CHECKOUT_DT,'hh24') as HOUR24,
sum(A.QTY) as QTY,
sum(A.SALE_REAL_AMT) as AMOUNT
FROM
TableA A
LEFT JOIN TableB B ON A.ITEM_ID = B.ITEM_ID
LEFT JOIN TableC C ON A.DPET_ID = C.DPET_ID
GROUP BY A.ITEM_ID, A.DPET_ID,to_char(A.CHECKOUT_DT,'yyyy-mm-dd') ,to_char(A.CHECKOUT_DT,'hh24')
/
给dpet_name字段加个max()