Skip to content

Instantly share code, notes, and snippets.

@YiLi225

YiLi225/AND_logic.sql

Last active Dec 6, 2020
Embed
What would you like to do?
/** 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