[英]Selecting the distinct values from three columns with the max of a fourth where there are duplicates
我有一个带有一个数值(n)和三个字符串值(a,b,c)的表。 如何查询此表,以便仅获得(a,b,c)的不同值,如果存在重复项,则取相应的一组n值的最大值?
select max(n), a, b, c
from mytable
group by a, b, c
使用GROUP BY
:
select a, b, c, max(n)
from table
group by a, b, c;
这将仅显示a, b, c
唯一或不同集合a, b, c
并显示在该集合中找到的最大n
。
MAX
是设计用于GROUP BY
的聚合函数。 其他可能有用的聚合函数包括MIN
, AVERAGE
和COUNT
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.