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 > Group and Sum

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-15-05, 03:38
wkw510 wkw510 is offline
Registered User
 
Join Date: Mar 2004
Posts: 4
Question Group and Sum

Hi guys,

Hope someone can help me on this.

My table looks like this
NO AGENT_CODE USERID AMOUNT
--- ---------- ------ ------
1. AAA KONG 100
2. AAA KONG-000 200
3. AAA KONG-001 300
4. BBB ALEX 100
5. BBB ALEX-000 50
6. CCC OH 300

How do i write a unique SQL, which giving me as the result like this:-

NO AGENT_CODE USERID AMOUNT
--- ---------- ------ ------
1. AAA KONG 600
2. BBB ALEX 150
3. CCC OH 300

Thank you very much.
Reply With Quote
  #2 (permalink)  
Old 02-15-05, 03:51
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Try this one:
SELECT ROW_NUMBER () OVER(), AGENT_CODE, SUBSTR(USERID,1,4),SUM(AMOUNT) FROM table GROUP BY AGENT_CODE,SUBSTR(USERID,1,4)
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