Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions exercises/00-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $ postgres=#
## Create Tables
```sql
create table users (
user_handle int Primary key,
user_handle uuid Primary key,
first_name text,
last_name text,
email text,
Expand All @@ -41,14 +41,14 @@ language text
```sql
create table purchases (
date date,
user_handle int,
sku int,
user_handle uuid,
sku uuid,
quantity int
);
```
```sql
create table products (
sku int,
sku uuid,
product text,
price money
);
Expand Down
6 changes: 5 additions & 1 deletion exercises/01-import-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

## 01.

Your goal is to bulk import CSV data into the users, purchases, and products tables. You will have to use the method shown in https://egghead.io/lessons/postgresql-bulk-insert-and-export-data-with-csv-files to complete this exercise.
Your goal is to bulk import CSV data into the users, purchases, and products tables.

You will find `[product-data.csv](./product-data.csv)`, `[purchases-data.csv](./purchases-data.csv)`, and `[user-data.csv](./user-data.csv)` in this exercise folder that you can use to import into the `users`, `purchases`, and `products` tables.

You will have to use the method shown in https://egghead.io/lessons/postgresql-bulk-insert-and-export-data-with-csv-files to complete this exercise.
2 changes: 2 additions & 0 deletions exercises/02-cast-int-to-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

## 01.

Often times when working with data, you'll have the right data but in the wrong format that you need for the task at hand. You'll need to learn how to convert from one datatype to another.

Your goal is to cast an integer into a string. Use both the long and shorthand methods of casting types. You will have to research the correct syntax yourself in order to complete this exercise.
2 changes: 1 addition & 1 deletion exercises/05-CTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ group by user_handle, sku;

## 02.

Your goal is to find the average quantity a single user is purchasing of each product. You will need to use the CTE that you defined in Part 1 to do so.
Your goal is to find the average quantity a single user is purchasing of each product instead of all of the users. You will need to re-use the CTE that you defined in Part 1 to do so.
4 changes: 2 additions & 2 deletions exercises/06-filter-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
Your goal is to return all female users in their 20's that have purchased more than 100 products. You will need to filter aggregate and row data.

## 02.
What other ways can you filter this data?
How could find demographic purchases the most of a single product?

The team wants you to do market research on a product. How could find which demographic purchases the most of a single product? (e.g. 18302880 | Pepper - Pablano | \$5.28)
4 changes: 2 additions & 2 deletions exercises/07-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $ drop table users;

```sql
$ create table users (
user_handle int Primary key,
user_handle uuid Primary key,
first_name text,
last_name text,
email text,
Expand All @@ -27,7 +27,7 @@ insert into users values ('1', 'Agustin', 'Gillingham', '[email protected]
Your goal is to guarantee that a payment is successfully processed. To do so, you will need to initiate a transaction that:
- checks if product is available
- inserts payment info into users table
- adds item to purchases table
- adds items to purchases table

If any of these actions fail, the transaction should be aborted.

Expand Down
2 changes: 1 addition & 1 deletion exercises/purchases-data.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
date,id,sku,quantity
date,user_handle,sku,quantity
11/8/2019,79,18302861,6
3/30/2020,51,18302862,1
7/11/2019,75,18302863,3
Expand Down
10 changes: 10 additions & 0 deletions exercises/solutions/06-filter-data.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## 01
```sql
SELECT
u.user_handle,
Expand Down Expand Up @@ -28,4 +29,13 @@ user_handle | sum
2 | 146
36 | 126
93 | 110
```

## 02
```sql
postgres=# select email, users.user_handle, age, gender, sum(quantity) as total from users join purchases on (users.user_handle = purchases.user_handle) where sku=18302880 group by users.user_handle;
email | user_handle | age | gender | total
------------------------<del>-------------</del>-----<del>--------</del>--&#x2013;&#x2014;
[email protected] | 16 | 19 | Male | 12
(1 row)
```
2 changes: 1 addition & 1 deletion exercises/user-data.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id,first_name,last_name,email,gender,age,language
user_handle,first_name,last_name,email,gender,age,language
1,Ophelia,Claffey,[email protected],Female,40,Macedonian

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would the values change here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it changed above to uuid but remained an int

2,Marta,Brokenbrow,[email protected],Female,23,Somali
3,Barney,Grenshields,[email protected],Male,66,Thai
Expand Down