Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Oracle / Oracle Server / December 2005

Tip: Looking for answers? Try searching our database.

newby question finding average

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 29 Dec 2005 12:18 GMT
I would like to find the average temperature combining a  number of
locations where the record overlaps.

for a particular month I could use ...
sum(round(avg(decode(to_char(to_date,'mm'), '01',temp, null)), 1))
"Jan" from table where locatios in (a, b, c)

If I had the following data..

    location 1    location 2      location 3
Jan 1999    25.1        26        27       
Jan 2000    25.1        20
Jan 2001    25.3
Jan 2002    25.3

the above script would result in 24.8 because it averages all the
figures avalable

however I would like to average the temperature across all available
locations for each year first and then add the averaged figures

Jan 1999 = 26   
Jan 2000 = 22.5   
Jan 2001 = 25.3
Jan 2002 = 25.3

results in 24.8 and this the figure I mant.

Is there a way to decode by the year, find the average of each year
and then average the resulting figures.

I want only the one figure for each month as an average across all
years of record using many locations with varying overlaps.

This would seem to be a simple task but has me stumped!

Dave
Dave - 29 Dec 2005 12:50 GMT
Sorry better to use a diiferent set of data  :)

I would like to find the average temperature combining a  number of
locations where the record overlaps.

for a particular month I could use ...
sum(round(avg(decode(to_char(to_date,'mm'), '01',temp, null)), 1))
"Jan" from table where locatios in (a, b, c)

If I had the following data..

    location 1    location 2      location 3
Jan 1999    25.1        26        40       
Jan 2000    25.1        20
Jan 2001    25.3
Jan 2002    25.3

the above script would result in 26.7 because it averages all the
figures avalable

however I would like to average the temperature across all available
locations for each year first and then add the averaged figures

Jan 1999 = 30.4   
Jan 2000 = 22.5   
Jan 2001 = 25.3
Jan 2002 = 25.3

results in 25.9 and this the figure I mant.

Is there a way to decode by the year, find the average of each year
and then average the resulting figures.

I want only the one figure for each month as an average across all
years of record using many locations with varying overlaps.

This would seem to be a simple task but has me stumped!

I also wish to save the average figure as a new_value variable and use
elsewhere down in the script. I am fine with this part.

thanks Dave
Dave - 29 Dec 2005 13:04 GMT
Am using sqlplus

>Sorry better to use a diiferent set of data  :)
>
[quoted text clipped - 38 lines]
>
>thanks Dave
Michel Cadot - 29 Dec 2005 13:59 GMT
| Am using sqlplus
|
[quoted text clipped - 40 lines]
| >
| >thanks Dave

break on report
compute avg of temperature on report
select extract (year from the_date) year, avg(temperature) temperature
from mytable
where locatios in (a, b, c)
group by extract (year from the_date)
/

Regards
Michel Cadot
Dave - 29 Dec 2005 14:46 GMT
>| Am using sqlplus
>|
[quoted text clipped - 51 lines]
>Regards
>Michel Cadot

thanks Michel
once I have computed avg of temperature on report
how do I assign an alias to this value..
do I just add ..

col "Ave" new_value avger
compute avg of temperature on report "Ave"

and use &&aver as required

Dave
Michel Cadot - 29 Dec 2005 18:36 GMT
| >| Am using sqlplus
| >|
[quoted text clipped - 63 lines]
|
| Dave

You can't in this way but you can do something like:

select distinct extract (year from the_date) year,
   avg(temperature) over(partition by extract (year from the_date)) avgYear,
  avg(temperature) over() AvgGlobal
from mytable
where locatios in (a, b, c)
/

Regards
Michel Cadot
Dave - 30 Dec 2005 06:00 GMT
>| >| Am using sqlplus
>| >|
[quoted text clipped - 75 lines]
>Regards
>Michel Cadot

I'm not quite sure what you mean but will work on it for a while with
one of my more knowledgeable colleagues and I appeciate you're advice
Michel
Bye for now, Dave
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.