ORA-00979 not a group by expression

后端 未结 8 1747
梦谈多话
梦谈多话 2020-11-21 04:33

I am getting ORA-00979 with the following query:

SELECT cr.review_sk, cr.cs_sk, cr.full_name,
tolist(to_char(cf.fact_date, \'mm/dd/yyyy\')) \"appt\",
cs.cs_i         


        
8条回答
  •  离开以前
    2020-11-21 04:53

    Too bad Oracle has limitations like these. Sure, the result for a column not in the GROUP BY would be random, but sometimes you want that. Silly Oracle, you can do this in MySQL/MSSQL.

    BUT there is a work around for Oracle:

    While the following line does not work

    SELECT unique_id_col, COUNT(1) AS cnt FROM yourTable GROUP BY col_A;
    

    You can trick Oracle with some 0's like the following, to keep your column in scope, but not group by it (assuming these are numbers, otherwise use CONCAT)

    SELECT MAX(unique_id_col) AS unique_id_col, COUNT(1) AS cnt 
    FROM yourTable GROUP BY col_A, (unique_id_col*0 + col_A);
    

提交回复
热议问题