如何获取mysql中最后插入的2行特定id?

如何获取mysql中最后插入的2行特定id?,mysql,sql,datetime,Mysql,Sql,Datetime,我正在使用mysql。我在获取行时遇到问题。我的桌子是这样的 vehicleno lat lng status rdate rtime 12 13 12 05:56:45 12 05:58:45 此表不

我正在使用mysql。我在获取行时遇到问题。我的桌子是这样的

vehicleno     lat       lng       status        rdate       rtime
  12
  13
  12                                                        05:56:45
  12                                                        05:58:45 

此表不断插入用于跟踪车辆的值。我想最后插入2个值(行)的垂直车辆(如12)。这样我就可以确定车辆是空闲还是移动。如何编写查询。请在这方面帮助我。

将rtime列数据类型time更改为datetime

MYSQL

编辑

   hql2.setMaxResults(2);

尝试此查询,它将适用于Hibernate


从HistoryLatitudeBean中选择前2个rtime,其中vehicleno=:vehicleno ORDER BY rtime DESC

从表中选择*,其中vehicleno=12 ORDER BY rtime DESC limit 2
应起作用。由于不知道什么列类型
rtime
,我无法确定。很高兴它起作用了。没有数据可供使用,我不确定如何让SQL在所有车辆上运行。我不知道hibernate是什么,mate,对不起。这里从vehicle where vehicleno=12是的,这里就是,
String hql2=“从HistoryLatitudeBean where vehicleno=:vehicleno ORDER BY rtime DESC limit 2”查询正在执行,但不限制2。请从查询中删除限制2,并使用post中给出的setMaxResults
   hql2.setMaxResults(2);