MySQL如何从下表中为每对值选择最高值?

时间:2021-01-26 13:42:38

I have the following table:

我有下表:

+----+---------+---------+-------+
| ID | FARM_ID | GATE_ID | SCORE |
+----+---------+---------+-------+
|  1 |       1 |       1 |   100 |
|  2 |       2 |       1 |   100 |
|  3 |       5 |       5 |   100 |
|  4 |       4 |       1 |    16 |
|  5 |       4 |       3 |    16 |
|  6 |       4 |       5 |    23 |
|  7 |       5 |       1 |   100 |
|  8 |       4 |       1 |    95 |
|  9 |       4 |       3 |    91 |
| 10 |       4 |       5 |   100 |
| 11 |       5 |       1 |    20 |
| 12 |       4 |       1 |   100 |
| 13 |       4 |       3 |    95 |
| 14 |       4 |       5 |    95 |
| 15 |       4 |       6 |    91 |
| 16 |       5 |       1 |    16 |
| 17 |       4 |       1 |    95 |
| 18 |       4 |       2 |    91 |
| 19 |       4 |       3 |   100 |
| 20 |       4 |       5 |    91 |
| 21 |       4 |       6 |    95 |
| 22 |       4 |       1 |    91 |
| 23 |       4 |       2 |    95 |
| 24 |       4 |       3 |    95 |
| 25 |       4 |       4 |    91 |
| 26 |       4 |       6 |   100 |
| 27 |       4 |       2 |   100 |
| 28 |       4 |       3 |    91 |
| 29 |       4 |       4 |    95 |
| 30 |       4 |       6 |    95 |
| 31 |       4 |       2 |    95 |
| 32 |       4 |       4 |   100 |
| 33 |       4 |       6 |    91 |
| 34 |       5 |       3 |   100 |
| 35 |       5 |       6 |   100 |
| 36 |       5 |       2 |   100 |
| 37 |       5 |       4 |   100 |
| 38 |       3 |       1 |    91 |
| 39 |       3 |       5 |   100 |
| 40 |       3 |       1 |   100 |
| 41 |       3 |       3 |    91 |
| 42 |       3 |       5 |    91 |
| 43 |       3 |       1 |    91 |
| 44 |       3 |       3 |   100 |
| 45 |       3 |       6 |    91 |
| 46 |       3 |       2 |    91 |
| 47 |       3 |       3 |    91 |
| 48 |       3 |       6 |   100 |
| 49 |       3 |       2 |   100 |
| 50 |       3 |       4 |    91 |
| 51 |       3 |       6 |    91 |
| 52 |       3 |       2 |    91 |
| 53 |       3 |       4 |   100 |
| 54 |       8 |       1 |   100 |
| 55 |       7 |       1 |   100 |
| 56 |       6 |       1 |   100 |
+----+---------+---------+-------+

Desired results:

期望的结果:

I wish to show only the highest score for each FARM_ID--GATE_ID pair. (There should be 23 unique pairs present above and as a result).

我希望只显示每个FARM_ID - GATE_ID对的最高分。 (上面应该有23个独特的对,因此)。

Thanks greatly!

非常感谢!

1 个解决方案

#1


3  

select farm_id, gate_id, max(score)
from table
group by farm_id, gate_id 

?

#1


3  

select farm_id, gate_id, max(score)
from table
group by farm_id, gate_id 

?