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
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# DC Assignment 1: Meet the farmersmarket.db and Basic SQL
# Assignment 1: Meet the farmersmarket.db and Basic SQL

🚨 **Please review our [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md)** 🚨 for detailed instructions on how to format, branch, and submit your work. Following these guidelines is crucial for your submissions to be evaluated correctly.

#### Submission Parameters:
* Submission Due Date: `March 31, 2026`
* Submission Due Date: `November 17, 2025`
* Weight: 30% of total grade
* The branch name for your repo should be: `assignment-one`
* What to submit for this assignment:
* This markdown (Assignment1.md) with written responses in Section 4
* One Entity-Relationship Diagram (preferably in a pdf, jpeg, png format).
* One .sql file
* What the pull request link should look like for this assignment: `https://github.com/<your_github_username>/sql/pulls/<pr_id>`
Expand Down Expand Up @@ -115,7 +114,7 @@ Steps to complete this part of the assignment:
- Open the assignment1.sql file in DB Browser for SQLite:
- from [Github](./02_activities/assignments/assignment1.sql)
- or, from your local forked repository
- Complete each question, by writing responses between the QUERY # and END QUERY blocks
- Complete each question

### Write SQL

Expand All @@ -126,11 +125,10 @@ Steps to complete this part of the assignment:
<div align="center">-</div>

#### WHERE
1. Write a query that returns all customer purchases of product IDs 4 and 9. Limit to 25 rows of output.
1. Write a query that returns all customer purchases of product IDs 4 and 9.
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:
1. two conditions using AND
2. one condition using BETWEEN
Limit to 25 rows of output.

<div align="center">-</div>

Expand All @@ -142,7 +140,7 @@ Limit to 25 rows of output.
<div align="center">-</div>

#### JOIN
1. Write a query that `INNER JOIN`s the `vendor` table to the `vendor_booth_assignments` table on the `vendor_id` field they both have in common, and sorts the result by `market_date` then `vendor_name`. Limit to 24 rows of output.
1. Write a query that `INNER JOIN`s 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`.

***

Expand All @@ -153,7 +151,7 @@ Steps to complete this part of the assignment:
- Open the assignment1.sql file in DB Browser for SQLite:
- from [Github](./02_activities/assignments/assignment1.sql)
- or, from your local forked repository
- Complete each question, by writing responses between the QUERY # and END QUERY blocks
- Complete each question

### Write SQL

Expand All @@ -180,34 +178,36 @@ To insert the new row use VALUES, specifying the value you want for each column:

**HINT**: you might need to search for strfrtime modifers sqlite on the web to know what the modifers 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`.

**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!!
**HINTS**: you will need to AGGREGATE, GROUP BY, and filter...but remember, STRFTIME returns a STRING for your WHERE statement!!




## Section 4: What values systems are embedded in databases and data systems you encounter in your day-to-day life?

I would suggest that the values that one encounters in databases and data systems in the quotidian are either unassuming/uncritical, and or naively determined. By the latter, I imply that most value systems, with their varying hermeneutical destinations, are not simply willed or agenticaly assumed, but rather possessive and deterministic. One does not chose which ideas or indexes to follow, one simply deploys oneself with these not in mind. One can read, on can study, however, behaviour tends not to follow the fantasies and the petulations, whether intellectual or political, that one may entertain. Rather, one is compelled to act with what is in engraved in what counts as the actions and the decisions that are actually relevant, that is those that are done in the horizon of fear and uncertainty. I believe, that what is considered as a "technical worker", those professionals in either the hard sciences or in the digital professions, such as as Computer Science or Data Science, are not nearly unaware of the unassuming values. More emphatically I deem that they are either untrained in carrying critical injunctions, and more affirmatively the shouldn't. To use an analogy to stress my point, a knife is a "piece" of technology. A good knife is defined by its ability to cut properly. One can use as knife to cut bread or to stab someone. The knife itself is not bad, it is good because it cuts and its stab. Stabbing is normatively negative and punishable. Therefore the function of the knife, as the function of database/data system, is contingent on the user, not the maker of the knife. A technical maker (the creator of the database as the creator of the knife) cannot "code" in a function into the knife, he or she can only strive to make it sharp. In that regard, whatever system of values is coded into the tool is naively determined. At the end of the day, the function of database/data system is determined by the barer, not by the maker. In that, whatever values are "embedded" in databases sufferer in their irrelevance, from the naiveté of their designer.














***

## Section 4:
You can start this section anytime.

Steps to complete this part of the assignment:
- Read the article
- Write, within this markdown file, between 250 and 1000 words. No additional citations/sources are required.

### Ethics

Read: Qadri, R. (2021, November 11). _When Databases Get to Define Family._ Wired. <br>
https://www.wired.com/story/pakistan-digital-database-family-design/

Link if you encounter a paywall: https://archive.is/srKHV or https://web.archive.org/web/20240422105834/https://www.wired.com/story/pakistan-digital-database-family-design/

**What values systems are embedded in databases and data systems you encounter in your day-to-day life?**

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


```
Your thoughts...
```
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,88 +1,91 @@
/* ASSIGNMENT 1 */
--Please write responses between the QUERY # and END QUERY blocks
/* ASSIGNMENT 1 */
/* SECTION 2 */


--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,
/* 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. */
--QUERY 2




--END QUERY
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.
Limit to 25 rows of output. */
--QUERY 3




--END QUERY

/* 1. Write a query that returns all customer purchases of product IDs 4 and 9. */
SELECT *
FROM customer_purchases
WHERE product_id IN (4, 9)
LIMIT 25;


/*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:
1. two conditions using AND
2. one condition using BETWEEN
Limit to 25 rows of output.
*/
--QUERY 4

-- option 1
SELECT *,
quantity * cost_to_customer_per_qty AS price
FROM customer_purchases
WHERE customer_id >= 8 AND customer_id <= 10
LIMIT 25;



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


--CASE
/* 1. Products can be sold by the individual unit or by bulk measures like lbs. or oz.
Using the product table, write a query that outputs the product_id and product_name
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




--END QUERY
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;


--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 market_date, then vendor_name.
Limit to 24 rows of output. */
--QUERY 7




--END QUERY
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 market_date, vendor_name
LIMIT 24;



Expand All @@ -91,25 +94,31 @@ Limit to 24 rows of output. */
-- AGGREGATE
/* 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




--END QUERY
SELECT
v.vendor_id,
v.vendor_name,
COUNT(*) AS booth_rental_count
FROM vendor v
INNER JOIN vendor_booth_assignments vba
ON v.vendor_id = vba.vendor_id
GROUP BY v.vendor_id, v.vendor_name;


/* 2. The Farmer’s Market Customer Appreciation Committee wants to give a bumper
sticker to everyone who has ever spent more than $2000 at the market. Write a query that generates a list
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




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


--Temp Table
Expand All @@ -123,37 +132,39 @@ When inserting the new vendor, you need to appropriately align the columns to be
-> To insert the new row use VALUES, specifying the value you want for each column:
VALUES(col1,col2,col3,col4,col5)
*/
--QUERY 10



CREATE TABLE new_vendor AS
SELECT *
FROM vendor;
SELECT * FROM new_vendor;
INSERT INTO new_vendor
VALUES (10, 'Thomass Superfood Store', 'Fresh Focused', 'Thomas', 'Rosenthal');

--END QUERY


-- 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!
Limit to 25 rows of output. */
--QUERY 11




--END QUERY
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.
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...
AND be sure you remove the LIMIT from the previous query before aggregating!! */
--QUERY 12

but remember, STRFTIME returns a STRING for your WHERE statement!! */
SELECT
customer_id,
SUM(quantity * cost_to_customer_per_qty) 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