Question: create table Cocktails ( cname varchar(32) primary key, price integer); create table Ingredients ( iname varchar(32) primary key, unit_cost decimal, abv integer); create table Recipes
create table Cocktails ( cname varchar(32) primary key, price integer);
create table Ingredients ( iname varchar(32) primary key, unit_cost decimal, abv integer);
create table Recipes ( cname varchar(32), iname varchar(32), units integer, primary key (cname, iname), foreign key (cname) references Cocktails(cname), foreign key (iname) references Ingredients(iname) );
insert into Cocktails (cname, price) values ('Aprerol spritz', 10); insert into Cocktails (cname, price) values ('Gimlet', 14); insert into Cocktails (cname, price) values ('Manhattan', 10); insert into Cocktails (cname, price) values ('Whiskey sour', 12); insert into Cocktails (cname, price) values ('Gin fizz', 11);
insert into Ingredients (iname, unit_cost, abv) values ('gin', 1, 40); insert into Ingredients (iname, unit_cost, abv) values ('whiskey', 2, 43); insert into Ingredients (iname, unit_cost, abv) values ('vodka', 1, 40); insert into Ingredients (iname, unit_cost, abv) values ('vermouth', 0.5, 18); insert into Ingredients (iname, unit_cost, abv) values ('lemon juice', 0.1, 0); insert into Ingredients (iname, unit_cost, abv) values ('soda water', 0.1, 0);
insert into Recipes (cname, iname, units) values ('Gimlet', 'gin', 4); insert into Recipes (cname, iname, units) values ('Gimlet', 'lemon juice', 1); insert into Recipes (cname, iname, units) values ('Gin fizz', 'gin', 3); insert into Recipes (cname, iname, units) values ('Gin fizz', 'soda water', 2); insert into Recipes (cname, iname, units) values ('Gin fizz', 'lemon juice', 2); insert into Recipes (cname, iname, units) values ('Manhattan', 'whiskey', 3); insert into Recipes (cname, iname, units) values ('Manhattan', 'vermouth', 1); insert into Recipes (cname, iname, units) values ('Whiskey sour', 'whiskey', 2); insert into Recipes (cname, iname, units) values ('Whiskey sour', 'lemon juice', 1);
List pairs of cocktails that contain the same ingredient. Result should have the schema: (cname1, cname2, iname). Do not list a pair more than once, e.g., you should not list both (Gimlet, Gin fizz, gin) and (Gin fizz, Gimlet, gin). postgrsql
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
