Skip to content
Open

Done #1404

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# SQL Bear Organizer

[Timothy Treadwell](http://en.wikipedia.org/wiki/Timothy_Treadwell) has a lot on his plate protecting the bears of the Katmai National Park in Alaska. Help him keep track of all of his bear friends using SQL.
Expand Down
9 changes: 9 additions & 0 deletions lib/create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE bears (
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER,
gender TEXT,
color TEXT,
temperament TEXT,
alive BOOLEAN
);
9 changes: 9 additions & 0 deletions lib/insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
INSERT INTO bears (id, name, age, gender, color, temperament, alive) VALUES
(1, "Mr. Chocolate", 1, "M", "honey", "sleepy", 0),
(2, "Rowdy", 2, "M", "polar", "grumpy", 0),
(3, "Tabitha", 3, "F", "black", "silly", 1),
(4, "Sargeant Brown", 4, "M", "honey", "mean", 0),
(5, "Melissa", 5, "F", "brown", "harsh", 0),
(6, "Grinch", 6, "M", "honey", "sweet", 1),
(7, "Wendy", 7, "F", "honey", "bumbly", 1),
(8, null, 8, "M", "black", "bully", 1);
16 changes: 8 additions & 8 deletions lib/sql_queries.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
def selects_all_female_bears_return_name_and_age
"Write your SQL query here"
"SELECT name, age FROM bears WHERE gender = 'F';"
end

def selects_all_bears_names_and_orders_in_alphabetical_order
"Write your SQL query here"
"SELECT name FROM bears ORDER BY name ASC;"
end

def selects_all_bears_names_and_ages_that_are_alive_and_order_youngest_to_oldest
"Write your SQL query here"
"SELECT name, age FROM bears WHERE alive = 1 ORDER BY age ASC;"
end

def selects_oldest_bear_and_returns_name_and_age
"Write your SQL query here"
"SELECT name, MAX(age) FROM bears;"
end

def select_youngest_bear_and_returns_name_and_age
"Write your SQL query here"
"SELECT name, MIN(age) FROM bears;"
end

def selects_most_prominent_color_and_returns_with_count
"Write your SQL query here"
"SELECT color, MAX(count_color) FROM (SELECT color, COUNT(color) AS count_color FROM bears GROUP BY color);"
end

def counts_number_of_bears_with_goofy_temperaments
"Write your SQL query here"
"SELECT COUNT(temperament) FROM bears WHERE temperament = 'goofy'"
end

def selects_bear_that_killed_Tim
"Write your SQL query here"
"SELECT * FROM bears WHERE temperament = 'aggressive'"
end