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: 5 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,9 @@ Consider, for example, concepts of fariness, inequality, social structures, marg


```
Your thoughts...
Databases are designed by people regarding real-world objects. Therefore, within their design, they may reflect the values and assumptions that their designers have with respect to the world. When it becomes necessary for people to interact with these databases to carry out essential activities, then these values and assumptions can have consequences for people whose lives do not align with them.

Fortunately, most of the data systems in Canada that regular people interact with, at least in my experience, are designed very inclusively and fairly. The Canadian government goes to great lengths to do so, and most of the problems around databases are centred more so around efficiently updating them than problems around exclusionary social values. This reflects the high level of social development that Canada has achieved, and I believe that we are very lucky to live in such a unique country.

Rather than existing databases, it may be rather the lack of certain data that displays the value system embedded in the Canadian data ecosystem. Canada currently lacks a large-scale comprehensive micro-level panel survey of residents, which many other advanced economies have (such as the Panel Study of Income Dynamics run by the University of Michigan). This is likely due to the fact that organizing a large-scale repeating survey like this requires significant institutional coordination and investment. Canadian institutions, being relatively more risk-averse compared to those in peer countries, have so far avoided taking the steps necessary to establish such a project. Therefore, it is my belief that the Canadian data ecosystem would benefit greatly from a greater degree of entrepreneurial thinking and bold action.
```
115 changes: 71 additions & 44 deletions 02_activities/assignments/DC_Cohort/assignment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@
--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


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

--QUERY
SELECT *
FROM customer_purchases
WHERE product_id == 4 OR product_id == 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),
Expand All @@ -36,10 +39,10 @@ filtered by customer IDs between 8 and 10 (inclusive) using either:
Limit to 25 rows of output.
*/
--QUERY 3




SELECT *, (quantity * cost_to_customer_per_qty) AS price
FROM customer_purchases
WHERE customer_id BETWEEN 8 AND 10
LIMIT 25;
--END QUERY


Expand All @@ -49,21 +52,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 4




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 5




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


Expand All @@ -72,10 +87,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 6




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


Expand All @@ -86,10 +103,9 @@ 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 7




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


Expand All @@ -99,10 +115,13 @@ 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 8




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


Expand All @@ -118,10 +137,12 @@ When inserting the new vendor, you need to appropriately align the columns to be
VALUES(col1,col2,col3,col4,col5)
*/
--QUERY 9
CREATE TEMPORARY TABLE new_vendor AS
SELECT *
FROM vendor




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


Expand All @@ -132,10 +153,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 10




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


Expand All @@ -146,8 +169,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 11




SELECT
customer_id,
strftime('%m', market_date) AS month,
strftime('%Y', market_date) AS year,
SUM(quantity * cost_to_customer_per_qty) AS total_expenditure
FROM customer_purchases
WHERE strftime('%m', market_date) = '04' AND strftime('%Y', market_date) = '2022'
GROUP BY customer_id, year, month;
--END QUERY
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.