gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:36:29 26 4
gpt4 key购买 nike

我有下表:

+----+---------+---------+-------+
| 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 |
+----+---------+---------+-------+

期望的结果:

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

非常感谢!

最佳答案

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

?

关于MySQL 如何从下表中为每对值仅选择最高值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10131206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com