Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 74 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```SQL

SELECT *
FROM customers
WHERE UPPER(city) = 'LONDON'
```

* [ ] ***find all customers with postal code 1010. Returns 3 customers***
Expand All @@ -48,7 +50,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```SQL

SELECT *
FROM customers
WHERE postal_code = '1010'
```

* [ ] ***find the phone number for the supplier with the id 11. Should be (010) 9984510***
Expand All @@ -59,7 +63,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```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***
Expand All @@ -70,7 +76,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```SQL

SELECT *
FROM orders
ORDER BY order_date DESC <-- I couldn't think of a way to do this with a WHERE clause -->
```

* [ ] ***find all suppliers who have names longer than 20 characters. Returns 11 records***
Expand All @@ -82,7 +90,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```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***
Expand All @@ -95,7 +105,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```SQL

SELECT *
FROM customers
WHERE UPPER(contact_title) LIKE '%MARKET%'
```

* [ ] ***add a customer record for***
Expand All @@ -112,7 +124,8 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```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"_***
Expand All @@ -123,7 +136,9 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```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***
Expand All @@ -135,7 +150,11 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```SQL

SELECT c.company_name, COUNT(o.order_id)
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***
Expand All @@ -146,7 +165,11 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```SQL

SELECT c.contact_name, COUNT(o.order_id) as ordertotal
FROM orders o JOIN customers c
ON o.customer_id = c.customer_id
GROUP BY c.contact_name
ORDER BY ordertotal 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***
Expand All @@ -157,7 +180,11 @@ Reimport the Northwind database into PostgreSQL using pgAdmin. This is the same
</details>

```SQL

SELECT c.city, COUNT(o.order_id) as ordertotal
FROM orders o JOIN customers c
ON o.customer_id = c.customer_id
GROUP BY c.city
ORDER BY ordertotal DESC
```

## Data Normalization
Expand All @@ -177,49 +204,49 @@ 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 Table

| | | | | | | | | |
| Person ID |First Name | | | | | | | |
|------------|------------|------------|------------|------------|------------|------------|------------|------------|
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| 1 |Jane | | | | | | | |
| 2 |Bob | | | | | | | |
| 3 |Sam | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |

Table Name:
Table Name:Person/Pet Table

| | | | | | | | | |
| Person ID |Pet ID | | | | | | | |
|------------|------------|------------|------------|------------|------------|------------|------------|------------|
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| 1 | 1 | | | | | | | |
| 1 | 2 | | | | | | | |
| 1 | 3 | | | | | | | |
| 2 | 4 | | | | | | | |
| 3 | 5 | | | | | | | |
| 3 | 6 | | | | | | | |
| 3 | 7 | | | | | | | |

Table Name:
Table Name:Pet Table

| | | | | | | | | |
|Pet ID |Pet Name |Pet Type | | | | | | |
|------------|------------|------------|------------|------------|------------|------------|------------|------------|
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| 1 |Ellie |Dog | | | | | | |
| 2 |Tiger |Cat | | | | | | |
| 3 |Toby |Turtle | | | | | | |
| 4 |Joe |Horse | | | | | | |
| 5 |Ginger |Dog | | | | | | |
| 6 |Miss Kitty |Cat | | | | | | |
| 7 |Bubble |Fish | | | | | | |

Table Name:
Table Name:Lifestyle

| | | | | | | | | |
|Person ID |Fence |City | | | | | | |
|------------|------------|------------|------------|------------|------------|------------|------------|------------|
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| 1 |No |Yes | | | | | | |
| 2 |No |No | | | | | | |
| 3 |Yes |No | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
Expand All @@ -232,7 +259,10 @@ Table Name:
* [ ] ***delete all customers that have no orders. Should delete 2 (or 3 if you haven't deleted the record added) records***

```SQL

DELETE
FROM customers USING Orders
where customers.customer_id = orders.customer_id
and orders.order_id is NULL; <-- USING not JOIN -->
```

* [ ] ***Create Database and Table: After creating the database, tables, columns, and constraint, generate the script necessary to recreate the database. This script is what you will submit for review***
Expand All @@ -250,7 +280,10 @@ Table Name:
* account `budget` is required.

```SQL

CREATE TABLE ACCOUNTS(id INTEGER, name TEXT, budget INTEGER);
INSERT INTO ACCOUNTS VALUES(1, 'Jack', 4);
INSERT INTO ACCOUNTS VALUES(2, 'Sally', 3);
INSERT INTO ACCOUNTS VALUES(3, 'Sandy-Clause', 4);
```

To see the script
Expand Down