Skip to content

Commit 4f8f518

Browse files
authored
Update Assignment2.md
1 parent 11eb08f commit 4f8f518

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

02_activities/assignments/Assignment2.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,20 @@ Find the NULLs and then using COALESCE, replace the NULL with a blank for the fi
8686

8787
**HINT**: keep the syntax the same, but edited the correct components with the string. The `||` values concatenate the columns into strings. Edit the appropriate columns -- you're making two edits -- and the NULL rows will be fixed. All the other rows will remain the same.
8888

89+
<div align="center">-</div>
90+
8991
#### Windowed Functions
9092
1. Write a query that selects from the customer_purchases table and numbers each customer’s visits to the farmer’s market (labeling each market date with a different number). Each customer’s first visit is labeled 1, second visit is labeled 2, etc.
9193

9294
You can either display all rows in the customer_purchases table, with the counter changing on each new market date for each customer, or select only the unique market dates per customer (without purchase details) and number those visits.
95+
9396
**HINT**: One of these approaches uses ROW_NUMBER() and one uses DENSE_RANK().
9497

9598
2. Reverse the numbering of the query from a part so each customer’s most recent visit is labeled 1, then write another query that uses this one as a subquery (or temp table) and filters the results to only the customer’s most recent visit.
9699

97100
3. Using a COUNT() window function, include a value along with each row of the customer_purchases table that indicates how many different times that customer has purchased that product_id.
98101

102+
<div align="center">-</div>
99103

100104
#### String manipulations
101105
1. Some product names in the product table have descriptions like "Jar" or "Organic". These are separated from the product name with a hyphen. Create a column using SUBSTR (and a couple of other commands) that captures these, but is otherwise NULL. Remove any trailing or leading whitespaces. Don't just use a case statement for each product!
@@ -106,6 +110,8 @@ You can either display all rows in the customer_purchases table, with the counte
106110

107111
**HINT**: you might need to use INSTR(product_name,'-') to find the hyphens. INSTR will help split the column.
108112

113+
<div align="center">-</div>
114+
109115
#### UNION
110116
1. Using a UNION, write a query that displays the market dates with the highest and lowest total sales.
111117

@@ -129,18 +135,21 @@ Steps to complete this part of the assignment:
129135

130136
**HINT**: Be sure you select only relevant columns and rows. Remember, CROSS JOIN will explode your table rows, so CROSS JOIN should likely be a subquery. Think a bit about the row counts: how many distinct vendors, product names are there (x)? How many customers are there (y). Before your final group by you should have the product of those two queries (x\*y).
131137

138+
<div align="center">-</div>
132139

133140
#### INSERT
134141
1. Create a new table "product_units". This table will contain only products where the `product_qty_type = 'unit'`. It should use all of the columns from the product table, as well as a new column for the `CURRENT_TIMESTAMP`. Name the timestamp column `snapshot_timestamp`.
135142

136143
2. Using `INSERT`, add a new row to the product_unit table (with an updated timestamp). This can be any product you desire (e.g. add another record for Apple Pie).
137144

145+
<div align="center">-</div>
138146

139147
#### DELETE
140148
1. Delete the older record for the whatever product you added.
141149

142150
**HINT**: If you don't specify a WHERE clause, [you are going to have a bad time](https://imgflip.com/i/8iq872).
143151

152+
<div align="center">-</div>
144153

145154
#### UPDATE
146155
1. We want to add the current_quantity to the product_units table. First, add a new column, `current_quantity` to the table using the following syntax.

0 commit comments

Comments
 (0)