diff --git a/02_activities/assignments/DC_Cohort/Assignment-1_Section-1_ERD.png b/02_activities/assignments/DC_Cohort/Assignment-1_Section-1_ERD.png new file mode 100644 index 000000000..a9ff62600 Binary files /dev/null and b/02_activities/assignments/DC_Cohort/Assignment-1_Section-1_ERD.png differ diff --git a/02_activities/assignments/DC_Cohort/Assignment1.md b/02_activities/assignments/DC_Cohort/Assignment1.md index d5ff55ce4..d969dea0c 100644 --- a/02_activities/assignments/DC_Cohort/Assignment1.md +++ b/02_activities/assignments/DC_Cohort/Assignment1.md @@ -209,5 +209,9 @@ Consider, for example, concepts of fariness, inequality, social structures, marg ``` -Your thoughts... +One most recent example that I have encountered where value systems are embedded in data systems are essentially credit cards. To illustrate, when I applied for my American Express credit card this year, I had to fill in a bunch of different information on their portal. This information included my name, SIN, annual income, employment status, occupation, date of birth, and so on. American Express used all these details to determine my eligibility for the card and to calculate my credit limit within a matter of seconds. Due to my previous credit history from an older credit card and other factors, my application was approved pretty quickly. Critically, credit card companies value people who pay on time because these individuals are considered less risky financially (i.e., credit card companies can often lose money from someone who fails to repay their debts). Not only that, but the credit card company also gets a small charge fee from merchants whenever people use their card. In other words, these companies value people who use their card consistently as well. + +While my credit card application was rather smooth, this is not necessarily always the case for other people. There are some people that I know that cannot get a credit card because of an intersection of different factors (age, income, credit history, etc). For example, if someone has little to no credit history and low income, they are not seen as an ideal candidate. I argue that this isn’t fair because some people often live paycheck to paycheck and credit cards could be helpful for them as they wait for their next paycheck. A low income does not necessarily mean that someone will not pay on time. However, because of these algorithms set in place based on past historical data patterns, these people are often disadvantaged. + +I argue OSAP also has the similar problems embedded within its database/data system. When I was in undergrad, OSAP required the incomes of both your parents to determine your eligibility, whether you are given loans or grants, and how much. The application and loan/grant determination was relatively easy for me because my parents are still married. In contrast, my peers with divorced parents (or those who never married) had challenges with OSAP where they were given no money at all. For individuals with two parents who are no longer together, OSAP automatically assumes that both parents can support and contribute to your education. This is a flawed assumption because some people may be estranged from one (or even both) of their parents. OSAP also might not consider that a parent with sole custody may have a substantially lower income than the other parent and, thus, drive up the total parental income and reduce OSAP loan/grant amounts. Because of this, OSAP can unintentionally discriminate against someone who might really need OSAP to attend post-secondary school. ``` diff --git a/02_activities/assignments/DC_Cohort/assignment1.sql b/02_activities/assignments/DC_Cohort/assignment1.sql index a80923591..5b53d0213 100644 --- a/02_activities/assignments/DC_Cohort/assignment1.sql +++ b/02_activities/assignments/DC_Cohort/assignment1.sql @@ -6,20 +6,20 @@ --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, + customer_first_name +LIMIT 10; --END QUERY @@ -27,10 +27,10 @@ sorted by customer_last_name, then customer_first_ name. */ /* 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 = 4 OR product_id = 9 +LIMIT 25; --END QUERY @@ -42,10 +42,12 @@ filtered by customer IDs between 8 and 10 (inclusive) using either: 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 @@ -55,10 +57,15 @@ 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 @@ -66,10 +73,18 @@ if the product_qty_type is “unit,” and otherwise displays the word “bulk. 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 product_name LIKE '%pepper%' + THEN 1 + ELSE 0 + END AS pepper_flag +FROM product; --END QUERY @@ -78,10 +93,14 @@ 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 AS v +INNER JOIN vendor_booth_assignments AS vba +ON v.vendor_id = vba.vendor_id +ORDER BY + vba.market_date, + v.vendor_name +LIMIT 24; --END QUERY @@ -92,10 +111,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(booth_number) +FROM vendor_booth_assignments +GROUP BY vendor_id; --END QUERY @@ -105,10 +125,19 @@ 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 + c.customer_id, + SUM(cp.cost_per_quantity*cp.quantity) AS total, + c.customer_first_name, + c.customer_last_name +FROM customer AS c +LEFT JOIN customer_purchases AS cp +ON c.customer_id = cp.customer_id +GROUP BY c.customer_id +HAVING total > 2000 +ORDER BY + c.customer_last_name, + c.customer_first_name; --END QUERY @@ -124,10 +153,28 @@ When inserting the new vendor, you need to appropriately align the columns to be VALUES(col1,col2,col3,col4,col5) */ --QUERY 10 - - - - +-- STEP 1: Create a temp table called new_vendor from the vendor table (all columns) +CREATE TEMP TABLE new_vendor AS +SELECT * +FROM vendor; + +-- STEP 2: Using INSERT keyword, add a 10th record +INSERT INTO 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'); + +-- STEP 3: Check temp.new_vendor table to see if it inserted properly +SELECT * +FROM new_vendor; --END QUERY @@ -138,10 +185,12 @@ 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 @@ -152,8 +201,12 @@ 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, + strftime('%m', market_date) AS month, + strftime('%Y', market_date) AS year, + SUM(quantity*cost_per_quantity) AS total_money_spent +FROM customer_purchases +WHERE month = '04' AND year = '2022' +GROUP BY customer_id; --END QUERY