ErrorMessage: ORA-00979: not a GROUP BY expression

Record time oracle error: ErrorMessage: ORA-00979: not a GROUP BY expression

difference between oracle and other databases

Reason: select list item is not present in the column can appear in the group by a list of items, but not vice versa, the column select list item appears to be present in all of the group by the back (except aggregate function )

Solution: column appears in the select must all appear in the back of the group by

 
 SELECT SUM(C.total_in) as total_in, C.VEN_NO as VEN_NO, C.VENDOR_NAM as VENDOR_NAM, SUM(C.total_out) as total_out from (
(
 SELECT count(*) AS total_in,A.VEN_NO, A.VENDOR_NAM, 0 total_out FROM 
 (SELECT DISTINCT EMP_NAM, VEN_NO,VENDOR_NAM,CHECK_TYP  FROM LIEMS99.VIEW_ENTRY WHERE TO_CHAR(CHECK_TIM,'yyyy-mm-dd') = '2019-04-24'  AND CHECK_TYP='I') A
 GROUP BY A.VEN_NO,A.VENDOR_NAM
)
 union all
(
 SELECT 0 total_in,B.VEN_NO, B.VENDOR_NAM, count(*) AS total_out FROM 
 (SELECT DISTINCT EMP_NAM, VEN_NO,VENDOR_NAM,CHECK_TYP  FROM LIEMS99.VIEW_ENTRY WHERE TO_CHAR(CHECK_TIM,'yyyy-mm-dd') = '2019-04-24'   AND CHECK_TYP='O') B
 GROUP BY B.VEN_NO,B.VENDOR_NAM
)
) C  group by C.VEN_NO,C.VENDOR_NAM ORDER BY total_in desc

 

Guess you like

Origin www.cnblogs.com/zhou-pan/p/10932573.html