ORA-00979: not a GROUP BY expression- Please Guide

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

ORA-00979: not a GROUP BY expression- Please Guide

I am getting oracle prepare error: ORA-00979: not a GROUP BY expression.
Can you guide me how can I resolve this problem?

proc sql;

connect to oracle (user=EEEEEE password=RRRRRR path='werwrw' buffsize=1000000);

create table R1.TT as select * from connection to oracle

(Select  household_id

  ,business_unit

  ,Transaction_date

  ,Order_id

  ,sales_credit

  ,sum(decode(sales_Credit,1,amount,2,-amount)) as Amount

  ,sum(decode(sales_Credit,1,quantity,2, -quantity)) as Quantity

  ,Label2_Code

  ,nvl/*coalesce*/ (case transaction_type*sales_credit when 1 then profit_amount when 2 then -profit_amount end,0)as net_Profit_amount

from mbs.transaction  where business_unit in (1,3)

  and   sales_credit in (1,2)

group by household_id

  ,business_unit

  ,Transaction_date

  ,Order_id

  ,sales_credit);

disconnect from oracle ;

quit;

Thanks


Accepted Solutions
Solution
‎12-26-2013 01:01 PM
Super Contributor
Posts: 578

Re: ORA-00979: not a GROUP BY expression- Please Guide

proc sql;

connect to oracle (user=lookup password=lookup path='K6P_POLE' buffsize=1000000);

create table R1.TT as select * from connection to oracle

(Select  household_id

  ,business_unit

  ,Transaction_date

  ,Order_id

  ,sales_credit

  ,sum(decode(sales_Credit,1,amount,2,-amount)) as Amount

  ,sum(decode(sales_Credit,1,quantity,2, -quantity)) as Quantity

  ,Label2_Code

  ,nvl(case transaction_type*sales_credit when 1 then profit_amount when 2 then -profit_amount end,0)as net_Profit_amount

from mbs.transaction 

where sales_credit in (1,2)

and   business_unit in (1,3)and household_id>0

group by household_id

  ,business_unit

  ,Transaction_date

  ,Order_id

  ,sales_credit

  ,Label2_Code

  ,nvl(case transaction_type*sales_credit when 1 then profit_amount when 2 then -profit_amount end,0)

);

disconnect from oracle ;

quit;

View solution in original post


All Replies
Super Contributor
Posts: 578

Re: ORA-00979: not a GROUP BY expression- Please Guide

how do you want the label2_code and net profit amount to be included?  probably a sum around the net profit amount and include label2_code in the group by?

Contributor
Posts: 43

Re: ORA-00979: not a GROUP BY expression- Please Guide


Hi DBailey,

I am including both of them as field or variable in my table. (both are different variables)
label2_code

net profit amount

Thank you


hi Arthur


I included both of them in - group by

but it is still showing the same error.

Thank you


Super Contributor
Posts: 578

Re: ORA-00979: not a GROUP BY expression- Please Guide

Can you post the code?

Contributor
Posts: 43

Re: ORA-00979: not a GROUP BY expression- Please Guide

Yees sure

proc sql;

connect to oracle (user=EEEEEE password=RRRRRR path='werwrw' buffsize=1000000);

create table R1.TT as select * from connection to oracle

(Select  household_id

  ,business_unit

  ,Transaction_date

  ,Order_id

  ,sales_credit

  ,sum(decode(sales_Credit,1,amount,2,-amount)) as Amount

  ,sum(decode(sales_Credit,1,quantity,2, -quantity)) as Quantity

  ,Label2_Code

  ,nvl/*coalesce*/ (case transaction_type*sales_credit when 1 then profit_amount when 2 then -profit_amount end,0)as net_Profit_amount

from mbs.transaction 

where sales_credit in (1,2)

and   business_unit in (1,3)and household_id>0

group by household_id

  ,business_unit

  ,Transaction_date

  ,Order_id

  ,sales_credit

  ,Label2_Code

  ,net_profit_amount);

disconnect from oracle ;

quit;

PROC Star
Posts: 7,363

Re: ORA-00979: not a GROUP BY expression- Please Guide

I just noticed 2 things.  One: you should also add nvl to the group by statement.  Two, shouldn't there be a comma after nvl?

Solution
‎12-26-2013 01:01 PM
Super Contributor
Posts: 578

Re: ORA-00979: not a GROUP BY expression- Please Guide

proc sql;

connect to oracle (user=lookup password=lookup path='K6P_POLE' buffsize=1000000);

create table R1.TT as select * from connection to oracle

(Select  household_id

  ,business_unit

  ,Transaction_date

  ,Order_id

  ,sales_credit

  ,sum(decode(sales_Credit,1,amount,2,-amount)) as Amount

  ,sum(decode(sales_Credit,1,quantity,2, -quantity)) as Quantity

  ,Label2_Code

  ,nvl(case transaction_type*sales_credit when 1 then profit_amount when 2 then -profit_amount end,0)as net_Profit_amount

from mbs.transaction 

where sales_credit in (1,2)

and   business_unit in (1,3)and household_id>0

group by household_id

  ,business_unit

  ,Transaction_date

  ,Order_id

  ,sales_credit

  ,Label2_Code

  ,nvl(case transaction_type*sales_credit when 1 then profit_amount when 2 then -profit_amount end,0)

);

disconnect from oracle ;

quit;

Contributor
Posts: 43

Re: ORA-00979: not a GROUP BY expression- Please Guide

Thank you very much DBailey:-)

Thank you Arthur...

The Program is running now.

Merry Christmas...

Super Contributor
Posts: 578

Re: ORA-00979: not a GROUP BY expression- Please Guide

I don't think oracle gas the functionality to group by a calculated named expression...you need to include the nvl statement in the group by rather than the calculated column name net_profit_amount.  I haven't seen a comment in the middle of a function like you have in the NVL, so if this still doesn't work you might try removing that.

PROC Star
Posts: 7,363

Re: ORA-00979: not a GROUP BY expression- Please Guide

I'd think you have to include all of the non-aggregated fields in the group by statement (i.e., also include Label2_Code and net_Profit_amount).

New User
Posts: 1

Re: ORA-00979: not a GROUP BY expression- Please Guide

working in 10g but not in 12c



SELECT *
  FROM (  SELECT ABS (SUM (DECODE (CM, 5, D.MPRef.mass, 0.0))) "Calculated",
                 DECODE (GROUPING_ID (S1),
                         1, '*** Grand Total ***',
                         0, (SELECT title
                               FROM TEST_979_title T
                              WHERE TitleSubfile = '33' AND T.code = S1))
                    title,
                 S1
            FROM (WITH FindAssemblies
                       AS (SELECT  AssemblyModelCode "M",
                                  AssemblyPartnum "Assembly"
                             FROM TEST_979_effect E
                            WHERE     AssemblyModelCode = 'N'
                                  AND ('123' BETWEEN E.firstEffect
                                                       AND E.lastEffect))
                  SELECT MPRef, ConsideredMaturity CM, NVL (LOADCODE, '-') S1
                    FROM TEST_979_Detail
                   WHERE     AssemblyModelCode = 'N'
                         AND AssemblyPartNum IN (SELECT "Assembly"
                                                   FROM FindAssemblies)) D
        GROUP BY ROLLUP (S1));

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 6945 views
  • 11 likes
  • 4 in conversation