Skip to content

Instantly share code, notes, and snippets.

@YiLi225

YiLi225/sequential.sql

Last active Nov 29, 2020
Embed
What would you like to do?
/** 3. User logins in California followed by Massachusetts **/
SELECT *
FROM
(
SELECT
dat.*,
LEAD(location_var) OVER (PARTITION BY id_var ORDER BY date_var) AS next_location
FROM
userlogin dat
) dat2
WHERE
location_var = 'California' AND next_location = 'Massachusetts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment