Explain how to find the first or last event for each entity using advanced SQL techniques.
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Overview: Explain how to return the first or last event for each user or entity in SQL. Tests your command of window functions, deterministic tie-breaking, NULL ordering, and alternatives such as DISTINCT ON, aggregate re-joins and lateral joins.