gpt4 book ai didi

php - MySQL选择不同的行

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

你好,我有一个这样的模式,表名提要

其中msg_id是唯一的,是表的主键

| msg_id |评论|
| 1 | 10 |
| 2 | 10 |
| 3 | 10 |
| 4 | 21 |

我想构建一个查询来选择最后两行

输出应该是这样的

| msg_id |评论|
| 3 | 10 |
| 4 | 21 |

简而言之,查询应该返回带有 msg_id 的行,这些行具有不同的注释值

最佳答案

按列分组是唯一的,并为每组选择最高的id

select max(msg_id) as msg_id, commented
from your_table
group by commented

关于php - MySQL选择不同的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26799133/

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