Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Last active November 29, 2020 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YiLi225/70de51ee31659a2c3d391f3762c94aa9 to your computer and use it in GitHub Desktop.
Save YiLi225/70de51ee31659a2c3d391f3762c94aa9 to your computer and use it in GitHub Desktop.
/** 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