If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2: GROUP BY problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-07-04, 06:53
ghorita ghorita is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
DB2: GROUP BY problem

Hello,

I'm trying to execute the following query with a SQL0122N error:

SELECT A.INVOICE_NUMBER, A.QTY_SHIPPED, C.SERIAL_NUMBER, A.QTY_SHIPPED*A.UNIT_PRICE AS TOTAL_REVENUE FROM BIDS.DAC_SHIP_LINE A, BIDS.DAC_SHIP_COMPONENT B, BIDS.DAC_SHIP_SERIAL C WHERE A.INVOICE_NUMBER = B.INVOICE_NUMBER AND A.LINE_NUMBER = B.LINE_NUMBER AND A.INVOICE_NUMBER = C.INVOICE_NUMBER AND A.LINE_NUMBER = C.LINE_NUMBER AND B.COMPONENT_NUMBER = C.COMPONENT_NUMBER AND A.QTY_SHIPPED ¬= B.QUANTITY_SHIPPED AND CONFIGURATION_FLAG = 'C' AND COMPONENT_IND = 'Y' GROUP BY A.INVOICE_NUMBER

SQL0122N A SELECT statement with no GROUP BY clause contains a column name and a column function in the SELECT clause, or a column name is contained in the SELECT clause but not in the GROUP BY clause. SQLSTATE=42803


THANKS!!
Reply With Quote
  #2 (permalink)  
Old 09-07-04, 07:16
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
$db2 "? SQL0122N "

SQL0122N A SELECT statement with no GROUP BY clause contains a
column name and a column function in the SELECT clause,
or a column name is contained in the SELECT clause but
not in the GROUP BY clause.

Explanation: The SELECT statement has one of the following
errors:

o A column name and a column function are contained in the
SELECT clause but there is no GROUP BY clause.

o A column name is contained in the SELECT clause but not in
the GROUP BY clause.



The column may be contained in a scalar function.

If the NODENUMBER or PARTITION functions are specified in the
SELECT clause, then all partitioning key columns of the
underlying table are considered to be in the SELECT clause.

The statement cannot be processed.

User Response: Correct the statement by including the columns in
the GROUP BY clause that are in the SELECT clause or by removing
the columns from the SELECT clause.

sqlcode: -122

sqlstate: 42803
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 09-07-04, 07:25
ghorita ghorita is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
db2 ? SQL0122N

Yes, that help page (as most DB2 help pages) is useless... if you look at my query, I have indeed included a column in the GROUP BY clause that is also in the SELECT clause.
Reply With Quote
  #4 (permalink)  
Old 09-07-04, 10:03
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
I don't see a group function that would require you to have a group by clause. Have you tried the query without the GROUP BY clause?
Reply With Quote
  #5 (permalink)  
Old 09-07-04, 10:59
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
...and 'grouping' purely to make distinct with 'A.QTY_SHIPPED*A.UNIT_PRICE' in the select ain't gonna get you what you want!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On