SQL · ByteDance · Medium
Given a table impressions(ad_id INT, user_id INT, impression_ts TIMESTAMP), each row records that user_id saw ad_id at impression_ts. A single (ad_id, user_id) pair may occur multiple times. Write a single SQL statement that returns one row for every (ad_id, user_id) group that occurs at least twice. The row must include: last_impression_ts: the latest timestamp in the group second_last_impression_ts: the timestamp immediately preceding the latest one diff_seconds: the…
Checking your access…