dcsimg
Results 1 to 3 of 3

Thread: Help with an assignment

  1. #1
    Join Date
    Oct 2011
    Posts
    3

    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)

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,912
    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

  3. #3
    Join Date
    Oct 2011
    Posts
    3
    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
  •