From a4dcf39db8687a42ef46c37725e411b313587a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 20:49:45 -0400 Subject: [PATCH 01/13] start --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a24715b..aa85fd8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Working with SQL Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same data we used during the guided project. -* [ ] ***pgAdmin data refresh*** +* [x] ***pgAdmin data refresh*** * Select the northwind database created during the guided project. From 5dba6afef096826236729b32648c9768fba59c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 20:57:42 -0400 Subject: [PATCH 02/13] question 1 complete --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aa85fd8..5385344 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ### Answer the following data queries. Keep track of the SQL you write by pasting it into this document under its appropriate header below in the provided SQL code block. You will be submitting that through the regular fork, change, pull process -* [ ] ***find all customers that live in London. Returns 6 records*** +* [x] ***find all customers that live in London. Returns 6 records***
hint @@ -38,6 +38,10 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL +SELECT contact_name, city +FROM customers +WHERE city = ('London') + ``` * [ ] ***find all customers with postal code 1010. Returns 3 customers*** From 6f8842b12ba5a58099841886dd778afd6fa87878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:00:20 -0400 Subject: [PATCH 03/13] question 2 complete --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5385344..56cd45d 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ WHERE city = ('London') ``` -* [ ] ***find all customers with postal code 1010. Returns 3 customers*** +* [x] ***find all customers with postal code 1010. Returns 3 customers***
hint @@ -53,6 +53,10 @@ WHERE city = ('London') ```SQL +SELECT contact_name, postal_code +FROM customers +WHERE postal_code = '1010' + ``` * [ ] ***find the phone number for the supplier with the id 11. Should be (010) 9984510*** From f0cdaa33496b08d8c719549e7938c804a7b081eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:04:49 -0400 Subject: [PATCH 04/13] question 3 complete --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56cd45d..07e4239 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ WHERE postal_code = '1010' ``` -* [ ] ***find the phone number for the supplier with the id 11. Should be (010) 9984510*** +* [x] ***find the phone number for the supplier with the id 11. Should be (010) 9984510***
hint @@ -68,6 +68,10 @@ WHERE postal_code = '1010' ```SQL +SELECT contact_name, supplier_id, phone +FROM suppliers +WHERE supplier_id = '11' + ``` * [ ] ***list orders descending by the order date. The order with date 1998-05-06 should be at the top*** From 876d56c419720e2ca7890d68c38db1d54d480b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:10:16 -0400 Subject: [PATCH 05/13] question 4 complete --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07e4239..cfeb80c 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ WHERE supplier_id = '11' ``` -* [ ] ***list orders descending by the order date. The order with date 1998-05-06 should be at the top*** +* [x] ***list orders descending by the order date. The order with date 1998-05-06 should be at the top***
hint @@ -83,6 +83,10 @@ WHERE supplier_id = '11' ```SQL +SELECT * +FROM orders +ORDER BY order_date desc + ``` * [ ] ***find all suppliers who have names longer than 20 characters. Returns 11 records*** From cb76e6755b3a3b97acd4e929bfe4cf3eb6509101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:12:51 -0400 Subject: [PATCH 06/13] question 5 complete --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cfeb80c..1a64db9 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ ORDER BY order_date desc ``` -* [ ] ***find all suppliers who have names longer than 20 characters. Returns 11 records*** +* [x] ***find all suppliers who have names longer than 20 characters. Returns 11 records***
hint @@ -99,6 +99,10 @@ ORDER BY order_date desc ```SQL +SELECT contact_name +FROM suppliers +WHERE length(company_name) > 20 + ``` * [ ] ***find all customers that include the word 'MARKET' in the contact title. Should return 19 records*** From e3cf4e9d498e21cdfe3c58c985fcfc2ecf446133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:23:57 -0400 Subject: [PATCH 07/13] question 6 complete --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a64db9..7ad56b3 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ WHERE length(company_name) > 20 ``` -* [ ] ***find all customers that include the word 'MARKET' in the contact title. Should return 19 records*** +* [x] ***find all customers that include the word 'MARKET' in the contact title. Should return 19 records***
hint @@ -116,6 +116,10 @@ WHERE length(company_name) > 20 ```SQL +SELECT contact_title +FROM customers +WHERE upper(contact_title) LIKE ('%MARKET%') + ``` * [ ] ***add a customer record for*** From bb1db4315847bfe56d80fb034ba9513e0de9e282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:31:46 -0400 Subject: [PATCH 08/13] question 7 complete --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7ad56b3..29761be 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,9 @@ WHERE upper(contact_title) LIKE ('%MARKET%') ```SQL +INSERT INTO customers(customer_id, company_name, contact_name, address, city, postal_code, country) +VALUES ('SHIRE', 'The Shire', 'Bilbo Baggins', '1 Hobbit-Hole', 'Bag End', '111', 'Middle Earth') + ``` * [ ] ***update _Bilbo Baggins_ record so that the postal code changes to _"11122"_*** From 6e1970f98a0f5965815775b674be24a923d93ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:34:29 -0400 Subject: [PATCH 09/13] question 8 complete --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29761be..49f0ef1 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ WHERE upper(contact_title) LIKE ('%MARKET%') ``` -* [ ] ***add a customer record for*** +* [x] ***add a customer record for*** * customer id is 'SHIRE' * company name is 'The Shire' * contact name is 'Bilbo Baggins' @@ -142,7 +142,7 @@ VALUES ('SHIRE', 'The Shire', 'Bilbo Baggins', '1 Hobbit-Hole', 'Bag End', '111' ``` -* [ ] ***update _Bilbo Baggins_ record so that the postal code changes to _"11122"_*** +* [x] ***update _Bilbo Baggins_ record so that the postal code changes to _"11122"_***
hint @@ -151,6 +151,10 @@ VALUES ('SHIRE', 'The Shire', 'Bilbo Baggins', '1 Hobbit-Hole', 'Bag End', '111' ```SQL +UPDATE customers +SET postal_code = '11122' +WHERE customer_id = 'SHIRE' + ``` * [ ] ***list orders grouped and ordered by customer company name showing the number of orders per customer company name. _Rattlesnake Canyon Grocery_ should have 18 orders*** From 18ffe67f0e4873d67c80bf31d3a97d3e34ea248b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:52:32 -0400 Subject: [PATCH 10/13] question 9 complete --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 49f0ef1..5581739 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ WHERE customer_id = 'SHIRE' ``` -* [ ] ***list orders grouped and ordered by customer company name showing the number of orders per customer company name. _Rattlesnake Canyon Grocery_ should have 18 orders*** +* [x] ***list orders grouped and ordered by customer company name showing the number of orders per customer company name. _Rattlesnake Canyon Grocery_ should have 18 orders***
hint @@ -167,6 +167,12 @@ WHERE customer_id = 'SHIRE' ```SQL +SELECT c.company_name, COUNT(o.customer_id) +FROM customers c JOIN orders o +ON o.customer_id = c.customer_id +GROUP BY c.company_name +ORDER BY c.company_name + ``` * [ ] ***list customers by contact name and the number of orders per contact name. Sort the list by the number of orders in descending order. _Jose Pavarotti_ should be at the top with 31 orders followed by _Roland Mendal_ with 30 orders. Last should be _Francisco Chang_ with 1 order*** From 8ea4c153345c995b02d5301fe5c10bd681b30463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 21:57:50 -0400 Subject: [PATCH 11/13] question 10 complete --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5581739..00ce95c 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,7 @@ ORDER BY c.company_name ``` -* [ ] ***list customers by contact name and the number of orders per contact name. Sort the list by the number of orders in descending order. _Jose Pavarotti_ should be at the top with 31 orders followed by _Roland Mendal_ with 30 orders. Last should be _Francisco Chang_ with 1 order*** +* [x] ***list customers by contact name and the number of orders per contact name. Sort the list by the number of orders in descending order. _Jose Pavarotti_ should be at the top with 31 orders followed by _Roland Mendal_ with 30 orders. Last should be _Francisco Chang_ with 1 order***
hint @@ -184,6 +184,12 @@ ORDER BY c.company_name ```SQL +SELECT c.contact_name, COUNT(o.customer_id) +FROM customers c JOIN orders o +ON o.customer_id = c.customer_id +GROUP BY c.contact_name +ORDER BY 2 DESC + ``` * [ ] ***list orders grouped by customer's city showing the number of orders per city. Returns 69 Records with _Aachen_ showing 6 orders and _Albuquerque_ showing 18 orders*** From 00150ad32650c37e1df03d17580783116c4685ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 22:04:03 -0400 Subject: [PATCH 12/13] question 11 complete --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 00ce95c..d14398c 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ ORDER BY 2 DESC ``` -* [ ] ***list orders grouped by customer's city showing the number of orders per city. Returns 69 Records with _Aachen_ showing 6 orders and _Albuquerque_ showing 18 orders*** +* [x] ***list orders grouped by customer's city showing the number of orders per city. Returns 69 Records with _Aachen_ showing 6 orders and _Albuquerque_ showing 18 orders***
hint @@ -201,6 +201,12 @@ ORDER BY 2 DESC ```SQL +SELECT c.city, COUNT(o.customer_id) +FROM customers c JOIN orders o +ON o.customer_id = c.customer_id +GROUP BY c.city +ORDER BY 2 DESC + ``` ## Data Normalization From bf537445c7de31e9056c669d70a62f9a5cabfb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myeongwon=20Andr=C3=A9=20Jeon?= Date: Wed, 2 Sep 2020 23:40:01 -0400 Subject: [PATCH 13/13] mvp done --- README.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d14398c..2582e4c 100644 --- a/README.md +++ b/README.md @@ -226,41 +226,41 @@ Below are some empty tables to be used to normalize the database * Not all of the cells will contain data in the final solution * Feel free to edit these tables as necessary -Table Name: +Table Name: Persons -| | | | | | | | | | +| id | Person |fenced yard |City Dweller| | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +| 1 | Jane | 0 | 1 | | | | | | +| 2 | Bob | 0 | 0 | | | | | | +| 3 | Sam | 1 | 0 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -Table Name: +Table Name: Pet Types -| | | | | | | | | | +| id | pet type | | | | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +| 1 | dog | | | | | | | | +| 2 | horse | | | | | | | | +| 3 | cat | | | | | | | | +| 4 | turtle | | | | | | | | +| 5 | fish | | | | | | | | | | | | | | | | | | | | | | | | | | | | -Table Name: +Table Name: Pets -| | | | | | | | | | +| id | owner id | pet id | pet name | | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +| 1 | 1 | 1 | Ellie | | | | | | +| 2 | 1 | 3 | Tiger | | | | | | +| 3 | 1 | 4 | Toby | | | | | | +| 4 | 2 | 2 | Joe | | | | | | +| 5 | 3 | 1 | Ginger | | | | | | +| 6 | 3 | 3 | Miss Kitty | | | | | | +| 7 | 3 | 5 | Bubble | | | | | | Table Name: