sql select first and last record of each group

Solutions on MaxInterview for sql select first and last record of each group by the best coders in the world

showing results for - "sql select first and last record of each group"
Felix
23 Jan 2018
1select v.*
2from (select v.*,
3             row_number() over (partition by vehicleid, tripid order by datetime asc) as seqnum_asc,
4             row_number() over (partition by vehicleid, tripid order by datetime desc) as seqnum_desc
5      from vehicles v
6     ) v
7where seqnum_asc = 1 or seqnum_desc = 1;