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
Binary file modified 01_materials/slides/slides_03.pdf
Binary file not shown.
19 changes: 16 additions & 3 deletions 02_activities/assignments/DC_Cohort/Assignment1.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Steps to complete this part of the assignment:

#### WHERE
1. Write a query that returns all customer purchases of product IDs 4 and 9. Limit to 25 rows of output.
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:
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
2. one condition using BETWEEN <br>
Limit to 25 rows of output.
Expand Down Expand Up @@ -182,7 +182,7 @@ To insert the new row use VALUES, specifying the value you want for each column:

Limit to 25 rows of output.

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`.
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_per_quantity`.

**HINTS**: you will need to AGGREGATE, GROUP BY, and filter...but remember, STRFTIME returns a STRING for your WHERE statement...
AND be sure you remove the LIMIT from the previous query before aggregating!!
Expand All @@ -209,5 +209,18 @@ Consider, for example, concepts of fariness, inequality, social structures, marg


```
Your thoughts...
#

Rida Qadri’s article about Pakistan’s National Database and Registration Authority (NADRA) shows that databases are not just technical systems used to store information. They are also built based on decisions about what information matters and how people should be categorized. One thing that stood out to me was how NADRA’s database had a specific idea of what a family should look like. People had to fit into the relationships and categories that were already designed in the system. When someone’s real-life situation did not match those categories, the problem was not with the person’s information; the problem was that the database was not designed to represent their reality.

This made me realize that database design is not always neutral. The choices made when creating tables, fields, and relationships can reflect the values and assumptions of the people who build the system. For example, if a database only allows certain options for family relationships, gender, or legal status, it may unintentionally exclude people who do not fit those options. Once these choices become part of a system used by organizations or governments, they can affect people’s access to important services and opportunities.

I can see similar examples in everyday systems I interact with. Many forms I complete for school, banking, healthcare, or other services have fixed categories. For example, a form may ask for marital status, gender, or an emergency contact relationship using a limited list of choices. These categories are usually created to make data easier to organize, but they may not represent everyone’s situation. People who do not fit the available options may have to choose an inaccurate answer, leave information incomplete, or spend extra time explaining their circumstances.

The farmers market database we worked with in this course also shows how database structures involve decisions. For example, the `customer_purchases` table assumes that each purchase is connected to a specific customer through a `customer_id`. The `vendor_booth_assignments` table assumes a clear relationship between vendors, booths, and market dates. These choices make the database organized and useful, but they also represent decisions about how the real world is being modeled. Someone has to decide what information should be stored and how different parts of the data connect.

The biggest lesson I took from Qadri’s article is that the impact of a database is not only measured by whether it works technically. We also need to think about who is included, who might be left out, and whose experiences are not represented. A system can be efficient and still create problems if it is based on assumptions that do not apply to everyone.

As someone learning data science, this is something I want to keep in mind. Building databases and models is not only about writing correct queries or creating efficient systems. It is also about understanding that the way we organize data can influence real people. Even small design choices, like what categories exist in a table or what relationships are allowed, can have meaningful consequences.

```
127 changes: 78 additions & 49 deletions 02_activities/assignments/DC_Cohort/assignment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,45 @@
--SELECT
/* 1. Write a query that returns everything in the customer table. */
--QUERY 1




SELECT *
FROM customer;
--END QUERY


/* 2. Write a query that displays all of the columns and 10 rows from the customer table,
sorted by customer_last_name, then customer_first_ name. */
--QUERY 2




SELECT *
FROM customer
ORDER BY customer_last_name ASC, customer_first_name ASC
LIMIT 10;
--END QUERY


--WHERE
/* 1. Write a query that returns all customer purchases of product IDs 4 and 9.
Limit to 25 rows of output. */
--QUERY 3




SELECT *
FROM customer_purchases
WHERE product_id IN (4, 9)
LIMIT 25;
--END QUERY



/*2. Write a query that returns all customer purchases and a new calculated column 'price' (quantity * cost_to_customer_per_qty),
/*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
2. one condition using BETWEEN
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


Expand All @@ -55,21 +54,33 @@ Using the product table, write a query that outputs the product_id and product_n
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.” */
--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


/* 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. */
--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 LOWER(product_name) LIKE '%pepper%' THEN 1
ELSE 0
END AS pepper_flag
FROM product;
--END QUERY


Expand All @@ -78,10 +89,12 @@ contains the word “pepper” (regardless of capitalization), and otherwise out
vendor_id field they both have in common, and sorts the result by market_date, then vendor_name.
Limit to 24 rows of output. */
--QUERY 7




SELECT *
FROM vendor
INNER JOIN vendor_booth_assignments
ON vendor.vendor_id = vendor_booth_assignments.vendor_id
ORDER BY market_date ASC, vendor_name ASC
LIMIT 24;
--END QUERY


Expand All @@ -92,10 +105,11 @@ Limit to 24 rows of output. */
/* 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. */
--QUERY 8




SELECT
vendor_id,
COUNT(*) AS booth_rentals
FROM vendor_booth_assignments
GROUP BY vendor_id;
--END QUERY


Expand All @@ -105,10 +119,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. */
--QUERY 9




SELECT
customer.customer_id,
customer_first_name,
customer_last_name,
SUM(quantity * cost_per_quantity) AS total_spent
FROM customer
INNER JOIN customer_purchases
ON customer.customer_id = customer_purchases.customer_id
GROUP BY customer.customer_id
HAVING total_spent > 2000
ORDER BY customer_last_name ASC, customer_first_name ASC;
--END QUERY


Expand All @@ -124,10 +145,13 @@ When inserting the new vendor, you need to appropriately align the columns to be
VALUES(col1,col2,col3,col4,col5)
*/
--QUERY 10
CREATE TEMP TABLE new_vendor AS
SELECT *
FROM vendor;




INSERT INTO new_vendor
VALUES
(10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas', 'Rosenthal');
--END QUERY


Expand All @@ -138,22 +162,27 @@ HINT: you might need to search for strfrtime modifers sqlite on the web to know
and year are!
Limit to 25 rows of output. */
--QUERY 11




SELECT
customer_id,
STRFTIME('%m', market_date) AS month,
STRFTIME('%Y', market_date) AS year
FROM customer_purchases
LIMIT 25;
--END QUERY


/* 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.
Remember that money spent is quantity*cost_per_quantity.

HINTS: you will need to AGGREGATE, GROUP BY, and filter...
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_per_quantity) AS total_spent
FROM customer_purchases
WHERE STRFTIME('%m', market_date) = '04'
AND STRFTIME('%Y', market_date) = '2022'
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.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Steps to complete this part of the assignment:

#### WHERE
1. Write a query that returns all customer purchases of product IDs 4 and 9. Limit to 25 rows of output.
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:
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
2. one condition using BETWEEN <br>
Limit to 25 rows of output.
Expand Down Expand Up @@ -177,11 +177,11 @@ To insert the new row use VALUES, specifying the value you want for each column:
#### 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!
**HINT**: you might need to search for strfrtime modifiers sqlite on the web to know what the modifiers for month and year are!

Limit to 25 rows of output.

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`.
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_per_quantity`.

**HINTS**: you will need to AGGREGATE, GROUP BY, and filter...but remember, STRFTIME returns a STRING for your WHERE statement...
AND be sure you remove the LIMIT from the previous query before aggregating!!
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Limit to 25 rows of output. */



/*2. Write a query that returns all customer purchases and a new calculated column 'price' (quantity * cost_to_customer_per_qty),
/*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
2. one condition using BETWEEN
Expand Down Expand Up @@ -134,7 +134,7 @@ VALUES(col1,col2,col3,col4,col5)
-- 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
HINT: you might need to search for strfrtime modifiers sqlite on the web to know what the modifiers for month
and year are!
Limit to 25 rows of output. */
--QUERY 11
Expand All @@ -146,7 +146,7 @@ Limit to 25 rows of output. */


/* 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.
Remember that money spent is quantity*cost_per_quantity.

HINTS: you will need to AGGREGATE, GROUP BY, and filter...
but remember, STRFTIME returns a STRING for your WHERE statement...
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 04_this_cohort/custom_slides/markdown/imgs/03_subquery_where.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions 04_this_cohort/custom_slides/markdown/xaringan-themer.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/* Colors */
--text-color: #657b83;
--header-color: #dc322f;
--background-color: #000000;
--background-color: #d3d2d9;
--link-color: #b58900;
--text-bold-color: #d33682;
--code-highlight-color: #268bd2;
Expand All @@ -56,7 +56,7 @@
--title-slide-background-color: #000000;
--title-slide-text-color: #fdf6e3;
--header-background-color: #dc322f;
--header-background-text-color: #000000;
--header-background-text-color: #d3d2d9;
}

html {
Expand Down Expand Up @@ -190,7 +190,7 @@ th, td {
.remark-slide table:not(.table-unshaded) thead,
.remark-slide table:not(.table-unshaded) tfoot,
.remark-slide table:not(.table-unshaded) tr:nth-child(even) {
background: #2C2D26;
background: #000000;
}
table.dataTable tbody {
background-color: var(--background-color);
Expand All @@ -200,7 +200,7 @@ table.dataTable.display tbody tr.odd {
background-color: var(--background-color);
}
table.dataTable.display tbody tr.even {
background-color: #2C2D26;
background-color: #000000;
}
table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
background-color: rgba(255, 255, 255, 0.5);
Expand Down
Binary file modified 04_this_cohort/custom_slides/pdf/slides_03.pdf
Binary file not shown.
41 changes: 41 additions & 0 deletions 04_this_cohort/live_code/module_2/CASE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* MODULE 2 */
/* CASE */


SELECT *
/* 1. Add a CASE statement declaring which days vendors should come */
,CASE WHEN vendor_type = 'Fresh Focused' THEN 'Wednesday'
WHEN vendor_type = 'Eggs & Meats' THEN 'Thursday'
ELSE 'Saturday'
END as day_of_specialty

/* 2. Add another CASE statement for Pie Day */
,CASE WHEN vendor_name = "Annie's Pies" -- double quotes okay here
THEN 'Annie is the best'
END as pie_day


/* 3. Add another CASE statement with an ELSE clause to handle rows evaluating to False */
,CASE WHEN vendor_name LIKE '%pie%'
THEN 'Wednesday' -- this came first for Annie even though she sells Prepared Foods too
WHEN vendor_type = 'Prepared Foods'
THEN 'Thursday'
ELSE 'Friday'
END as pies_special_day


FROM vendor;

/* 4. Experiment with selecting a different column instead of just a string value */
SELECT *
,CASE WHEN cost_per_quantity < 1.00
THEN cost_per_quantity*5
ELSE cost_per_quantity
END as inflation

FROM customer_purchases




--------------------------------------------------------------------------------------------------------------------------------------------
Loading