diff --git a/02_activities/assignments/DC_Cohort/Assignment1.md b/02_activities/assignments/DC_Cohort/Assignment1.md index d5ff55ce4..fdeb72937 100644 --- a/02_activities/assignments/DC_Cohort/Assignment1.md +++ b/02_activities/assignments/DC_Cohort/Assignment1.md @@ -210,4 +210,14 @@ Consider, for example, concepts of fariness, inequality, social structures, marg ``` Your thoughts... +One of the value systems that I encounter in my daily life is related to my PhD research, which focuses on cancer treatment. +Patient databases typically include basic personal information such as name and date of birth, along with health-related info including diagnosis, symptoms, and treatment protocol. +Currently, the main hospitals in downtown Toronto do not have a central system where the patient data is shared, and requires manual updating at each hospital if the patient is transferred or receiving treatments at different locations. +While the standalone systems can help address security and privacy concerns, from a database perspective, this system can introduce a lot of inconsistencies. +For example, if pathology uses a drop-down list of different markers, this list may not be the same between the hospital databases along with different naming conventions (eg. CD4 vs. CD-4). +In certain instances, the patient info may be very different if they went to Hospital 1 for treatment of Disease A, and then separately to Hospital 2 for Disease 2, as there can be no communication between the two treatments and thus no manual updating of the database occurs. +It’s important to have the full picture for informing treatment protocols, and inconsistencies in information/databases may affect this decision, especially if the visits are not disclosed by the patient. +Additionally, from a data analysis or study perspective, it may be difficult to compare between patient cohorts if the data is not consistent. +At a broader scale, this means that hospitals may be excluded from the data analysis or studies if there is not a rigorous recordkeeping/database system, which is more common in less developed areas. +Ultimately, this can lead to underrepresentation of these populations when developing treatments. ``` diff --git a/02_activities/assignments/DC_Cohort/assignment1.sql b/02_activities/assignments/DC_Cohort/assignment1.sql index a80923591..e19a2caa8 100644 --- a/02_activities/assignments/DC_Cohort/assignment1.sql +++ b/02_activities/assignments/DC_Cohort/assignment1.sql @@ -7,7 +7,8 @@ /* 1. Write a query that returns everything in the customer table. */ --QUERY 1 - +SELECT * +FROM customer; --END QUERY @@ -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 @@ -28,7 +32,10 @@ sorted by customer_last_name, then customer_first_ name. */ Limit to 25 rows of output. */ --QUERY 3 - +SELECT * +FROM customer_purchases +WHERE product_id in (4, 9) +LIMIT 25; --END QUERY @@ -43,7 +50,12 @@ 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 @@ -56,7 +68,15 @@ 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 @@ -67,7 +87,20 @@ 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; --END QUERY @@ -79,6 +112,15 @@ 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 + v.vendor_id, + vba.market_date, + v.vendor_name +FROM vendor as v +INNER JOIN vendor_booth_assignments as vba + ON v.vendor_id = vba.vendor_id +ORDER BY market_date, vendor_name +LIMIT 24; @@ -93,7 +135,9 @@ 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_rented +FROM vendor_booth_assignments +GROUP BY vendor_id; --END QUERY @@ -106,7 +150,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 + c.customer_id, + c.customer_first_name, + c.customer_last_name, + SUM(cp.quantity * cp.cost_per_quantity) AS total_spent +FROM customer AS c +INNER JOIN customer_purchases AS cp + ON c.customer_id = cp.customer_id +GROUP BY c.customer_id +HAVING SUM(cp.quantity * cp.cost_per_quantity) > 2000 +ORDER BY c.customer_last_name, c.customer_first_name; --END QUERY @@ -125,7 +179,12 @@ VALUES(col1,col2,col3,col4,col5) */ --QUERY 10 +CREATE TEMP TABLE new_vendor AS + SELECT * + FROM vendor AS v; +INSERT INTO new_vendor + VALUES(10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas', 'Rosenthal'); --END QUERY @@ -139,7 +198,12 @@ 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 @@ -153,7 +217,14 @@ 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 diff --git a/02_activities/assignments/DC_Cohort/conceptual_model.png b/02_activities/assignments/DC_Cohort/conceptual_model.png new file mode 100644 index 000000000..4209b822a Binary files /dev/null and b/02_activities/assignments/DC_Cohort/conceptual_model.png differ