57. First and Last Value

This advanced SQL exercise is part of the book: Advanced SQL – Practical Techniques and Use-Cases, which includes 100 day-to-day SQL challenges (and solutions), need-to-know advanced features, and key concepts.

Given a table that specifies the travel route of a sales agent. Each row specifies the date when the agent arrived at the current destination (DestDate), the previous destination the agent visited (PrevDest), and the current destination where the agent is present now (CurrDate):

CREATE TABLE Destinations
(DestDate date,
PrevDest varchar(25),
CurrDest varchar(25))

To read more

UpScale Analytics is one of the largest platforms in the world for learning SQL by doing, consisting over 300 SQL exercises at different levels (including solutions), by topics, across over 100 different datasets. More…