diff --git a/README.md b/README.md index a24715b..0203b09 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT customer_id, city +FROM customers +WHERE city = 'London' ``` * [ ] ***find all customers with postal code 1010. Returns 3 customers*** @@ -48,7 +50,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT customer_id, postal_code +FROM customers +WHERE postal_code = '1010' ``` * [ ] ***find the phone number for the supplier with the id 11. Should be (010) 9984510*** @@ -59,7 +63,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT 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*** @@ -70,7 +76,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT customer_id, order_date +FROM orders +ORDER BY order_date DESC ``` * [ ] ***find all suppliers who have names longer than 20 characters. Returns 11 records*** @@ -82,7 +90,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT supplier_id, company_name +FROM suppliers +WHERE length(company_name) > '20' ``` * [ ] ***find all customers that include the word 'MARKET' in the contact title. Should return 19 records*** @@ -95,7 +105,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT contact_title +FROM customers +WHERE upper(contact_title) LIKE '%MARKET%' ``` * [ ] ***add a customer record for*** @@ -112,7 +124,8 @@ 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', 'Bage End', '111', 'Middle Earth') ``` * [ ] ***update _Bilbo Baggins_ record so that the postal code changes to _"11122"_*** @@ -123,7 +136,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +UPDATE customers +SET postal_code = '11122' +WHERE contact_name = 'Bilbo Baggins' ``` * [ ] ***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*** @@ -135,7 +150,10 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +-- SELECT count(o.order_date), c.company_name +-- FROM order o RIGHT JOIN customers c +-- ON o.customer_id = c.customer_id +-- GROUP 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*** @@ -146,7 +164,11 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT count(o.order_date), c.city +FROM order o RIGHT JOIN customers c +ON o.customer_id = c.customer_id +GROUP BY c.contact_name +ORDER BY count(0.order_date) 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,7 +179,11 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same ```SQL - +SELECT count(o.order_date), c.city +FROM order o RIGHT JOIN customers c +ON o.customer_id = c.customer_id +GROUP BY c.city +ORDER BY count(o.order_date) desc ``` ## Data Normalization @@ -177,41 +203,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: Person -| | | | | | | | | | -|------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +|Person Id |Name |fenced yard |City Dweller| | | | | | +|------------|------------|------------|------------|------------|------------|------------|------------| +|1 |Jane |0 |1 | | | | | | +|2 |Bob |0 |0 | | | | | | +|3 |Sam |1 |0 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -Table Name: +Table Name: Pet Type -| | | | | | | | | | +|Person Id | Type | | | | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +|1 |dog | | | | | | | | +|2 |horse | | | | | | | | +|3 |cat | | | | | | | | +|4 |turtle | | | | | | | | +|5 |fish | | | | | | | | | | | | | | | | | | | | | | | | | | | | -Table Name: +Table Name: Pets -| | | | | | | | | | +|Id |Owner Id |Pet Id |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: