Currently stuck on question that requires me to query data on count of user id's between 10 and 50 exclude 20 and 30. Exact Question: Write a query that returns the count of all user_id records between 10 and 50, exclusive of the user IDs 20 and 30.
Tables to pull from down below... created_at (date) name (string) address (string) state (string) zipcode (integer) user_id (integer)
CodePudding user response:
Answer is modified from previous comment meant to be the answer. The answer is right based on the format and the basic syntax is correct from a clause-base perspective. SELECT COUNT (*) FROM purchases WHERE user_id BETWEEN 10 AND 50 AND user_id NOT IN (20,30)
CodePudding user response:
Use between
and not in
:
select count(*) from mytable
where user_id between 10 and 50
and user_id not in (20, 30)