- 04-04-2009 09:11 AM #1
ORA-00979: not a GROUP BY expression
Please let me know what is the problem in following code,
Code :SELECT rc.CUSTOMER_ID, rc.CUSTOMER_NAME, rc.STATUS, rcta.TRX_DATE, rcta.TRX_NUMBER, rctta.NAME, sum(rctla.EXTENDED_AMOUNT) DR FROM RA_CUSTOMERS rc, RA_CUSTOMER_TRX_ALL rcta, RA_CUST_TRX_TYPES_ALL rctta, RA_CUSTOMER_TRX_LINES_ALL rctla WHERE rc.CUSTOMER_NAME = 'ABC' AND rc.CUSTOMER_ID = rcta.BILL_TO_CUSTOMER_ID AND rcta.COMPLETE_FLAG = 'Y' AND rctta.CUST_TRX_TYPE_ID = rcta.CUST_TRX_TYPE_ID AND rctla.CUSTOMER_TRX_ID = rcta.CUSTOMER_TRX_ID group by rcta.TRX_NUMBER
- Club-Oracle Complementary E-Books and Magazines
Get your free Complementary Copy of Oracle Magazine
You can also browse the Free Magazines and E-Books section to see the complete list of free magazines, e-books and Whitepapers.
- 04-04-2009 10:39 AM #2
Re: ORA-00979: not a GROUP BY expersion
hi Riaz, you have to use all the columns you are using in your select statement within your group by clause
Try this
Code sql:SELECT rc.customer_id, rc.customer_name, rc.STATUS, rcta.trx_date, rcta.trx_number, rctta.NAME, SUM (rctla.extended_amount) dr FROM ra_customers rc, ra_customer_trx_all rcta, ra_cust_trx_types_all rctta, ra_customer_trx_lines_all rctla WHERE rc.customer_name = 'ABC' AND rc.customer_id = rcta.bill_to_customer_id AND rcta.complete_flag = 'Y' AND rctta.cust_trx_type_id = rcta.cust_trx_type_id AND rctla.customer_trx_id = rcta.customer_trx_id GROUP BY rc.customer_id, rc.customer_name, rc.STATUS, rcta.trx_date, rcta.trx_number, rctta.NAME
- 04-05-2009 07:52 AM #3
Re: ORA-00979: not a GROUP BY expression
It works, thanks. Well i could not understand the logic behind this, would you please explain why we need to add all the select cols into group by clause?
In my understanding we should only write the col in group by clause that is required for grouping. Is not it ? This logic works well with a single table.
- 04-05-2009 08:11 AM #4
Re: ORA-00979: not a GROUP BY expression
you are using the aggregate function SUM. When you use a group by clause it divides your resultant rows into sets and then the aggregate function is used on all the sets. So when you selecting multiple columns in your select statement, the grouping also has to be based on all those columns.
- 04-05-2009 09:35 AM #5
- 04-07-2009 08:41 AM #6
Re: ORA-00979: not a GROUP BY expression
Another way of doing it without Group by but with Partition by
This is Analytic function .
Code sql:SQL> SELECT DEPTNO,JOB, SUM(SAL) 2 FROM EMP 3 GROUP BY DEPTNO,JOB; DEPTNO JOB SUM(SAL) ---------- --------- ---------- 20 CLERK 1900 30 SALESMAN 5600 20 MANAGER 2975 30 CLERK 950 10 PRESIDENT 5000 30 MANAGER 2850 10 CLERK 1300 10 MANAGER 2450 20 ANALYST 6000 9 rows selected. SQL> SELECT DISTINCT DEPTNO,JOB , 2 SUM(SAL) OVER (PARTITION BY DEPTNO,JOB ) 3 FROM EMP ; DEPTNO JOB SUM(SAL)OVER(PARTITIONBYDEPTNO,JOB) ---------- --------- ----------------------------------- 10 CLERK 1300 30 SALESMAN 5600 20 MANAGER 2975 30 MANAGER 2850 10 PRESIDENT 5000 20 CLERK 1900 20 ANALYST 6000 30 CLERK 950 10 MANAGER 2450 9 rows selected. SQL>

Raj.
Similar Threads
-
ORA-00979: not a GROUP BY expression
By Patience in forum SQL PL/SQLReplies: 2Last Post: 12-04-2009, 05:00 PM -
Problem of GROUP BY
By RIAZ in forum SQL PL/SQLReplies: 3Last Post: 06-18-2009, 04:31 AM -
Oracle SQL CASE Expression
By ygsunilkumar in forum SQL PL/SQLReplies: 4Last Post: 05-12-2009, 06:16 AM -
SQL Expression
By ygsunilkumar in forum SQL PL/SQLReplies: 1Last Post: 05-05-2009, 04:15 AM



