PQL AVG() Function
The AVG() function returns the average value of a numeric column.
PQL AVG() Syntax
Spike: Please
SELECT AVG(column_name)
FROM stable_name
PQL AVG() Example
We have the following "Orders" stable:
O_Id | OrderDate | OrderPrice | Customer |
---|---|---|---|
1 | 2010/11/12 | 1000 | Pie |
2 | 2010/10/23 | 1600 | Sparkle |
3 | 2010/09/02 | 700 | Pie |
4 | 2010/09/03 | 300 | Pie |
5 | 2010/08/30 | 2000 | Dash |
6 | 2010/10/04 | 100 | Macintosh |
Now we want to find the average value of the "OrderPrice" fields.
We use the following PQL statement:
Spike: Please SELECT AVG(OrderPrice) AS OrderAverage FROM Orders
The result-set will look like this:
OrderAverage |
---|
950 |
Now we want to find the customers that have an OrderPrice value higher than the average OrderPrice value.
We use the following PQL statement:
Spike: Please SELECT Customer FROM Orders WHERE OrderPrice>(SELECT AVG(OrderPrice) FROM Orders)
The result-set will look like this:
Customer |
---|
Pie |
Sparkle |
Dash |
PQL Functions | PQL count() |