Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Last active December 6, 2020 01:38
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/e9b393d6f8240f5194a3e4bfe7c9f450 to your computer and use it in GitHub Desktop.
Save YiLi225/e9b393d6f8240f5194a3e4bfe7c9f450 to your computer and use it in GitHub Desktop.
/** 1.2 User logins in both NYC and Illinois -- logic AND **/
SELECT
id_var, user_var
FROM
(
SELECT
id_var,
user_var,
SUM(CASE WHEN location_var = 'NYC' THEN 1 ELSE 0 END) AS nyc_cnt,
SUM(CASE WHEN location_var = 'Illinois' THEN 1 ELSE 0 END) AS illinois_cnt
FROM
userlogin
GROUP BY id_var, user_var
) dat
WHERE
nyc_cnt > 0
AND illinois_cnt > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment