简体   繁体   English

SQL:为另一列的唯一条目平均一列的值

[英]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.

相关问题 通过另一列SQL中的唯一条目对列进行分组 - Group column by unique entries in another column SQL 选择列的唯一条目,然后按另一条目的唯一条目过滤 - Select unique entries of column and filter these by unique entries of another one SQL 按一列选择唯一值,按另一列选择最新值 - SQL Select unique values by one column with the latest value by another column 在 SQL 中,在另一列中查找具有唯一值的列中的重复项 - In SQL, find duplicates in one column with unique values for another column SQL Group由一列组成,在另一列中计数条目 - SQL Group by one column, count entries in another SQL查询可根据另一列中的值返回一列中的唯一行 - SQL query that returns one unique row in one column based on values in another column SQL 将一列的值按另一列分组 - SQL group values for one column by another column SQL-从一列返回所有唯一的值对,在另一列中返回每个值 - SQL - Return all unique pairs of values from one column, for each value in another column 在一个列中选择唯一值,并在另一列中符合条件 - select unique values in one column and match with the criteria in another column 如何基于另一列SQL中的唯一值创建数组列 - How to create array column based on unique values in another column SQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM