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
6 changes: 4 additions & 2 deletions 02_activities/assignments/Assignment1.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ Link if you encounter a paywall: https://web.archive.org/web/20240422105834/http

Consider, for example, concepts of fariness, inequality, social structures, marginalization, intersection of technology and society, etc.

I have encountered value systems embedded in subscription streaming site databases and data systems. Their systems assume that their subscribers have a traditional ‘nuclear’ family where all members live under one roof. However, for individuals with non-traditional family structures—such as separated families who are legally one family but live in different households—these systems block access to the service for members outside the main household. This is not fair to separated families as it doesn’t take into account families with non-traditional living arrangements and fails to recognize the diversity of modern family structures. Instead, it prioritizes corporate profit over inclusivity and fairness.

Another example of databases that I utilize on a daily basis are healthcare and identification databases. These databases value decentralized, siloed data management over efficiency and innovation. For instance, healthcare databases in Ontario are not synchronized between family doctors, hospitals, telehealth hotlines and pharmacies. This system disproportionally affects individuals with complex medical conditions, further delaying their treatment in a system that already struggles with delivering care efficiently. Furthermore, individuals without a family doctor are left to manage their own records, leading to inconsistencies in their care and poor outcomes. To improve their healthcare databases and take a more patient-centric approach, Ontario could mandate data-sharing across healthcare providers. Furthermore, the issue of database fragmentation extends to identification systems in Ontario and Canada, requiring a separate health card, driver’s license and passport. This system is inefficient and dated and could be improved by using an integrated digital identification system that could serve as a unified digital ID. This system would greatly increase efficiency and accessibility and reduce taxpayer costs. Overall, both the healthcare record and identification systems would benefit from upgrades the move the systems from decentralized data management to integrated data systems to improve efficiency, reduce cost, and reflect modern societal needs.


```
Your thoughts...
```
Binary file added 02_activities/assignments/SQL logical model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 77 additions & 7 deletions 02_activities/assignments/assignment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@

--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. */
-- option 1

SELECT *
FROM customer_purchases
WHERE product_id = 4 or product_id = 9;

-- option 2

Expand All @@ -27,10 +33,15 @@ filtered by vendor IDs between 8 and 10 (inclusive) using either:
2. one condition using BETWEEN
*/
-- option 1


SELECT *,
quantity * cost_to_customer_per_qty AS price
FROM customer_purchases
WHERE vendor_id >= 8 AND vendor_id <= 10;
-- option 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to provide another solution using BETWEEN.


SELECT *,
quantity * cost_to_customer_per_qty AS price
FROM customer_purchases
WHERE vendor_id BETWEEN 8 AND 10;


--CASE
Expand All @@ -39,18 +50,42 @@ 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.” */

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_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;

--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 *
FROM vendor
INNER JOIN vendor_booth_assignments
ON vendor.vendor_id = vendor_booth_assignments.vendor_id
ORDER BY vendor_name, market_date;



Expand All @@ -60,6 +95,12 @@ 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 (booth_number)
FROM vendor_booth_assignments
GROUP BY vendor_id



/* 2. The Farmer’s Market Customer Appreciation Committee wants to give a bumper
Expand All @@ -69,6 +110,16 @@ 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
*,
SUM(quantity * cost_to_customer_per_qty) AS total_cost
FROM customer cust
INNER JOIN customer_purchases custp
ON cust.customer_id = custp.customer_id
GROUP BY cust.customer_id
HAVING total_cost > 2000
ORDER BY cust.customer_last_name, cust.customer_first_name


--Temp Table
/* 1. Insert the original vendor table into a temp.new_vendor and then add a 10th vendor:
Expand All @@ -82,14 +133,25 @@ 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 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');


-- 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! */

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.
Expand All @@ -98,3 +160,11 @@ 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,
strftime ('%m', market_date) AS month,
strftime ('%Y', market_date) AS year,
SUM (quantity*cost_to_customer_per_qty) AS total_cost
FROM customer_purchases
WHERE strftime('%m', market_date) = '04' AND strftime('%Y', market_date) = '2022'
GROUP BY customer_id, month, year;