diff --git a/02_activities/assignments/DC_Cohort/Assignment1.md b/02_activities/assignments/DC_Cohort/Assignment1.md index d5ff55ce4..b2e0e055e 100644 --- a/02_activities/assignments/DC_Cohort/Assignment1.md +++ b/02_activities/assignments/DC_Cohort/Assignment1.md @@ -106,6 +106,11 @@ Please do not pick the exact same tables that I have already diagrammed. For exa - - The column names can be found in a few spots (DB Schema window in the bottom right, the Database Structure tab in the main window by expanding each table entry, at the top of the Browse Data tab in the main window) + +My attempt: + +![logical_model.png](./images/logical_model.png) + *** ## Section 2: @@ -207,7 +212,14 @@ Link if you encounter a paywall: https://archive.is/srKHV or https://web.archive Consider, for example, concepts of fariness, inequality, social structures, marginalization, intersection of technology and society, etc. +My reponse: + +*In her article "When Databases Get to Define Family," Rida Qadri shows that databases aren't just neutral tools for storing data—they are built around social expectations, state morality, and institutional shortcuts. When tech teams design a system, their unexamined coding choices can create major real-world barriers for anyone who doesn't fit the "default" user profile. This is something I see happening in day-to-day life all the time.* + +*For instance, the Canadian healthcare data infrastructure completely privileges citizens and permanent residents over international students. During school breaks, we cannot use the student wellness center. When I get sick during school break and try to book an appointment online at a clinic in Ontario, the system usually requires a standard OHIP card number. But as an international student, my insurance is UHIP, which has a completely different ID format. Because the online database is only optimized for OHIP, it rejects my UHIP number as an invalid input and blocks me from booking. This tiny technical constraint makes getting medical care unfair and exhausting. Since the automated system doesn't work for me, I have to call clinics directly. When you're actively sick, the last thing you want to do is wait on the phone for hours or call back ten times just to get a human receptionist to do a manual override. We could also try walking into a clinic without an appointment, but you might wait for hours or get turned away entirely if they run out of slots. Going to the ER is an option, but that involves an entirely different, massive price tag. By treating non-standard insurance IDs as digital noise, the database schema makes off-campus healthcare less accessible for internationals.* + +*While the Canadian system excludes people by failing to recognize unusual profiles, data systems in China have the opposite problem: they track individual profiles all too well, forcing people into inescapable webs of family association. This reflects the traditional concept of Lianzuo (连坐), where a whole family faces the consequences of one person's actions. In the digital age, this collective punishment is automated.* + +*If one applies for a public sector or civil service job in China, they'd have to go through a political background check (政审). The relational databases seamlessly link your profile to your family tree. If a parent has a criminal record, the system flags it during the automated screening, and the applicant is immediately disqualified, regardless of their personal or professional merit. Similarly, the Supreme Court’s public database for "Dishonest Persons" (失信) automates financial blocks. If a parent is blacklisted for unpaid debts, the system flags their identity and automatically blocks their children from enrolling in private or international schools. In these systems, the database doesn't view you as an independent individual, but as an inseparable node tied to your family's record.* -``` -Your thoughts... -``` +*Ultimately, both the Canadian healthcare system and Chinese data tracking prove the article's point. Databases act as powerful societal gatekeepers. They don't just store information; they dictate who gets to navigate society smoothly and who gets pushed to the margins.* diff --git a/02_activities/assignments/DC_Cohort/assignment1.sql b/02_activities/assignments/DC_Cohort/assignment1.sql index a80923591..50c712e15 100644 --- a/02_activities/assignments/DC_Cohort/assignment1.sql +++ b/02_activities/assignments/DC_Cohort/assignment1.sql @@ -7,8 +7,7 @@ /* 1. Write a query that returns everything in the customer table. */ --QUERY 1 - - +SELECT * FROM customer; --END QUERY @@ -17,8 +16,10 @@ 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 @@ -28,13 +29,14 @@ sorted by customer_last_name, then customer_first_ name. */ Limit to 25 rows of output. */ --QUERY 3 - - +SELECT * +FROM customer_purchases +WHERE product_id = 4 OR product_id = 9 +LIMIT 25; --END QUERY - /*2. Write a query that returns all customer purchases and a new calculated column 'price' (quantity * cost_per_quantity), filtered by customer IDs between 8 and 10 (inclusive) using either: 1. two conditions using AND @@ -43,8 +45,10 @@ Limit to 25 rows of output. */ --QUERY 4 - - +SELECT *, quantity * cost_per_quantity AS price +FROM customer_purchases +WHERE customer_id BETWEEN 8 AND 10 +LIMIT 25; --END QUERY @@ -56,8 +60,12 @@ 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' + ELSE 'bulk' + END AS prod_qty_type_condensed +FROM product; --END QUERY @@ -67,8 +75,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' + ELSE 'bulk' + END AS prod_qty_type_condensed, + CASE + WHEN product_name LIKE '%pepper%' THEN 1 + ELSE 0 + END AS pepper_flag +FROM product; --END QUERY @@ -79,8 +95,12 @@ 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 * -- best practice is to specify the cols, since there might be cols from diff tables w same names +FROM vendor AS v +INNER JOIN vendor_booth_assignments AS vb -- can omit "inner" b/c it's the default join method +USING (vendor_id) -- ON v.vendor_id = vb.vendor_id -- keeps both vendor_id cols; USING deletes 1 ID col +ORDER BY market_date, vendor_name +LIMIT 24; --END QUERY @@ -93,8 +113,11 @@ Limit to 24 rows of output. */ at the farmer’s market by counting the vendor booth assignments per vendor_id. */ --QUERY 8 +SELECT * FROM vendor_booth_assignments; - +SELECT vendor_id, COUNT(booth_number) AS times_rented_booth +FROM vendor_booth_assignments +GROUP BY vendor_id; --END QUERY @@ -106,8 +129,15 @@ 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 + customer_id, + customer_last_name, + customer_first_name, + SUM(quantity * cost_per_quantity) AS total_spent +FROM customer_purchases LEFT JOIN customer USING(customer_id) +GROUP BY customer_id +HAVING total_spent > 2000 +ORDER BY customer_last_name, customer_first_name; --END QUERY @@ -125,8 +155,19 @@ VALUES(col1,col2,col3,col4,col5) */ --QUERY 10 +-- if a table named new_vendor_inventory exists, delete it, otherwise do nothing +DROP TABLE IF EXISTS temp.new_vendor; +-- create temp table +CREATE TABLE temp.new_vendor AS +SELECT * FROM vendor; +-- add new vendor +INSERT INTO temp.new_vendor +VALUES(10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas', 'Rosenthal'); + +-- check new temp table +SELECT * FROM temp.new_vendor; --END QUERY @@ -139,8 +180,13 @@ and year are! Limit to 25 rows of output. */ --QUERY 11 - - +SELECT + customer_id, + market_date, + strftime('%m', market_date) AS month, + strftime('%Y', market_date) AS year +FROM customer_purchases +LIMIT 25; --END QUERY @@ -153,7 +199,14 @@ 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 + customer_id, + market_date, + strftime('%m', market_date) AS month, + strftime('%Y', market_date) AS year, + SUM(quantity * cost_per_quantity) AS total_spent +FROM customer_purchases +WHERE month = '04' AND year = '2022' +GROUP BY customer_id; --END QUERY diff --git a/02_activities/assignments/DC_Cohort/images/logical_model.png b/02_activities/assignments/DC_Cohort/images/logical_model.png new file mode 100644 index 000000000..f5481407b Binary files /dev/null and b/02_activities/assignments/DC_Cohort/images/logical_model.png differ