diff --git a/README.md b/README.md index 1a7ce45..03ba14c 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. You can find a copy of the SQL script under the `assets` folder in this repository. -* [ ] ***pgAdmin data refresh*** +* [x] ***pgAdmin data refresh*** * Select the northwind database created during the guided project. @@ -29,7 +29,9 @@ 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 @@ -37,10 +39,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +SELECT * +FROM customers +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 @@ -48,10 +52,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +SELECT * +FROM customers +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 @@ -59,10 +65,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +SELECT 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*** +* [x] ***list orders descending by the order date. The order with date 1998-05-06 should be at the top***
hint @@ -70,10 +78,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +SELECT * +FROM orders +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 @@ -82,10 +92,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +SELECT * +FROM suppliers +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 @@ -95,10 +107,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +SELECT * +FROM customers +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' @@ -112,10 +126,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```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"_*** +* [x] ***update _Bilbo Baggins_ record so that the postal code changes to _"11122"_***
hint @@ -123,10 +139,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +UPDATE customers +SET postal_code = '11122' +WHERE upper(contact_name) LIKE '%BILBO%'; ``` -* [ ] ***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 @@ -135,10 +153,14 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +SELECT c.company_name, count(*) number_of_orders +FROM orders o JOIN customers c +ON c.customer_id = o.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*** +* [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 @@ -146,7 +168,11 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
```SQL - +SELECT c.contact_name, count(*) number_of_orders +FROM orders o JOIN customers c +ON c.customer_id = o.customer_id +GROUP BY c.contact_name +ORDER BY number_of_orders 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*** @@ -157,14 +183,18 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT c.city, count(*) number_of_orders +FROM customers c JOIN orders o +ON c.customer_id = o.customer_id +GROUP BY c.city +ORDER BY c.city; ``` ## Data Normalization Note: This step does not use PostgreSQL! -* [ ] ***Take the following data and normalize it into a 3NF database*** +* [x] ***Take the following data and normalize it into a 3NF database*** | Person Name | Pet Name | Pet Type | Pet Name 2 | Pet Type 2 | Pet Name 3 | Pet Type 3 | Fenced Yard | City Dweller | |-------------|----------|----------|------------|------------|------------|------------|-------------|--------------| @@ -177,41 +207,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: +Table Name: People 3NF -| | | | | | | | | | +| Person id | Name | | | | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +| 1 | Jane | | | | | | | | +| 2 | Bob | | | | | | | | +| 3 | Sam | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -Table Name: +Table Name: Pets 3NF -| | | | | | | | | | +| Pet id | Name | Person id | Pet Type | | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +| 1 | Ellie | 1 | Dog | | | | | | +| 2 | Joe | 2 | Horse | | | | | | +| 3 | Ginger | 3 | Dog | | | | | | +| 4 | Tiger | 1 | Cat | | | | | | +| 5 | Miss Kitty | 3 | Cat | | | | | | +| 6 | Toby | 1 | Turtle | | | | | | +| 7 | Bubble | 3 | Fish | | | | | | + +Table Name: Home 3NF + +| Home id | Fenced Yard | City Dweller | Person id | | | | | | +|------------|-------------|--------------|------------|------------|------------|------------|------------|------------| +| 1 | No | Yes | 1 | | | | | | +| 2 | No | No | 2 | | | | | | +| 3 | Yes | No | 3 | | | | | | +| | | | | | | | | | +| | | | | | | | | | +| | | | | | | | | | +| | | | | | | | | | Table Name: