diff --git a/02_activities/assignments/DC_Cohort/Assignment1.md b/02_activities/assignments/DC_Cohort/Assignment1.md index f78778f5b..4e57ab8d0 100644 --- a/02_activities/assignments/DC_Cohort/Assignment1.md +++ b/02_activities/assignments/DC_Cohort/Assignment1.md @@ -197,7 +197,7 @@ Steps to complete this part of the assignment: Read: Qadri, R. (2021, November 11). _When Databases Get to Define Family._ Wired.
https://www.wired.com/story/pakistan-digital-database-family-design/ -Link if you encounter a paywall: https://archive.is/srKHV or https://web.archive.org/web/20240422105834/https://www.wired.com/story/pakistan-digital-database-family-design/ +Link if you encounter a paywall: https://web.archive.org/web/20240422105834/https://www.wired.com/story/pakistan-digital-database-family-design/ **What values systems are embedded in databases and data systems you encounter in your day-to-day life?** @@ -205,5 +205,9 @@ Consider, for example, concepts of fariness, inequality, social structures, marg ``` -Your thoughts... +The Question: What values systems are embedded in databases and data systems you encounter in your day-to-day life? + +Consider, for example, concepts of fariness, inequality, social structures, marginalization, intersection of technology and society, etc. + +For me personally, the story of Riz is very touching, because there are notions and aspect of database that don't always capture the nuance ideas of identity, especially hidden identities. For example, in my day-to-day life, I have friends that do not necessarily belong to the "0" or "1" distinctions of "Male" and "female." Coming from China, where this is the only distinction, data and the way it is encoded into databases can be discriminatory and marginalize certain groups, in this case, the non-binary community. Similarly, for citing relatinoship status, if you ever complete tax filings for the government of Canada, they don't have a large assortment of options to encode into the national registry (i.e., Widow, single, divorced etc.). If anything that I have learned from this article, it is that data and the way data is structured can marginalize many minority groups without intentionally doing so. I can't say for sure what specific value systems are embedded -as making a blanket statement would not be suiting. However, there are definitely values and perspectives that are not considered. One question I might have is how can we engage the public/stakeholders when building these databases and registries and systems ? ``` diff --git a/02_activities/assignments/DC_Cohort/Assignment_one_model.pdf b/02_activities/assignments/DC_Cohort/Assignment_one_model.pdf new file mode 100644 index 000000000..e1e1a3153 Binary files /dev/null and b/02_activities/assignments/DC_Cohort/Assignment_one_model.pdf differ diff --git a/02_activities/assignments/DC_Cohort/assignment1.sql b/02_activities/assignments/DC_Cohort/assignment1.sql index c992e3205..bbad4a916 100644 --- a/02_activities/assignments/DC_Cohort/assignment1.sql +++ b/02_activities/assignments/DC_Cohort/assignment1.sql @@ -4,17 +4,21 @@ --SELECT /* 1. Write a query that returns everything in the customer table. */ - +SELECT* +FROM customer; /* 2. Write a query that displays all of the columns and 10 rows from the cus- tomer table, sorted by customer_last_name, then customer_first_ name. */ - - +SELECT* +FROM customer +LIMIT 10; --WHERE /* 1. Write a query that returns all customer purchases of product IDs 4 and 9. */ - +SELECT* +FROM customer_purchases +WHERE product_id = 4 OR product_id = 9; /*2. Write a query that returns all customer purchases and a new calculated column 'price' (quantity * cost_to_customer_per_qty), @@ -23,10 +27,16 @@ filtered by customer IDs between 8 and 10 (inclusive) using either: 2. one condition using BETWEEN */ -- option 1 - +SELECT* +,quantity*cost_to_customer_per_qty AS price +FROM customer_purchases +WHERE customer_id > 7 AND customer_id < 11; -- option 2 - +SELECT* +,quantity*cost_to_customer_per_qty AS price +FROM customer_purchases +WHERE customer_id BETWEEN 8 AND 10; --CASE @@ -34,20 +44,41 @@ filtered by customer IDs between 8 and 10 (inclusive) using either: Using the product table, write a query that outputs the product_id and product_name columns and add a column called prod_qty_type_condensed that displays the word “unit” if the product_qty_type is “unit,” and otherwise displays the word “bulk.” */ - +SELECT product_id +,product_name +,CASE + WHEN product_size LIKE '%lbs%' + OR product_size LIKE '%oz%' THEN 'bulk' + ELSE 'unit' +END AS prod_qty_type_condensed +FROM product; /* 2. We want to flag all of the different types of pepper products that are sold at the market. add a column to the previous query called pepper_flag that outputs a 1 if the product_name contains the word “pepper” (regardless of capitalization), and otherwise outputs 0. */ - +SELECT product_id +,product_name +,CASE + WHEN product_size LIKE '%lbs%' + OR product_size LIKE '%oz%' THEN 'bulk' + ELSE 'unit' +END AS prod_qty_type_condensed +,CASE + WHEN product_name LIKE '%pepper%' THEN 1 + ELSE 0 +END AS pepper_flag +FROM product; --JOIN /* 1. Write a query that INNER JOINs the vendor table to the vendor_booth_assignments table on the vendor_id field they both have in common, and sorts the result by vendor_name, then market_date. */ - - +SELECT* +FROM vendor AS v +INNER JOIN vendor_booth_assignments AS b + ON v.vendor_id = b.vendor_id; +ORDER BY v.vendor_name, b.market_date; /* SECTION 3 */ @@ -55,7 +86,11 @@ vendor_id field they both have in common, and sorts the result by vendor_name, t -- AGGREGATE /* 1. Write a query that determines how many times each vendor has rented a booth at the farmer’s market by counting the vendor booth assignments per vendor_id. */ - +SELECT + vendor_id, + COUNT(*) AS times_rented +FROM vendor_booth_assignments +GROUP BY vendor_id; /* 2. The Farmer’s Market Customer Appreciation Committee wants to give a bumper @@ -63,8 +98,19 @@ sticker to everyone who has ever spent more than $2000 at the market. Write a qu 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. */ - - +SELECT customer.customer_first_name + ,customer.customer_last_name + ,SUM(customer_purchases.purchase_amount) AS total_spent +FROM customer +INNER JOIN customer_purchases + ON customer.customer_id = customer_purchases.customer_id +GROUP BY customer.customer_first_name + ,customer.customer_last_name +HAVING + SUM(customer_purchases.purchase_amount) > 2000 +ORDER BY + customer.customer_last_name, + customer.customer_first_name; --Temp Table /* 1. Insert the original vendor table into a temp.new_vendor and then add a 10th vendor: @@ -77,10 +123,16 @@ When inserting the new vendor, you need to appropriately align the columns to be -> To insert the new row use VALUES, specifying the value you want for each column: VALUES(col1,col2,col3,col4,col5) */ +CREATE TEMP TABLE temp.new_vendor AS +SELECT * +FROM vendor; --I could only run this once, or else it gave an error, but it works! :) + +INSERT INTO temp.new_vendor (vendor_id, vendor_name, vendor_type, vendor_owner_first_name, vendor_owner_last_name) --I think I needed this to specify which columns to insert right? +VALUES (10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas', 'Rosenthal'); --- Date +-- Date--Excused to finish from instructor /*1. Get the customer_id, month, and year (in separate columns) of every purchase in the customer_purchases table. HINT: you might need to search for strfrtime modifers sqlite on the web to know what the modifers for month @@ -93,4 +145,3 @@ Remember that money spent is quantity*cost_to_customer_per_qty. HINTS: you will need to AGGREGATE, GROUP BY, and filter... but remember, STRFTIME returns a STRING for your WHERE statement!! */ -