Garayed.com  

Go Back   Garayed.com > Oracle
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-06-2007, 01:51 AM
Geoff Muldoon
 
Posts: n/a
Default AVG across columns

Hi all,

Oracle 10.2 on linux ...

Is there any inbuilt way of calculating the average for values in separate
columns of a table across a row (cf. the average of values in rows for a
column) which allows for null values?

Given this data in table x:
row_id v1 v2 v3 v4
A 5 10 null 9
B null 5 5 null
C 6 8 7 7


I'd like a query result that looks like:
row_id row_avg
A 8 -- (5+10+9)/3
B 5 -- (5+5)/2
C 7 -- (6+8+7+7)/4

The simple math of (sum(v1 + v2 + v3 + v4) / 4) won't work due to null
addition, and nvl to sidestep this gives an incorrect denominator count.

Solution needs to be SQL not PL/SQL.

Yes, I know the data is poorly normalized.

GM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:10 AM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.