I have a table with one numeric value (n) and three string values (a,b,c). How do I query this table so that I get only distinct values of (a,b,c) and if there are duplicates, take the maximum of the corresponding set of n values?
From stackoverflow
-
select max(n), a, b, c from mytable group by a, b, cJon Ericson : Arg! Beat me to it. ;-) -
Use
GROUP BY:select a, b, c, max(n) from table group by a, b, c;This will show only unique or distinct sets of
a, b, cand show the maximumnfound in that set.MAXis an aggregate function designed for use withGROUP BY. Other potentially useful aggregate functions includeMIN,AVERAGE, andCOUNT.Chris Lively : +1 because you are also right.
0 comments:
Post a Comment