答案 0 :(得分:1)
您可以将sunquery用于最长时间
select * from my_table
where time1 = (
select max(time1)
from my_table
)
答案 1 :(得分:1)
这是一个依赖于窗口函数RANK()
(自MySQL 8.0起可用)的解决方案:
SELECT *
FROM (SELECT id, name, time1, RANK() OVER(ORDER BY time1 DESC) rnk FROM mytable) x
WHERE rnk = 1
内部查询为每条记录分配一个等级,按降序排列;排名最高的领带的排名相同,1
。然后,外部查询仅过滤排名为1
的记录。
答案 2 :(得分:0)
请尝试这个,
select * from table1 where time1 =(select time1 from table1 order by time1 limit 0,1);
或
select * from table1 where time1 = ( select max(time1) from table1 )
或
select * from table1 where time1=(select TOP 1 time1 from table1 order by time1 desc )