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


```
Your thoughts...
As I read the article, I realized that I have encountered friction when interacting with databases. It makes sense that
databases are encoded in ways that reflect a society's values and ways of living, which means that those who most conform to
society's rules receive easiest access to services by virtue of fitting into the right categories. Those who don't fit into
predefined and accepted categories face greater friction when trying to access such services. While I am fortunate enough to
not face very serious issues (like being denied access to identification, for example), databases have still caused some problems in my day-to-day life.

My full legal name, which includes my Chinese name, has caused friction in the past when I tried to create profiles and
accounts with institutions like schools and credit agencies etc. In the Western world, naming conventions commonly include
categories of "first name" and "last name" (and sometimes "middle name"). It seems to be assumed that each name is a single
word, that is, a string without spaces. Unfortunately, my first name contains 3 separate 'words' (with my English name coming
last). As a result, I appear in many institutional databases simply under my last name and the the first character (the first
'word') of my Chinese name, even when I try to input my full name when creating my profile. Unfortunately, it is also common
for Chinese families to follow a pattern in naming their children and I share the first character of my Chinese name with my
sister, whose name faces similar treatment in various databases. As such, it seems that my sister and I are barely
distinguishable from each other as legal and financial entities.

Western naming conventions are assumptions that have been encoded into databases, and though this seems like a minor issue, it
can lead to major problems. In my case, the problem came to light when my sister and I attempted to rent an apartment together.
Because we shared the same address for the vast majority of our lives, our credit profiles were mixed/spliced together by
TransUnion, and all our individual financial accounts appeared under my name (or rather, the partial version of my name that
was stored in their database). According to TransUnion, my sister did not exist. Although we called them and attempted to fix
the problem by explaining that we two different individuals, in a country that relies so heavily on credit profiles and credit
scores to gain access to financial products like mortgages, this experience has remained a worry at the back of my mind. It has
shown to me how databases and their design can encode assumptions and values that results in individuals having
unequal access to government and financial services.

```
84 changes: 81 additions & 3 deletions 02_activities/assignments/DC_Cohort/assignment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
/* 1. Write a query that returns everything in the customer table. */
--QUERY 1


SELECT *
FROM customer


--END QUERY
Expand All @@ -17,7 +18,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
Expand All @@ -28,7 +32,11 @@ 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
Expand All @@ -43,6 +51,11 @@ Limit to 25 rows of output.
*/
--QUERY 4

SELECT *
, quantity * cost_to_customer_per_qty AS price
FROM customer_purchases
WHERE customer_id BETWEEN 8 AND 10
LIMIT 25



Expand All @@ -56,7 +69,13 @@ 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
Expand All @@ -67,6 +86,17 @@ 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



Expand All @@ -79,7 +109,18 @@ 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
vendor.vendor_id,
market_date,
vendor_name

FROM vendor

INNER JOIN vendor_booth_assignments
ON vendor_booth_assignments.vendor_id = vendor.vendor_id

ORDER BY market_date, vendor_name
LIMIT 24


--END QUERY
Expand All @@ -93,6 +134,10 @@ Limit to 24 rows of output. */
at the farmer’s market by counting the vendor booth assignments per vendor_id. */
--QUERY 8

SELECT vendor_id,
COUNT (vendor_id) AS times_booth_rented
FROM vendor_booth_assignments
GROUP BY vendor_id



Expand All @@ -105,6 +150,20 @@ 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_last_name
,customer_first_name
,c. customer_id
,SUM(quantity * cost_to_customer_per_qty) as total_spend


FROM customer AS c
INNER JOIN customer_purchases AS cp
ON cp.customer_id = c.customer_id

GROUP BY c.customer_id
HAVING total_spend > 2000
ORDER BY customer_last_name, customer_first_name



Expand All @@ -125,7 +184,16 @@ VALUES(col1,col2,col3,col4,col5)
*/
--QUERY 10

CREATE TABLE temp.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)
VALUES (10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas' , 'Rosenthal')


--END QUERY
Expand All @@ -139,6 +207,11 @@ and year are!
Limit to 25 rows of output. */
--QUERY 11

SELECT customer_id,
STRFTIME ('%m', market_date) as month_of_purchase,
STRFTIME ('%Y', market_date) AS year_of_purchase
FROM customer_purchases
LIMIT 25



Expand All @@ -153,7 +226,12 @@ 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,

SUM(quantity * cost_to_customer_per_qty) AS total_spend

FROM customer_purchases
WHERE STRFTIME ('%Y-%m', market_date) = '2022-04'
GROUP BY customer_id

--END QUERY
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.