diff --git a/README.md b/README.md index a24715b..c639b15 100644 --- a/README.md +++ b/README.md @@ -31,59 +31,35 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same * [ ] ***find all customers that live in London. Returns 6 records*** -
hint + SELECT * +FROM customers +WHERE city = 'London' - * This can be done with SELECT and WHERE clauses -
- -```SQL - -``` * [ ] ***find all customers with postal code 1010. Returns 3 customers*** -
hint - - * This can be done with SELECT and WHERE clauses -
- -```SQL - -``` - +SELECT * +FROM customers +WHERE postal_code = '1010' * [ ] ***find the phone number for the supplier with the id 11. Should be (010) 9984510*** -
hint - - * This can be done with SELECT and WHERE clauses -
- -```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*** -
hint - - * This can be done with SELECT, WHERE, and ORDER BY clauses -
- -```SQL - -``` + SELECT * +FROM orders +ORDER BY order_date DESC * [ ] ***find all suppliers who have names longer than 20 characters. Returns 11 records*** -
hint + SELECT * +FROM suppliers +WHERE length(company_name) > 20 - * This can be done with SELECT and WHERE clauses - * You can use `length(company_name)` to get the length of the name -
- -```SQL - -``` * [ ] ***find all customers that include the word 'MARKET' in the contact title. Should return 19 records*** @@ -93,10 +69,10 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same * Don't forget the wildcard '%' symbols at the beginning and end of your substring to denote it can appear anywhere in the string in question * Remember to convert your contact title to all upper case for case insensitive comparing so upper(contact_title) +SELECT * +FROM suppliers as s +WHERE UPPER(s.contact_title) LIKE ('%MARKET%') -```SQL - -``` * [ ] ***add a customer record for*** * customer id is 'SHIRE' @@ -111,9 +87,8 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same * This can be done with the INSERT INTO clause -```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"_*** @@ -122,9 +97,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same * This can be done with UPDATE and WHERE clauses -```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*** @@ -134,9 +109,11 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same * There is more information about the COUNT clause on [W3 Schools](https://www.w3schools.com/sql/sql_count_avg_sum.asp) -```SQL - -``` +SELECT c.company_name, COUNT(o.customer_id) as thecount +FROM orders o JOIN customers c +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*** @@ -145,9 +122,12 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same * This can be done by adding an ORDER BY clause to the previous answer and changing the group by field -```SQL +SELECT c.contact_name, COUNT(o.customer_id) as thecount +FROM orders o JOIN customers c +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*** @@ -156,9 +136,11 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same * This is very similar to the previous two queries, however, it focuses on the City rather than the Customer Names -```SQL - -``` +SELECT c.city, COUNT(c.city) as thecount +FROM orders o JOIN customers c +ON o.customer_id = c.customer_id +GROUP BY c.city +ORDER BY c.city ## Data Normalization @@ -177,39 +159,38 @@ 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: +Person Table: -| | | | | | | | | | +| Person Id |Person Name |City Dwelle |Fenced Yard | | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| +| 1 | Jane | Yes | no | | | | | | +| 2 | Bob | No | no | | | | | | +| 3 | Sam | no | yes | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | - -Table Name: -| | | | | | | | | | +Pet Table: +| Pet Id | Pet Name | Pet Type | | | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +| 1 | Ellie | Dog | | | | | | | +| 2 | Joe | Horse | | | | | | | +| 3 | Ginger | Dog | | | | | | | +| 4 | Tiger | Cat | | | | | | | +| 5 | MissKitty | Cat | | | | | | | +| 6 | Toby | Turtle | | | | | | | +| 7 | Bubble | Fish | | | | | | | -Table Name: +PersonPet Table: -| | | | | | | | | | +| Pet Id | Person Id | | | | | | | | |------------|------------|------------|------------|------------|------------|------------|------------|------------| -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | -| | | | | | | | | | +| 1 | | | | | | | | | +| 2 | | | | | | | | | +| 3 | | | | | | | | | +| 4 | | | | | | | | | +| 5 | | | | | | | | | | | | | | | | | | | | | | | | | | | | |