簡體   English   中英

從三列中選擇不重復的值,最多四分之一,其中有重復項

[英]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的聚合函數。 其他可能有用的聚合函數包括MINAVERAGECOUNT

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM