Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    8

    Unanswered: Adding averages in different tables

    Hi,

    I have 3 tables A, B, C which have columns
    latitude
    longitude
    temperature.

    I want to subtract the average temperature ( taken from all these tables) at a particular latitude longitude range from the average termperature at a different latitude longitude range.

    Can someone help me with the query please.

    Thanks,
    SD

  2. #2
    Join Date
    Jul 2002
    Posts
    29

    Re: Adding averages in different tables

    Originally posted by sd_100
    Hi,

    I have 3 tables A, B, C which have columns
    latitude
    longitude
    temperature.

    I want to subtract the average temperature ( taken from all these tables) at a particular latitude longitude range from the average termperature at a different latitude longitude range.

    Can someone help me with the query please.

    Thanks,
    SD
    Try

    SELECT AVG(temprature)
    FROM
    ( SELECT a.latitude, a.longitude, a.temperature FROM a
    WHERE a.latitide = <something>
    AND a.longitude = <something>
    UNION ALL ( SELECT b.latitude, b.longitude, b.temperature FROM b
    WHERE b.latitide = <something>
    AND b.longitude = <something> )
    UNION ALL ( SELECT c.latitude, c.longitude, c.temperature FROM c
    WHERE c.latitide = <something>
    AND c.longitude = <something>)
    )

    -- rajXesh
    All you need in this life is ignorance and confidence, and then success is sure.
    -- Mark Twain (1835 - 1910)

  3. #3
    Join Date
    Jul 2003
    Location
    US
    Posts
    314

    Exclamation What exactly are the requirements

    Hi
    I would be able to help you out on this, but only if you could explain it in a more subtle manner, like what you have in the tables, do you need to join all the tables, and if possible could u give a few lines of input and few lines of output desired.
    Regards
    Aruneesh

  4. #4
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    4
    I will add to what rajXesh developed:

    SELECT AVG(temprature)
    FROM
    ( SELECT a.latitude, a.longitude, a.temperature
    FROM a
    WHERE a.latitide = latitide1
    AND a.longitude = longitude1
    UNION ALL
    SELECT b.latitude, b.longitude, b.temperature
    FROM b
    WHERE b.latitide = latitide1
    AND b.longitude = longitude1
    UNION ALL
    SELECT c.latitude, c.longitude, c.temperature
    FROM c
    WHERE c.latitide = latitide1
    AND c.longitude = longitude1
    )
    MINUS
    SELECT AVG(temprature)
    FROM
    ( SELECT a.latitude, a.longitude, a.temperature
    FROM a
    WHERE a.latitide = latitide2
    AND a.longitude = longitude2
    UNION ALL
    SELECT b.latitude, b.longitude, b.temperature
    FROM b
    WHERE b.latitide = latitide2
    AND b.longitude = longitude2
    UNION ALL
    SELECT c.latitude, c.longitude, c.temperature
    FROM c
    WHERE c.latitide = latitide2
    AND c.longitude = longitude2
    )

    Good luck !!

Posting Permissions

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