Skip to content
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
21 changes: 19 additions & 2 deletions 02_activities/assignments/DC_Cohort/Assignment2.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,24 @@ The store wants to keep customer addresses. Propose two architectures for the CU
**HINT:** search type 1 vs type 2 slowly changing dimensions.

```
Your answer...
type 1:
customer_address
-customer_id
-customer_address (New address insted of old address)
-city
-province
-customer_postal_code

type 2:
customer_address
-customer_id
-address_id
-customer_address
-city
-province
-customer_postal_code
-customer_address_date
When the customer changes their address, a new row is added and the old address is kept.
```

***
Expand Down Expand Up @@ -191,5 +208,5 @@ Consider, for example, concepts of labour, bias, LLM proliferation, moderating c


```
Your thoughts...
One important ethical issue in this article is the hidden human labor behind machine learning. Machine learning may seem automated, but the article shows that many important parts of these systems are created by people. For example, ImageNet was built using millions of images that had to be labeled by human workers. Many of these workers used Amazon Mechanical Truk and udentified images for very small amounts of money. This shows that important AI systems can depend on large amounts of human work that people may not see or recognize. Another ethical issue is human bias in training data. The people who create datasets make decisions about how objects and people should be categorized. These decisions can affect the machine learning systems that later use the data. The article discusses ImageNet Roulette, which demonstrated that some ImageNet categories for people could be strange, inaccurate or offensive.
```
61 changes: 50 additions & 11 deletions 02_activities/assignments/DC_Cohort/assignment2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Edit the appropriate columns -- you're making two edits -- and the NULL rows wil
All the other rows will remain the same. */
--QUERY 1


SELECT product_name || ',' ||
coalesce(product_size, '') || '(' || coalesce(product_qty_type, 'unit') || ')'
FROM product;


--END QUERY
Expand All @@ -41,6 +43,11 @@ HINT: One of these approaches uses ROW_NUMBER() and one uses DENSE_RANK().
Filter the visits to dates before April 29, 2022. */
--QUERY 2

SELECT customer_id, market_date, dense_rank() OVER(
PARTITION BY customer_id
ORDER BY market_date) as visit_number
FROM customer_purchases
WHERE market_date < '2022-04-29';



Expand All @@ -53,7 +60,13 @@ only the customer’s most recent visit.
HINT: Do not use the previous visit dates filter. */
--QUERY 3


SELECT * FROM (
SELECT customer_id, market_date, dense_rank() OVER (
PARTITION BY customer_id
ORDER BY market_date DESC) AS visit_number
FROM customer_purchases
)
WHERE visit_number = 1;


--END QUERY
Expand All @@ -66,7 +79,11 @@ You can make this a running count by including an ORDER BY within the PARTITION
Filter the visits to dates before April 29, 2022. */
--QUERY 4


SELECT *, count(*) OVER (
PARTITION BY customer_id, product_id
ORDER By market_date) AS purchase_count
FROM customer_purchases
WHERE market_date < '2022-04-29';


--END QUERY
Expand All @@ -85,7 +102,9 @@ Remove any trailing or leading whitespaces. Don't just use a case statement for
Hint: you might need to use INSTR(product_name,'-') to find the hyphens. INSTR will help split the column. */
--QUERY 5


SELECT product_name,
TRIM(substr(product_name, nullif(instr(product_name, '-'), 0) + 1)) AS description
FROM product;


--END QUERY
Expand All @@ -94,7 +113,8 @@ Hint: you might need to use INSTR(product_name,'-') to find the hyphens. INSTR w
/* 2. Filter the query to show any product_size value that contain a number with REGEXP. */
--QUERY 6


SELECT product_size FROM product
WHERE product_size REGEXP '[0-9]';


--END QUERY
Expand All @@ -111,7 +131,8 @@ HINT: There are a possibly a few ways to do this query, but if you're struggling
with a UNION binding them. */
--QUERY 7


SELECT market_date, sum(quantity * cost_per_quantity) AS total_sales FROM customer_purchases
GROUP BY market_date;


--END QUERY
Expand All @@ -131,7 +152,14 @@ Think a bit about the row counts: how many distinct vendors, product names are t
How many customers are there (y).
Before your final group by you should have the product of those two queries (x*y). */
--QUERY 8

SELECT v.vendor_name, p.product_name, count(c.customer_id) * 5 * vi.original_price AS total_amount
FROM vendor_inventory vi
JOIN vendor v
on vi.vendor_id = v.vendor_id
JOIN product p
on vi.product_id = p.product_id
CROSS JOIN customer c
GROUP BY v.vendor_name, p.product_name;



Expand All @@ -145,7 +173,10 @@ It should use all of the columns from the product table, as well as a new column
Name the timestamp column `snapshot_timestamp`. */
--QUERY 9


CREATE TABLE product_units AS
SELECT *, CURRENT_TIMESTAMP AS snapshot_timestamp
FROM product
WHERE product_qty_type = 'unit';


--END QUERY
Expand All @@ -154,7 +185,10 @@ Name the timestamp column `snapshot_timestamp`. */
/*2. Using `INSERT`, add a new row to the product_units table (with an updated timestamp).
This can be any product you desire (e.g. add another record for Apple Pie). */
--QUERY 10

INSERT INTO product_units
SELECT *, CURRENT_TIMESTAMP FROM product
WHERE product_qty_type = 'unit'
LIMIT 1;



Expand All @@ -167,7 +201,11 @@ This can be any product you desire (e.g. add another record for Apple Pie). */
HINT: If you don't specify a WHERE clause, you are going to have a bad time.*/
--QUERY 11


DELETE FROM product_units
WHERE product_id = 3
AND snapshot_timestamp = (SELECT min(snapshot_timestamp)
FROM product_units
WHERE product_id = 3);


--END QUERY
Expand All @@ -190,7 +228,8 @@ Finally, make sure you have a WHERE statement to update the right row,
you'll need to use product_units.product_id to refer to the correct row within the product_units table.
When you have all of these components, you can run the update statement. */
--QUERY 12

ALTER Table product_units
ADD current_quantity INT;



Expand Down
Loading
Loading