Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    58

    Unanswered: Help with Update statement

    Hi Guys,

    This is my first thread here. I am trying to update a column with the sum of the column(Col1) but it should be grouped by on another column (Col2)

    Code:
    update Table set Col1 = (select sum(Col1)
    from Table
    where Col3=1
    group by Col1,Col2)
    where Col1=1
    This is the sample data am trying with
    Code:
    COl1 Col2 Col3
    0.4   2     1
    0.8    2     1
    5    3      1
    The output should be
    Code:
    1.2          2         1
    1.2          2          1
    5              3          1
    Thanks For your help in advance.
    Regards,
    Magesh

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Is this what you want?

    Code:
    update Table as t set Col1 = (select sum(Col1)
    from Table as x
    where x.Col3=1 and x.col2 = t.col2
    )
    Andy

  3. #3
    Join Date
    Jul 2009
    Posts
    58
    Yes Andy.. that worked like charm.. thanks again..

Posting Permissions

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