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
Empty file.
16 changes: 9 additions & 7 deletions 02_activities/assignments/DC_Cohort/Assignment1.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily.

Checklist:
- [ ] Create a branch called `assignment-one`.
- [ ] Ensure that the repository is public.
- [ ] Review [the PR description guidelines](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md#guidelines-for-pull-request-descriptions) and adhere to them.
- [ ] Verify that the link is accessible in a private browser window.
- [ ] Create a branch called `assignment-one`.
- [ ] Ensure that the repository is public.
- [ ] Review [the PR description guidelines](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md#guidelines-for-pull-request-descriptions) and adhere to them.
- [ ] Verify that the link is accessible in a private browser window.

If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges.

Expand Down Expand Up @@ -204,6 +204,8 @@ 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.


```
Your thoughts...
```
What stayed with me most from the article is that database schemas are not neutral plumbing. They actively stipulate what counts as a “real” family. Validation rules that look tidy on paper can silently legislate social life, turning edge cases into errors and forcing people to contort their identities to fit a form. When basic rights hinge on passing those checks, technical choices become social choices.

Building on that, my core view is: data is logical, but people are complex. We rarely anticipate the full range of human arrangements when we design a “logical” structure. Once personhood is compressed into fields, the meaning of those fields—how institutions define “parent,” “guardian,” “spouse,” or even “gender”—drives the story the data can tell. Because different actors hold different definitions, the same reality can be recorded inconsistently, breeding confusion.

Many conclusions require multiple fields to cohere, and the absence of a single attribute can break an otherwise accurate narrative. That’s why i actually think data science is fundamentally social science, not just analysis. The data is telling a story, yet the story is always thicker than the schema allows. Static categories without time, multiplicity, or uncertainty flatten lives into yes/no boxes that mislead as much as they inform. If the goal is to let data carry richer truths, we need models that accommodate variance without treating it as failure. That means definitions that are explicit and revisitable, relationships that allow multiple roles over time, and humane exception paths that record context instead of faking compliance. Above all, it means recognizing that what we encode is never just storage—it is a claim about the world, and people live with its consequences.
93 changes: 83 additions & 10 deletions 02_activities/assignments/DC_Cohort/assignment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,80 @@
--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),
filtered by customer IDs between 8 and 10 (inclusive) using either:
1. two conditions using AND
2. one condition using BETWEEN
*/
-- option 1

SELECT *, quantity * cost_to_customer_per_qty as price
from customer_purchases
where customer_id >= 8 and customer_id <= 10;

-- option 2

SELECT *, 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
WHEN 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_name,
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
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;


/* SECTION 3 */
Expand All @@ -56,15 +87,28 @@ vendor_id field they both have in common, and sorts the result by vendor_name, t
/* 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

/* 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,
SUM(cp.quantity * cp.cost_to_customer_per_qty) 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 total_spent > 2000
ORDER BY c.customer_last_name, c.customer_first_name;

--Temp Table
/* 1. Insert the original vendor table into a temp.new_vendor and then add a 10th vendor:
Expand All @@ -78,6 +122,23 @@ When inserting the new vendor, you need to appropriately align the columns to be
VALUES(col1,col2,col3,col4,col5)
*/

DROP TABLE IF EXISTS temp.new_vendor;

CREATE TEMP TABLE new_vendor AS
SELECT *
FROM vendor;

INSERT INTO temp.new_vendor
(vendor_id, vendor_name, vendor_type, vendor_owner_first_name, vendor_owner_last_name)
SELECT
COALESCE(MAX(vendor_id), 0) + 1,
'Thomass Superfood Store',
'Fresh Focused',
'Thomas',
'Rosenthal'
FROM vendor;

SELECT * FROM temp.new_vendor;


-- Date
Expand All @@ -86,11 +147,23 @@ 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', 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 total_spent_april_2022
FROM customer_purchases
WHERE STRFTIME('%Y', market_date) = '2022'
AND STRFTIME('%m', market_date) = '04'
GROUP BY customer_id
ORDER BY total_spent_april_2022
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.