LIKES(drinker,beer); /* key: all columns */ FREQUENTS(drinker,pub); /* key: all
ID: 3529868 • Letter: L
Question
LIKES(drinker,beer); /* key: all columns */ FREQUENTS(drinker,pub); /* key: all columns */ SERVES(_pub,beer_,cost); /* key: (pub,beer) */ 1. Find pubs that serve some beer that Joe likes. 2. Find drinkers who frequent pubs where they can get a drink for less than $3 3. Find drinkers who like at least one expensive (over $8) beer that Joe likes. 4. Find drinkers who like some beers but do not frequent any pubs. 5. Find drinkers who frequent pubs that serve either 'Pielsner' or 'Heineken'. 6. Find pubs that serve every beer that Joe likes. 7. Find all drinkers who frequent a pub that serves at least 2 beers they like, and one of them for at most $3.Explanation / Answer
Modified one:
1)
select Distinct F.pub from FREQUENTS F, LIKES L where L.drinker=F.drinker and L.drinker='Joe'
2)
select distinct L.drinker from LIKES L, SERVES S where L.drinker=F.drinker and S.beer=L.beer and S.cost<3
3)
select distinct L.drinker from LIKES L, SERVES S where L.drinker=F.drinker and S.beer=L.beer and S.cost>8 and L.beer in ( select I.beer from LIKES I where I.drinker='Joe')
4)
select distinct L.drinker from LIKES L where L.drinker not in ( Select distinct F.drinker from FREQUENTS F)
5)
select Distinct L.drinkers from FREQUENTS F, LIKES L where L.drinker=F.drinker and L.beer='Pielsner' or L.beer='Heineken'
6)
select distinct F.pub from FREQUENTS F, LIKES L where L.drinker=F.drinker and L.drinker='Joe'
7)
select F.drinker,count(beer) from FREQUENTS F, LIKES L, SERVES S where L.drinker=F.drinker and S.beer=L.beer and S.cost=3 group by F.drinker pub having count(beer)>2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.