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