gpt4 book ai didi

mysql - 在mysql查询中获取最大值

转载 作者:可可西里 更新时间:2023-11-01 06:38:58 24 4
gpt4 key购买 nike

我有一张 table

       id     mid    userid    remarks
1 2 8 7
2 2 8 6
3 2 8 4
4 2 8 5
5 2 8 2
6 2 8 3
7 2 8 7
8 2 8 0
9 2 8 1
10 2 8 8

我需要该行之前的最后一行备注。即,备注“1”

SELECT MAX(id),mid,userid,remarks FROM sample 

最佳答案

Select Id,mid,userid,remarks from sample Where id<(select max(Id) from sample)
order by id desc limit 1

或者

Select Id,mid,userid,remarks from sample 
order by id desc limit 1 offset 1

关于mysql - 在mysql查询中获取最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11913408/

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