diff --git a/02_activities/assignments/DC_Cohort/Assignment1.md b/02_activities/assignments/DC_Cohort/Assignment1.md index f78778f5b..3944819ce 100644 --- a/02_activities/assignments/DC_Cohort/Assignment1.md +++ b/02_activities/assignments/DC_Cohort/Assignment1.md @@ -24,6 +24,7 @@ If you encounter any difficulties or have questions, please don't hesitate to re *** ## Section 1: + You can start this section following *session 1*. Steps to complete this part of the assignment: @@ -185,25 +186,13 @@ To insert the new row use VALUES, specifying the value you want for each column: *** -## Section 4: -You can start this section anytime. - -Steps to complete this part of the assignment: -- Read the article -- Write, within this markdown file, <1000 words. - -### Ethics - -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/ +## Section 4 – Ethics Reflection -**What values systems are embedded in databases and data systems you encounter in your day-to-day life?** +The article *“When Databases Get to Define Family”* looks at how ostensibly technical systems, like national identification or health databases, reflect and implement social and political values. For instance, Pakistan's national database, NADRA, is designed on assumptions of what constitutes a "family": a male head of household with dependants. This makes it hard for women, single parents, and non-traditional families to access services or assert relationships not conforming to this default. The database does not simply represent reality but creates it through the power of inclusion and exclusion. -Consider, for example, concepts of fariness, inequality, social structures, marginalization, intersection of technology and society, etc. +This example reminded me that databases are never neutral, whether in or out of health and social research. Every column name, data type, and rule expresses a judgment about what matters and who counts. For example, gender fields are often binary; addresses assume fixed housing; race and ethnicity categories reflect administrative convenience rather than lived experience in medical and population databases. These decisions may seem minor, but they can reproduce inequities and limit how people can represent themselves. +In my own work with health system and program data, I see parallel value systems embedded in datasets. Decisions about which outcomes are "valid," what counts as a patient encounter, or how pain is measured all reflect priorities set by institutions and policies. Unless we question them, such assumptions can get reproduced in data systems that, often unknowingly, may perpetuate structural inequities such as the under-representation of Indigenous communities or reinforcing gender stereotypes in health outcomes. -``` -Your thoughts... -``` +Ultimately, the article concluded that fairness in data systems starts with design. Ethical database work means involving diverse voices in defining data structures, documenting assumptions transparently, and recognizing the power dynamics of how the data are collected and linked. A responsible database should make inclusion a technical requirement, not an afterthought. diff --git a/02_activities/assignments/DC_Cohort/assignment1.sql b/02_activities/assignments/DC_Cohort/assignment1.sql index c992e3205..b1b2da741 100644 --- a/02_activities/assignments/DC_Cohort/assignment1.sql +++ b/02_activities/assignments/DC_Cohort/assignment1.sql @@ -4,17 +4,23 @@ --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 +ORDER BY customer_last_name, customer_first_name +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 IN (4, 9); /*2. Write a query that returns all customer purchases and a new calculated column 'price' (quantity * cost_to_customer_per_qty), @@ -23,10 +29,26 @@ filtered by customer IDs between 8 and 10 (inclusive) using either: 2. one condition using BETWEEN */ -- option 1 - +SELECT + customer_id, + product_id, + quantity, + cost_to_customer_per_qty, + (quantity * cost_to_customer_per_qty) AS price, + purchase_date +FROM customer_purchases +WHERE customer_id >= 8 AND customer_id <= 10; -- option 2 - +SELECT + customer_id, + product_id, + quantity, + cost_to_customer_per_qty, + (quantity * cost_to_customer_per_qty) AS price, + purchase_date +FROM customer_purchases +WHERE customer_id BETWEEN 8 AND 10; --CASE @@ -34,19 +56,48 @@ 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 LOWER(product_qty_type) = 'unit' THEN 'unit' + ELSE 'bulk' + 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 LOWER(product_qty_type) = 'unit' THEN 'unit' + ELSE 'bulk' + END AS prod_qty_type_condensed, + CASE + WHEN LOWER(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 + v.vendor_id, + v.vendor_name, + v.vendor_type, + v.vendor_owner_first_name, + v.vendor_owner_last_name, + vba.market_date, + vba.booth_number +FROM vendor AS v +INNER JOIN vendor_booth_assignments AS vba + ON v.vendor_id = vba.vendor_id +ORDER BY v.vendor_name, vba.market_date; @@ -55,7 +106,12 @@ 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 booth_rentals +FROM vendor_booth_assignments +GROUP BY vendor_id +ORDER BY vendor_id; /* 2. The Farmer’s Market Customer Appreciation Committee wants to give a bumper @@ -63,7 +119,17 @@ 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 + c.customer_id, + c.customer_last_name, + c.customer_first_name, + ROUND(SUM(cp.quantity * cp.cost_to_customer_per_qty), 2) AS total_spent +FROM customer AS c +JOIN customer_purchases AS cp + ON c.customer_id = cp.customer_id +GROUP BY c.customer_id, c.customer_last_name, c.customer_first_name +HAVING SUM(cp.quantity * cp.cost_to_customer_per_qty) > 2000 +ORDER BY c.customer_last_name, c.customer_first_name; --Temp Table @@ -77,7 +143,18 @@ 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) */ +-- 1) create the temp table from the original vendor +CREATE TEMP TABLE new_vendor AS +SELECT * FROM vendor; + +-- 2) insert a new row (align columns) +INSERT INTO temp.new_vendor + (vendor_id, vendor_name, vendor_type, vendor_owner_first_name, vendor_owner_last_name) +VALUES + (10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas', 'Rosenthal'); +-- (Optional) check it worked: +SELECT * FROM temp.new_vendor ORDER BY vendor_id; -- Date @@ -85,7 +162,11 @@ VALUES(col1,col2,col3,col4,col5) HINT: you might need to search for strfrtime modifers sqlite on the web to know what the modifers for month and year are! */ - +SELECT + customer_id, + STRFTIME('%m', purchase_date) AS month, + STRFTIME('%Y', purchase_date) AS year +FROM customer_purchases; /* 2. Using the previous query as a base, determine how much money each customer spent in April 2022. @@ -94,3 +175,11 @@ 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!! */ +SELECT + customer_id, + ROUND(SUM(quantity * cost_to_customer_per_qty), 2) AS total_spent_apr_2022 +FROM customer_purchases +WHERE STRFTIME('%Y', purchase_date) = '2022' + AND STRFTIME('%m', purchase_date) = '04' +GROUP BY customer_id +ORDER BY customer_id; \ No newline at end of file diff --git a/02_activities/assignments/DC_Cohort/logical_model.png b/02_activities/assignments/DC_Cohort/logical_model.png new file mode 100644 index 000000000..b8f64ad0d Binary files /dev/null and b/02_activities/assignments/DC_Cohort/logical_model.png differ