Petrogad
Petrogad

Reputation: 4423

MySQL Range and Average

I'm wondering if in MySQL you are able to find a range within values along with the average in a query. Assume the table below please:

-----------------------------------------
|     ID         |         VALUE        |
-----------------------------------------
|     1          |          30          |
-----------------------------------------
|     2          |          50          |
-----------------------------------------
|     3          |          10          |
-----------------------------------------

Range Low would be 10, range High would be 50, average would be 30.

Is there query that would allow me to grab these values without pulling them down into php and then sorting the array, and finding the average that way?

Cheers

Upvotes: 1

Views: 1144

Answers (2)

Virat Kadaru
Virat Kadaru

Reputation: 2256

Is this what you want?

select min(value) as low, max(value) as high, avg(value) from table_name

Upvotes: 2

Matt Bridges
Matt Bridges

Reputation: 49425

SELECT Avg(Value), Max(Value), Min(Value) FROM tableName

See also MySQL Aggregate Functions

Upvotes: 4

Related Questions