SQL: How to select users that have purchased ONLY a certain product? -
say have table looks following
customer purchases james basketball james football alex basketball how select customers have purchased basketball? ie alex. or advice.
this 1 way using standard sql;
select customer table1 group customer having count(*) = 1 , max(purchases)='basketball' if customer may have purchased more 1 basketball, can replace count(*) count(distinct purchases).
if go database specific, more readable option may except or minus, here sql server version;
select customer table1 purchases='basketball' except select customer table1 purchases<>'basketball' ...which same thing latter (may have purchased more 1 basketball) case.
Comments
Post a Comment