分享一个分组排序取最新一条数据的sql
select day, startTimeFiveMin, lon, lat, type from (
select day, startTimeFiveMin,lon,lat, type, ROW_NUMBER() OVER (PARTITION BY day ORDER BY o ASC) AS rank
from (
SELECT
day,
startTimeFiveMin,
lon,
lat,
type,
(case when type = 'gps' then 1 when type = 'wifi' then 2 when type = 'ip' then 3 else 4 end) as o
FROM
(
SELECT *
FROM test_lbs_data.ga_lbs_ontime_data
LIMIT 100
) AS a
) b
) c where c.rank = 1