diff --git a/exercises/00-setup.md b/exercises/00-setup.md index 778255d..d768e0d 100644 --- a/exercises/00-setup.md +++ b/exercises/00-setup.md @@ -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, @@ -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 ); diff --git a/exercises/01-import-data.md b/exercises/01-import-data.md index 0763b62..aaf6d10 100644 --- a/exercises/01-import-data.md +++ b/exercises/01-import-data.md @@ -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. diff --git a/exercises/02-cast-int-to-string.md b/exercises/02-cast-int-to-string.md index f2e9b4c..4b5492d 100644 --- a/exercises/02-cast-int-to-string.md +++ b/exercises/02-cast-int-to-string.md @@ -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. \ No newline at end of file diff --git a/exercises/05-CTE.md b/exercises/05-CTE.md index 2baf11e..33c0193 100644 --- a/exercises/05-CTE.md +++ b/exercises/05-CTE.md @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/exercises/06-filter-data.md b/exercises/06-filter-data.md index 7b941ab..456b733 100644 --- a/exercises/06-filter-data.md +++ b/exercises/06-filter-data.md @@ -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? \ No newline at end of file + +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) \ No newline at end of file diff --git a/exercises/07-transactions.md b/exercises/07-transactions.md index 9ca9f09..90d8400 100644 --- a/exercises/07-transactions.md +++ b/exercises/07-transactions.md @@ -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, @@ -27,7 +27,7 @@ insert into users values ('1', 'Agustin', 'Gillingham', 'agillingham8@devhub.com 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. diff --git a/exercises/purchases-data.csv b/exercises/purchases-data.csv index 924ed89..55bfbbe 100644 --- a/exercises/purchases-data.csv +++ b/exercises/purchases-data.csv @@ -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 diff --git a/exercises/solutions/06-filter-data.md b/exercises/solutions/06-filter-data.md index 61e7c26..f070251 100644 --- a/exercises/solutions/06-filter-data.md +++ b/exercises/solutions/06-filter-data.md @@ -1,3 +1,4 @@ +## 01 ```sql SELECT u.user_handle, @@ -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 +----------------------------------------------------–— +atanslief@berkeley.edu | 16 | 19 | Male | 12 +(1 row) ``` \ No newline at end of file diff --git a/exercises/user-data.csv b/exercises/user-data.csv index ef65812..3d3fac2 100644 --- a/exercises/user-data.csv +++ b/exercises/user-data.csv @@ -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,oclaffey0@hostgator.com,Female,40,Macedonian 2,Marta,Brokenbrow,mbrokenbrow1@lulu.com,Female,23,Somali 3,Barney,Grenshields,bgrenshields2@ed.gov,Male,66,Thai