Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    220

    Unanswered: Need help with Update query

    I have a table that looks like this:

    Code:
    UNIT     GROUP     LOC     FACTOR
    A100     GLOBAL   TOR    .17
    A100     GLOBAL   ROC    .17
    I am trying to update the FACTOR column so that I add all TOR values to the ROC values as such. Basically, if the LOC = TOR, add that FACTOR value to the ROC FACTOR value
    Code:
    UNIT     GROUP     LOC     FACTOR
    A100     GLOBAL   TOR    .17
    A100     GLOBAL   ROC    .34
    Can anyone lend me a hand here?

  2. #2
    Join Date
    Jun 2007
    Posts
    2
    Not sure exactly what you are trying to do, but try something like this:

    update myTable mT1
    set factor = (select newFactor
    from (select unit
    , group
    , t.factor+r.factor newfactor
    from myTable t
    , myTable r
    where t.group=r.group
    and t.unit=r.unit) mT2
    where mT1.group=mT2.group
    and mT1.unit=mT2.unit)
    where loc='ROC
    and EXISTS (select 1
    from (select unit
    , group
    , t.factor+r.factor newfactor
    from myTable t
    , myTable r
    where t.group=r.group
    and t.unit=r.unit) mT2
    where mT1.group=mT2.group
    and mT1.unit=mT2.unit);

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Tudz Drkl,
    please Read & FOLLOW the posting guidelines as enumerated in the #1 STICKY post at the top of this forum; especially the part about using code tags.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

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