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
120 changes: 120 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,39 @@ Answer the following data queries. Keep track of the SQL you write by pasting it

### find all customers that live in London. Returns 6 records.
> This can be done with SELECT and WHERE clauses
Thomas Hardy, Victoria Ashworth, Elizabeth Brown, Ann Devon, Simon Crowther, Hari Kumar;



### find all customers with postal code 1010. Returns 3 customers.
> This can be done with SELECT and WHERE clauses
Patricio Simpson, Yvonne Moncada, Sergio Gutierrez;


### find the phone number for the supplier with the id 11. Should be (010) 9984510.
> This can be done with SELECT and WHERE clauses
Petra Winkler (010) 9984510


### list orders descending by the order date. The order with date 1998-05-06 should be at the top.
> This can be done with SELECT, WHERE, and ORDER BY clauses
SELECT ship_name, order_date
FROM orders
WHERE order_date <= '1998-05-06'
ORDER BY order_date desc

this is the way it worked for me not sure if wanted me to copy all the longs but hope not because its a long list lol;



### find all suppliers who have names longer than 20 characters. You can use `length(company_name)` to get the length of the name. Returns 11 records.
> This can be done with SELECT and WHERE clauses
SELECT 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.
Expand All @@ -60,6 +77,14 @@ Answer the following data queries. Keep track of the SQL you write by pasting it

> Remember to convert your contact title to all upper case for case insenstive comparing so upper(contact_title)

SELECT contact_name
FROM customers
WHERE contact_title LIKE '%Market%'






### add a customer record for
* customer id is 'SHIRE'
Expand All @@ -70,25 +95,80 @@ Answer the following data queries. Keep track of the SQL you write by pasting it
* the postal code is '111'
* the country is 'Middle Earth'
> This can be done with the INSERT INTO clause
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"_.
> This can be done with UPDATE and WHERE clauses
UPDATE customers
SET postal_code = '11122'
Where postal_code = '111'







### list orders grouped by customer showing the number of orders per customer. _Rattlesnake Canyon Grocery_ should have 18 orders.
> This can be done with SELECT, COUNT, JOIN and GROUP BY clauses. Your count should focus on a field in the Orders table, not the Customer table

> There is more information about the COUNT clause on [W3 Schools](https://www.w3schools.com/sql/sql_count_avg_sum.asp)
SELECT c.contact_name, COUNT(a.customer_id)
FROM orders a JOIN customers c
ON a.customer_id = c.customer_id
GROUP BY c.contact_name










### list customers names and the number of orders per customer. Sort the list by number of orders in descending order. _Save-a-lot Markets should be at the top with 31 orders followed by _Ernst Handle_ with 30 orders. Last should be _Centro comercial Moctezuma_ with 1 order.
> This can be done by adding an ORDER BY clause to the previous answer

SELECT c.company_name, COUNT(a.customer_id) as orders
FROM orders a JOIN customers c
ON a.customer_id = c.customer_id
GROUP BY c.company_name
ORDER BY orders desc











### list orders grouped by customer's city showing number of orders per city. Returns 69 Records with _Aachen_ showing 6 orders and _Albuquerque_ showing 18 orders.
> This is very similar to the previous two queries, however, it focuses on the City rather than the CustomerName

SELECT c.city, COUNT(a.customer_id) as orders
FROM orders a JOIN customers c
ON a.customer_id = c.customer_id
GROUP BY c.city













## Data Normalization

Expand All @@ -102,6 +182,46 @@ Take the following data and normalize it into a 3NF database. You can use the w
| Bob | Joe | Horse | | | | | No | No |
| Sam | Ginger | Dog | Miss Kitty | Cat | Bubble | Fish | Yes | No |

╔═══════════╦══════════════╦═════════════╦══════════════╗
║ PERSON ID ║ PERSON NAME ║ FENCED YARD ║ CITY DWELLER ║
╠═══════════╬══════════════╬═════════════╬══════════════╣
║ 1 ║ Jane ║ No ║ Yes ║
╠═══════════╬══════════════╬═════════════╬══════════════╣
║ 2 ║ Bob ║ No ║ No ║
╠═══════════╬══════════════╬═════════════╬══════════════╣
║ 3 ║ Sam ║ Yes ║ No ║
╚═══════════╩══════════════╩═════════════╩══════════════╝
╔════════╦════════════╦══════════╦═══════════╗
║ PET ID ║ PET NAME ║ PET TYPE ║ PERSON ID ║
╠════════╬════════════╬══════════╬═══════════╣
║ 1 ║ Ellie ║ Dog ║ 1 ║
╠════════╬════════════╬══════════╬═══════════╣
║ 2 ║ Toby ║ Cat ║ 1 ║
╠════════╬════════════╬══════════╬═══════════╣
║ 3 ║ Tiger ║ Turtle ║ 1 ║
╠════════╬════════════╬══════════╬═══════════╣
║ 4 ║ Joe ║ Horse ║ 2 ║
╠════════╬════════════╬══════════╬═══════════╣
║ 5 ║ Bubble ║ Dog ║ 3 ║
╠════════╬════════════╬══════════╬═══════════╣
║ 6 ║ Ginger ║ Cat ║ 3 ║
╠════════╬════════════╬══════════╬═══════════╣
║ 7 ║ Miss Kitty ║ Fish ║ 3 ║
╚════════╩════════════╩══════════╩═══════════╝














---
## Stretch Goals

Expand Down