Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003
    Posts
    9

    Unanswered: 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.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    please don't crosspost

    http://www.dbforums.com/t997919.html
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,

    Crossposts must be deleted by moderator!!!

    Thanks,
    Grofaty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •