Skip to content
Closed
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
6 changes: 6 additions & 0 deletions 02_activities/assignments/DC_Cohort/Assignment2.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,10 @@ Consider, for example, concepts of labour, bias, LLM proliferation, moderating c

```
Your thoughts...
I think the key takeaway from this article is that AI and machine learning is driven by humans, and that will inevitably lead to a human bias. For some tasks such as training AI to fold a towel, the human labour involved won't produce issues for practice, but for something like the person subtree of ImageNet then it can pose a huge challenge. Sorting out bad actors in image identification databases reminds me of Wikipedia and how it is an open website that anybody can update information or misinformation with. Although it does take a lot of human labour to train the database, the product can still be used effectively if human bias can be accounted for. Wikipedia is for the most part a good resource. But it should still be used with context, triangulation, and nuance.

Adding onto human bias, I think that many people understand intuitively but not explicitly that AI or machine learning can seem neutral, but because humans train them and set their parameters they are not. For example if AI is used to summarize news based on articles with the most 'organic views' or other parameters, it may end up pushing narratives that are from a majority political viewpoint and exclude minority ones. To further problematize the issue, once an algorithm, is known certain actors may try to cheat the algorithm by optimizing certain parameters in a way that is beneficial towards them.

That being said I think there is a lot of room for AI to solve problems that are human-adjacent with low stakes, and that high stakes decisions should be very critically scrutinized. For example there are court cases of arrests made on individuals with facial recognition software. Like in the article I would be happy if a robot could fold all my laundry and clothes, but I definitely would not want arrests to be made based on software that is potentially flawed or error prone, at least without multiple humans checking the software's output.

```
74 changes: 69 additions & 5 deletions 02_activities/assignments/DC_Cohort/assignment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* 1. Write a query that returns everything in the customer table. */
--QUERY 1


SELECT * FROM customer;


--END QUERY
Expand All @@ -17,7 +17,9 @@
sorted by customer_last_name, then customer_first_ name. */
--QUERY 2


SELECT * FROM customer
ORDER BY customer_last_name, customer_first_name
LIMIT 10;


--END QUERY
Expand All @@ -28,6 +30,9 @@ sorted by customer_last_name, then customer_first_ name. */
Limit to 25 rows of output. */
--QUERY 3

SELECT * FROM customer_purchases
WHERE product_id = "1" OR product_id = "4"
LIMIT 25;



Expand All @@ -43,7 +48,10 @@ Limit to 25 rows of output.
*/
--QUERY 4


SELECT customer_id, quantity, cost_per_quantity, quantity * cost_per_quantity AS price
FROM customer_purchases
WHERE customer_id >= 8 AND customer_id <=10
LIMIT 25;


--END QUERY
Expand All @@ -56,6 +64,13 @@ columns and add a column called prod_qty_type_condensed that displays the word
if the product_qty_type is “unit,” and otherwise displays the word “bulk.” */
--QUERY 5

SELECT product_id, product_name,
CASE
WHEN product_qty_type = "unit" THEN "unit"
WHEN product_qty_type != "unit" THEN "bulk"

END AS product_qty_type_condensed
FROM product



Expand All @@ -67,6 +82,16 @@ add a column to the previous query called pepper_flag that outputs a 1 if the pr
contains the word “pepper” (regardless of capitalization), and otherwise outputs 0. */
--QUERY 6

SELECT product_id, product_name,
CASE
WHEN product_qty_type = "unit" THEN "unit"
WHEN product_qty_type != "unit" THEN "bulk"

END AS product_qty_type_condensed,
CASE
WHEN product_name LIKE '%pepper%' THEN "1" ELSE "0"
END AS pepper_flag
FROM product



Expand All @@ -79,6 +104,11 @@ vendor_id field they both have in common, and sorts the result by market_date, t
Limit to 24 rows of output. */
--QUERY 7

SELECT *
FROM vendor
INNER JOIN vendor_booth_assignments
ON vendor.vendor_id = vendor_booth_assignments.vendor_id
ORDER BY market_date, vendor_name;



Expand All @@ -93,7 +123,10 @@ Limit to 24 rows of output. */
at the farmer’s market by counting the vendor booth assignments per vendor_id. */
--QUERY 8


SELECT *,
COUNT(vendor_id)
FROM vendor_booth_assignments
GROUP BY vendor_id


--END QUERY
Expand All @@ -106,7 +139,14 @@ of customers for them to give stickers to, sorted by last name, then first name.
HINT: This query requires you to join two tables, use an aggregate function, and use the HAVING keyword. */
--QUERY 9


SELECT *,
SUM(cost_per_quantity * quantity) AS customer_total
FROM customer
INNER JOIN customer_purchases
ON customer.customer_id = customer_purchases.customer_id
GROUP BY customer.customer_id
HAVING SUM(cost_per_quantity * quantity)>2000
ORDER BY customer_last_name, customer_first_name;


--END QUERY
Expand All @@ -116,6 +156,8 @@ HINT: This query requires you to join two tables, use an aggregate function, and
/* 1. Insert the original vendor table into a temp.new_vendor and then add a 10th vendor:
Thomass Superfood Store, a Fresh Focused store, owned by Thomas Rosenthal



HINT: This is two total queries -- first create the table from the original, then insert the new 10th vendor.
When inserting the new vendor, you need to appropriately align the columns to be inserted
(there are five columns to be inserted, I've given you the details, but not the syntax)
Expand All @@ -126,7 +168,11 @@ VALUES(col1,col2,col3,col4,col5)
--QUERY 10


CREATE TEMP TABLE temp.new_vendor AS
SELECT * FROM vendor;

INSERT INTO temp.new_vendor
VALUES (10, "Thomass Superfood Store", "Fresh Focused Store","Thomas", "Rosenthal");

--END QUERY

Expand All @@ -139,7 +185,14 @@ and year are!
Limit to 25 rows of output. */
--QUERY 11

SELECT *,

strftime("%m", market_date) AS month,
strftime("%Y", market_date) AS year

FROM customer_purchases

LIMIT 25;


--END QUERY
Expand All @@ -153,6 +206,17 @@ but remember, STRFTIME returns a STRING for your WHERE statement...
AND be sure you remove the LIMIT from the previous query before aggregating!! */
--QUERY 12

SELECT *,

strftime("%m", market_date) AS month,
strftime("%Y", market_date) AS year,
SUM(cost_per_quantity * quantity) AS customer_total

FROM customer_purchases
WHERE strftime("%m", market_date)= "03" AND strftime("%Y", market_date) = "2023"
GROUP BY customer_id

LIMIT 25;



Expand Down
95 changes: 92 additions & 3 deletions 02_activities/assignments/DC_Cohort/assignment2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ 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. */
--QUERY 1
SELECT
product_name || ', ' || COALESCE(product_size, '')|| ' (' || COALESCE(product_qty_type, 'unit') || ')'
FROM product



Expand All @@ -40,8 +43,11 @@ each new market date for each customer, or select only the unique market dates p
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,
ROW_NUMBER() OVER (PARTITION BY customer_id) AS visit
FROM customer_purchases
WHERE market_date < '2022-04-29'
ORDER BY customer_id


--END QUERY
Expand All @@ -52,6 +58,15 @@ then write another query that uses this one as a subquery (or temp table) and fi
only the customer’s most recent visit.
HINT: Do not use the previous visit dates filter. */
--QUERY 3
SELECT customer_id, market_date,
FROM (
SELECT customer_id, market_date,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY market_date DESC) AS visit
FROM customer_purchases
ORDER BY customer_id )

WHERE visit = 1




Expand All @@ -66,6 +81,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 product_id, customer_id,
COUNT(product_id)
FROM customer_purchases
WHERE market_date > '2022-03-29'
GROUP BY product_id, customer_id



Expand All @@ -84,7 +104,12 @@ 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,
CASE
WHEN INSTR(product_name, '-') <> 0 THEN 'yes'
ELSE NULL
END AS hyphen_indicator
FROM product;



Expand All @@ -94,6 +119,9 @@ 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_name, product_size
FROM product
WHERE product_size REGEXP '[0-9]'



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

CREATE TEMP TABLE highest_price AS
SELECT market_date,
SUM (quantity*cost_per_quantity) AS price

FROM customer_purchases
GROUP BY market_date
ORDER BY price DESC
LIMIT 1;

CREATE TEMP TABLE lowest_price AS
SELECT market_date,
SUM (quantity*cost_per_quantity) AS price

FROM customer_purchases
GROUP BY market_date
ORDER BY price ASC
LIMIT 1;

SELECT * FROM highest_price
UNION ALL
SELECT * FROM lowest_Price



Expand All @@ -132,7 +181,27 @@ How many customers are there (y).
Before your final group by you should have the product of those two queries (x*y). */
--QUERY 8

DROP TABLE IF EXISTS total_sales;

CREATE TEMPORARY TABLE total_sales AS
SELECT vendor_id, product_id, customer_id,
SUM(original_price * 5) AS saleof5


FROM (
SELECT v.vendor_id, v.original_price, v.product_id, c.customer_id
FROM (SELECT vendor_id, original_price, product_id FROM vendor_inventory) AS v
CROSS JOIN (SELECT customer_id FROM customer) AS c
GROUP BY v.vendor_id, v.original_price, v.product_id, c.customer_id
)
GROUP BY vendor_id, product_id;

SELECT vendor_name, product_name, saleof5
FROM total_sales
INNER JOIN product AS p
ON total_sales.product_id = p.product_id
INNER JOIN vendor as v
ON total_sales.vendor_id = v.vendor_id


--END QUERY
Expand All @@ -145,7 +214,13 @@ 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

DROP TABLE IF EXISTS product_units;

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


--END QUERY
Expand All @@ -155,6 +230,7 @@ Name the timestamp column `snapshot_timestamp`. */
This can be any product you desire (e.g. add another record for Apple Pie). */
--QUERY 10

INSERT INTO product_units VALUES (99, 'Pears', 'medium', 99, 'unit', CURRENT_TIMESTAMP)



Expand All @@ -167,6 +243,7 @@ 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 = 99



Expand All @@ -191,7 +268,19 @@ Finally, make sure you have a WHERE statement to update the right row,
When you have all of these components, you can run the update statement. */
--QUERY 12

UPDATE product_units
SET current_quantity = COALESCE(current_quantity, '');

UPDATE product_units
SET current_quantity = v.quantity

FROM
( SELECT market_date, quantity, product_id, vendor_id
FROM vendor_inventory
GROUP BY product_id
ORDER BY market_date DESC) AS v

WHERE v.product_id = product_units.product_id;


--END QUERY
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading