ErrorMessage: ORA-00979: 不是 GROUP BY 表達式

記錄一次oracle報錯:ErrorMessage: ORA-00979: 不是 GROUP BY 表達式數據庫

oracle與其餘數據庫差異oracle

緣由:select 列表項中不存在的列能夠出如今group by的列表項中,但反過來就不行了,在select列表項中出現的列必須所有出如今group by後面(聚合函數除外)函數

解決:在select中出現的列必須所有出如今group by的後面spa

 
 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
相關文章
相關標籤/搜索