Urgent query help please
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Urgent query help please

  1. #1
    Join Date
    Jan 2001
    Posts
    318
    I have a data in a table:
    Called temp

    PK Ent_id Amt1 Amt2
    1 500 10 30
    2 500 20 30
    3 510 200 200


    I want to write a query which will sumup amt1 for ent_id and put that in amt2.
    1. When there is only one row (ent_id), in which case amt2 should be same as amt1.
    2. When there are more than one row(with same ent_id) it should sum that amount and put it in amt2 as shown above.


    I am able to write 2 queries for these 2 diffenent cases
    but I want to do it in one query.

    Can someone help please ??

    Thanks a lot.

    Sonali

  2. #2
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    Well, it would seem that you would want to store the total in the table where only Ent_ID is the key, but I'll give it to ya anyway :)

    UPDATE
    --Temp T1
    SET
    --T1.Amt2 =
    ----(
    ----SELECT
    ------SUM(T2.Amt2)
    ----FROM
    ------Temp T2
    ----WHERE
    ------T2.Ent_id = T1.Ent_id
    ----)

    HTH,

    - Chris

Posting Permissions

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


Click Here to Expand Forum to Full Width