d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Having > Sql
Add Reply New Topic New Poll
Member
Posts: 2,999
Joined: Oct 12 2005
Gold: 3.00
May 12 2016 01:40pm
Hello,

I'd appreciate any help with my current task :)

From all the customers which bought (for example) tea, coffee, ice tea, ice coffee, coke (kek), lemonade, tonic (etc.) I need to find those who bought lemonade and other products. But lemonade is a must.

So, someone gave me a hint to use the HAVING clause (cause I'm gonna use summed sales data in hectoliters), but I still don't know how to use it properly.


HAVING product = 'lemonade' and sum(quantity) > 0 -- This will give me only the 'lemonade' records, but I need also the other products but only from clients who bought lemonade. Thought about ELSE clause or something, I'm really missing something here :(


Thanks in advance
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 12 2016 03:12pm
that's not the purpose of 'having'.

you'll probably want an 'in' or 'exists' clause

select * from ( <your result here> )
where customer_id in (select customer_id from products_sold where product='lemonade')
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll