-
Help with an assignment
Please help me to deal with the following problem (at least in SQL or relational algebra):
Find all drinkers who frequent a bar that serves at least 2 beers they like , and one of them for at most 2$.
LIKES(drinker,beer)
FREQUENTS(drinker, bar)
SERVES(bar,beer,cost)
-
It is a complicated query, your professor really likes cheap beer. I gave my "shot"
select l.drinker
from likes as l
inner join frequents as f
on l.beer = f.beer
where (select count(*) from serves as s where s.bar = l.bar and s.beer = l.beer) >= 2
and exists (select * from serves as s where s.bar = = l.bar and s.beer = l.beer and s.cost <=2)
and
-
I did it slightly different, without using aggregate functions. Thank you for the provided solution.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|