把表名代进去试试
select devicename,eventsdatetime from (
select
devicename,
eventsdatetime,
row_number()over(partition by rn order by eventsdatetime desc) as rn from (
select
devicename,
eventsdatetime,
row_number()over(order by eventsdatetime)-row_number()over(partition by substr(devicename,1,1) order by eventsdatetime) as rn
from 表名 ) t1
) t2 where rn=1
order by 2