MySQL में, यह सबसे आसानी से वेरिएबल का उपयोग करके किया जाता है:
select t.*
from (select t.*,
(@rn := if(@v = vehicle, @rn + 1,
if(@v := vehicle, 1, 1)
)
) as rn
from table t cross join
(select @v := -1, @rn := 0) params
order by VehicleId, timestamp desc
) t
where rn <= 3;