Solved

Is there a weighted average function in Oracle

Posted on 2004-04-23
2
4,718 Views
Last Modified: 2012-05-04
Is there a function that calculated a weighted average? I was browsing my Oracle Docs and I can't seem to find that type of function?
0
Comment
Question by:Marek_Zyskowski
2 Comments
 

Expert Comment

by:tarar1
ID: 10901582
Yes you are you are true...i think there is no such thing ...you will have to do that yourself

If you can tell us the requirments then may be we can help you
0
 
LVL 8

Accepted Solution

by:
baonguyen1 earned 125 total points
ID: 10901661
This is not mine but I found it from Oracle web site. Not sure if it can help you:
------------------------------
Away to calculate weighted averages is as follows:

Create a calculated item using the following formula:

Weighted avg = sum(Weighting Factor * Weighting item) / sum(Weighting Factor)
e.g.
Average Price = sum(Quantity * Price) / sum(Quantity)

Use this calculated item in your report instead of the original item.
When a row shows the lowest level of data the calculation equals to the original value, but the subtotals and the totals show the weighted values all across your report.

Please be aware of the fact that when you calculate weighted averages
your dataset may contain zero or null values for the values to weight.
In some cases you may want to eliminate these figures.

The formula might look as follows then:
Average Price =
sum( Decode( nvl(price),0,0, quantity * price ))
/
sum( Decode( nvl(price),0,0, quantity ))
----------------------
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help on model clause 5 47
create a nested synonym 4 40
add more rows to hierarchy 3 34
subtr returning incorrect value 8 65
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question