diff --git a/README.md b/README.md index 9d497ea495..1577f19487 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/create.sql b/lib/create.sql index e69de29bb2..b000adafde 100644 --- a/lib/create.sql +++ b/lib/create.sql @@ -0,0 +1,9 @@ +CREATE TABLE bears ( +id INTEGER PRIMARY KEY, +name TEXT, +age INTEGER, +gender TEXT, +color TEXT, +temperament TEXT, +alive BOOLEAN +); \ No newline at end of file diff --git a/lib/insert.sql b/lib/insert.sql index e69de29bb2..148ec8caa8 100644 --- a/lib/insert.sql +++ b/lib/insert.sql @@ -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); diff --git a/lib/sql_queries.rb b/lib/sql_queries.rb index 187dc75632..4d524ab53d 100644 --- a/lib/sql_queries.rb +++ b/lib/sql_queries.rb @@ -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