gpt4 book ai didi

mysql - SQL从数据库中选择具有最大值的行并按2列分组

转载 作者:搜寻专家 更新时间:2023-10-30 23:28:57 24 4
gpt4 key购买 nike

<分区>

我有这张表:

TABLE 优惠

 +------+--------------+----------+----------------+
| id | player_id | team_id | valore |
+------+--------------+----------+----------------+
| 1 | 1 | 1 | 230 |
| 2 | 1 | 3 | 150 |
| 3 | 9 | 3 | 150 |
| 4 | 1 | 5 | 100 |
| 5 | 7 | 5 | 37 |
| 6 | 7 | 1 | 38 |
+------+--------------+----------+----------------+

我期待这样的结果,我想创建一个这样的 View :

+------+--------------+----------+----------------+
| id | player_id | team_id | valore |
+------+--------------+----------+----------------+
| 1 | 1 | 1 | 230 |
| 3 | 9 | 3 | 150 |
| 6 | 7 | 1 | 38 |
+------+--------------+----------+----------------+

我尝试使用此 SQL 代码:

创建 View ...

select t1.* 
from offers t1
left join ( select player_id,
team_id,
max(valore) as valore
from offers
group by player_id,
team_id) t2
on t1.player_id = t2.player_id
and t1.team_id = t2.team_id
and t1.valore = t2.valore

但结果与第一个表相同......它没有改变任何东西。谁能帮帮我?

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