Skip to content

Instantly share code, notes, and snippets.

@ewhitebloom
Last active August 29, 2015 13:57
Show Gist options
  • Save ewhitebloom/9470723 to your computer and use it in GitHub Desktop.
Save ewhitebloom/9470723 to your computer and use it in GitHub Desktop.
Recipes
1) select title, rating from movies where rating is not null order by rating asc limit 50;
2) select title from movies where rating is null order by title asc;
3) select title from movies where synopsis ilike '%thrilling%';
4) select title, year, rating from movies join genres on movies.genre_id = genres.id where genres.name = 'Science Fiction & Fantasy' AND movies.year BETWEEN 1980 AND 1990 order by rating desc;
5) select actors.name, movies.title, movies.year from cast_members join actors on actors.id = cast_members.actor_id join movies on movies.id = cast_members.movie_id where character ilike '%james bond%' order by year desc;
6) select movies.title, movies.year, genres.name from cast_members join movies on movies.id = cast_members.movie_id join actors on actors.id = cast_members.actor_id join genres on movies.genre_id = genres.id where actors.name = 'Julianne Moore' order by genres.name, movies.title;
7) select movies.title, movies.year, studios.name from movies join genres on genres.id = movies.genre_id join studios on studios.id = movies.studio_id where genres.name = 'Horror' order by year asc limit 5;
Recipes:
createdb recipes
CREATE TABLE recipes (
id serial,
name varchar(255) NOT NULL,
yields varchar(255),
time varchar(255),
ingredients_id integer not null,
directions varchar(1000)
)
CREATE TABLE ingredients (
id serial,
ingredients varchar(400) not null,
)
INSERT INTO recipes (name, yields, time, ingredients_id, directions)
VALUES ('Green Eggs & Ham', 2, 25, 1, '1) Cook the eggs. 2) Cook the ham. 3) Combine.' );
INSERT INTO ingredients (ingredients)
VALUES ('4 green eggs
1/2 lb ham');
INSERT INTO recipes (name, ingredients_id, directions)
VALUES ('Fried Green Tomatoes', 2, '1. Slice the tomatoes 1/2 inch thick.
2. Whisk eggs and milk together.
3. Dip tomatoes in egg mixture and then bread crumbs.
4. Heat oil in a large skillet.
5. Fry the tomatoes in the oil.' );
INSERT INTO ingredients (ingredients)
VALUES ('3 large green tomatoes
2 eggs
1/2 cup milk
1/2 cup breadcrumbs
1 quart vegetable oil');
INSERT INTO recipes (name, yields, ingredients_id, directions)
VALUES ('Martini', 1, 3, '1. Pour all ingredients into mixing glass with ice cubes.
2. Stir well.
3. Strain in chilled martini cocktail glass.
4. Squeeze oil from lemon peel onto the drink, or garnish with olive.' );
INSERT INTO ingredients (ingredients)
VALUES ('2 oz gin
1 oz dry vermouth
(optional) lemon peel or olive');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment