Jayyrus
Jayyrus

Reputation: 13051

Calculate max, average of some row sql

i've a table like:

enter image description here

i have to make sql query to get the average of v and order the average to have the #n best name in function of v in time. Users so have to select #n of best that want to have before do this query.

In order to have:

enter image description here

Can someone help me?

Upvotes: 0

Views: 781

Answers (3)

Baz1nga
Baz1nga

Reputation: 15579

select avg(average),name from tableName group by name order by avg(average) desc

Upvotes: 0

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

Use:

select name, sum(v) as average
from table
group by name
order by sum(v) desc

Upvotes: 0

cichy
cichy

Reputation: 10644

You don't need average, you need SUM

SELECT name, SUM(v) AS sum FROM table GROUP BY name ORDER BY SUM(v) DESC

Upvotes: 4

Related Questions