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 > How do you aggregate on a group?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-14-04, 15:11
axwack axwack is offline
Registered User
 
Join Date: Jun 2003
Posts: 9
How do you aggregate on a group?

This is a silly question but I need help on this.

I have a table of 50 rows. Each one has customer transaction data.

I want to create a stored procedure where if I send a customer name parameter, I want to select all the the transactions for that customer and sum the amount of transactions in groupings of 5.

So for example,

Customer1 05/15/2004 $10,000
Customer1 05/15/2004 $10,000
Customer1 05/15/2004 $10,000
Customer1 05/15/2004 $10,000
Customer1 05/15/2004 $10,000

Customer1 05/15/2004 $10,000
Customer1 05/15/2004 $10,000

So the logic is the first set of 5 have a sum > $30000 INSERT into exception
The second, although the same customer, is ok.

How do you get a grouping as such in SQL?

Thanks for the help.
Reply With Quote
  #2 (permalink)  
Old 05-14-04, 21:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
please don't crosspost

http://www.dbforums.com/t997919.html
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-17-04, 07:27
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

Crossposts must be deleted by moderator!!!

Thanks,
Grofaty
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