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
8 changes: 7 additions & 1 deletion 02_activities/assignments/DC_Cohort/Assignment1.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,11 @@ Consider, for example, concepts of fariness, inequality, social structures, marg


```
Your thoughts...
As an Epidemiology student, I reguarly learn about or work with public health databases, and it’s obvious that they quietly imbed value systems about whose experiences matter and what differences are worth measuring.

A big one is gender. Many older (and even some current) surveys only allow “male” or “female,” with no room for trans, nonbinary, or Two-Spirit identities. This reflects a value judgment that only binary gender categories are worth tracking. When data is collected like that, it erases entire groups at the input stage. Later, when a researcher wants to ask, for example, whether access to care differs for trans patients, it’s impossible to answer because the system never allowed those patients to exist in the first place.

Race and ethnicity are similar. A lot of administrative health data in Canada uses overly broad “race” fields (if race is collected at all). Different communities get collapsed into one label, like grouping Black African and Black Caribbean together, or “South Asian” being treated as interchangeable for people who are Sri Lankan, Tamil, or Punjabi. That flattening encodes a belief that these groups experience the health system the same way, which is not true. On the flip side, many databases have stopped collecting race altogether and just store country of birth instead. That quietly assumes race and racism don’t matter for health, i.e., that a Canadian-born Black person and a Canadian-born white person will have similar exposures, risks, and outcomes because they’re both “Canadian-born.”

These design choices have real consequences. They make it harder to study inequities, which then makes it easier for institutions to say “there’s no evidence of a disparity.” The absence of data becomes an excuse to ignore structural problems.
```
Binary file not shown.
113 changes: 100 additions & 13 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 = 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),
Expand All @@ -26,35 +32,74 @@ filtered by customer IDs between 8 and 10 (inclusive) using either:


-- option 2


SELECT
product_id,
vendor_id,
market_date,
customer_id,
quantity,
cost_to_customer_per_qty,
transaction_time,
quantity*cost_to_customer_per_qty AS price
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 product_qty_type
WHEN '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 product_qty_type
WHEN 'unit' THEN 'unit'
ELSE 'bulk'
END AS prod_qty_type_condensed,
CASE
WHEN INSTR(LOWER(product_name), 'pepper') > 0 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
INNER JOIN vendor_booth_assignments
ON vendor.vendor_id = vendor_booth_assignments.vendor_id
ORDER BY vendor_name, market_date;

/* SECTION 3 */

-- 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_booth_assignments.vendor_id,
vendor.vendor_name,
COUNT(vendor_booth_assignments.vendor_id) AS NumberOfRentals
FROM vendor_booth_assignments
INNER JOIN vendor
ON vendor_booth_assignments.vendor_id = vendor.vendor_id
GROUP BY vendor_booth_assignments.vendor_id;



Expand All @@ -64,7 +109,17 @@ 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_purchases.customer_id,
customer.customer_last_name,
customer.customer_first_name,
SUM(customer_purchases.quantity*customer_purchases.cost_to_customer_per_qty) AS TotalSpent
FROM customer_purchases
INNER JOIN customer
ON customer_purchases.customer_id = customer.customer_id
GROUP BY customer_purchases.customer_id
HAVING TotalSpent > 2000
ORDER BY customer_last_name, customer_first_name;

--Temp Table
/* 1. Insert the original vendor table into a temp.new_vendor and then add a 10th vendor:
Expand All @@ -77,20 +132,52 @@ 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 TABLE temp.new_vendor AS
SELECT
vendor_id,
vendor_name,
vendor_type,
vendor_owner_first_name,
vendor_owner_last_name
FROM vendor;

INSERT INTO temp.new_vendor
(vendor_id, vendor_name, vendor_type, vendor_owner_first_name, vendor_owner_last_name)
VALUES
(
(SELECT COALESCE(MAX(vendor_id), 0) + 1 FROM temp.new_vendor),
'Thomass Superfood Store',
'Fresh Variety: Veggies & More',
'Thomas',
'Rosenthal'
);

-- 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', market_date) AS month,
strftime('%Y', market_date) AS year
FROM customer_purchases;

/* 2. Using the previous query as a base, determine how much money each customer spent in April 2022.
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,
SUM(quantity * cost_to_customer_per_qty) AS TotalSpent_Apr2022
FROM customer_purchases
WHERE
strftime('%Y', market_date) = '2022' AND
strftime('%m', market_date) = '04'
GROUP BY customer_id
ORDER BY TotalSpent_Apr2022 DESC;