[英]SQL : averaging values on one column for unique entries of another column
Suppose I have a table with columns:假设我有一个包含列的表:
a CHAR, b Int, c Int
Column a only has entries of x/y/z, and the values in b and c go from 1 to 10. a 列只有 x/y/z 条目,b 和 c go 中的值从 1 到 10。
Then I do:然后我做:
select a, c
from mytable
where b > 5
What would I have to do from here to get a table of 3 rows (one for each letter), and the average c value for each of x, y and z?从这里我需要做什么才能得到一个 3 行的表(每个字母一个),以及 x、y 和 z 中每一个的平均 c 值?
Are you looking for group by
?您在寻找
group by
吗?
select a, avg(c)
from t
where b > 5
group by a;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.