icsd12015
icsd12015

Reputation: 33

How to select avg(value) per column_name in sql

I have a table named studios with the columns "earnings" and "country". Each item of that table describes a studio in a country and its earnings.
How can I select the average earnings of the studios for each country?

SELECT AVG(earnings) --I want per country
FROM studios

Upvotes: 0

Views: 142

Answers (3)

Andy Powell
Andy Powell

Reputation: 77

You can use this:

SELECT AVG(earnings) , country from studios group by country

Upvotes: 0

Kristiyan
Kristiyan

Reputation: 1663

You can do that: "SELECT AVG(earnings) FROM studios GROUP BY country" If you have column country_id is for prefer.

You can use and this query "SELECT AVG(earnings),country FROM studios GROUP BY country"

Upvotes: 1

Jakub Fedyczak
Jakub Fedyczak

Reputation: 2364

SELECT country,AVG(earnings) FROM studios GROUP BY country;

Upvotes: 1

Related Questions