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
23 changes: 6 additions & 17 deletions 02_activities/assignments/DC_Cohort/Assignment1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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. <br>
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.
111 changes: 100 additions & 11 deletions 02_activities/assignments/DC_Cohort/assignment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -23,30 +29,75 @@ 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
/* 1. Products can be sold by the individual unit or by bulk measures like lbs. or oz.
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;



Expand All @@ -55,15 +106,30 @@ 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
sticker to everyone who has ever spent more than $2000 at the market. Write a query that generates a list
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
Expand All @@ -77,15 +143,30 @@ 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
/*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
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.
Expand All @@ -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;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.