Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Posts
    62

    Unanswered: FInd duplicates of part of a record, sum and combine!!

    Hi everyone,
    I have a query as below:

    Row1 Row2 Row3 Row 4 Row 5
    1, 2, 2 , 0 , 15
    1 , 2 , 2 , 1 , 7
    0 , 1 , 1 , 4 , 2
    1 , 2 , 2 , 0 , 29


    I need to pull our records which have the same entries in Rows 1-4 and then add up Row 5. For example The above query would make three more queries i.e
    One
    1,2,2,0, 44

    Two
    1,2,2,1, 7

    Three
    0,1,1,4, 2

    I would then wish to recombine them into one table
    Final
    1,2,2,0, 44
    1,2,2,1 , 7
    0,1,1,4, 2.

    Is this possible and how would I go about doing this!?
    Been scratching my head for awhile now!
    thanks eveyrone!
    Sue

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select Row1, Row2, Row3, Row4, sum(Row5) as sum_row5
      into new_table
      from old_Table
    group 
        by Row1, Row2, Row3, Row4
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2004
    Posts
    62
    Hi,
    thank you very much! I thought it would take me ages!
    that's great!

Posting Permissions

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