简体   繁体   English

如何在sql中为每个column_name选择avg(value)

[英]How to select avg(value) per column_name in sql

I have a table named studios with the columns "earnings" and "country". 我有一个名为studios的表,其中包含“收入”和“国家/地区”列。 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
SELECT country,AVG(earnings) FROM studios GROUP BY country;

You can do that: "SELECT AVG(earnings) FROM studios GROUP BY country" If you have column country_id is for prefer. 你可以这样做: "SELECT AVG(earnings) FROM studios GROUP BY country"如果你有列country_id是为了更喜欢。

You can use and this query "SELECT AVG(earnings),country FROM studios GROUP BY country" 你可以使用和这个查询"SELECT AVG(earnings),country FROM studios GROUP BY country"

你可以用这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM