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
20 changes: 13 additions & 7 deletions 02_activities/assignments/Assignment1.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily.

Checklist:
- [ ] Create a branch called `assignment-one`.
- [ ] Ensure that the repository is public.
- [ ] Review [the PR description guidelines](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md#guidelines-for-pull-request-descriptions) and adhere to them.
- [ ] Verify that the link is accessible in a private browser window.
- [x] Create a branch called `assignment-one`.
- [x] Ensure that the repository is public.
- [x] Review [the PR description guidelines](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md#guidelines-for-pull-request-descriptions) and adhere to them.
- [x] Verify that the link is accessible in a private browser window.

If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges.

Expand Down Expand Up @@ -99,6 +99,8 @@ A logical data model must contain:

Please do not pick the exact same tables that I have already diagrammed. For example, you shouldn't diagram the relationship between `product` and `product_category`, but you could diagram `product` and `customer_purchases`.

<img src="assignment1.drawio.png" width=500>

**HINTS**:
- You will need to use the Browse Data tab in the main window to figure out the relationship types.
- You can't diagram tables that don't share a common column
Expand Down Expand Up @@ -204,6 +206,10 @@ 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.


```
Your thoughts...
```

I have taught many courses at the University of Toronto in the Department of Mathematics and so I have had intimate familiarity with the various excel sheets used to record the grades of students. One key underlying assumption in all these gradebooks is that every student one name and it is of the form [Personal Name] + [Family Name] in that order. An assumption which is simply not true for many people from non-Western countries.

Examples of names which do not match the format expected in a gradebook would be names in the reverse order of Western names; students who only have a Personal name; or, most frustratingly of all, students who have more than one name. Indeed, many Asian students will adopt a Western name in addition to their original name while they study at the University of Toronto. While this is not an issue for most students with two names, some of them will inconsistently use both for academic and administrative purposes. In the presence of student IDs, this is not necessarily system breaking since these allow us to uniquely assign a number to each student. However, some graded works can mistakenly not get a student ID associated to them, leading to truly frustrating nights trying to figure out what mark to assign to a given student.

My approach to dealing with this has been to attempt to record all the names associated to each student on my gradebooks. I say attempt, because this can be quite difficult to find out without going around to every student and saying “what’s your REAL name?” I don’t think this is particularly culturally sensitive so I generally just accumulate names as I go whenever there is some ambiguity. This of course only (partially) solves the non-uniqueness problem, but does nothing for the opposite order problem. It has been quite rare and I feel like I’m pretty good at knowing the difference between a first name and a last name for the most part. I shudder to think of a day when this becomes an issue.

Binary file added 02_activities/assignments/assignment1.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions 02_activities/assignments/assignment1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@
--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 @@ -31,27 +42,61 @@ filtered by vendor IDs between 8 and 10 (inclusive) using either:

-- option 2

SELECT *
,quantity*cost_to_customer_per_qty as 'price'

FROM customer_purchases
WHERE vendor_id BETWEEN 8 and 10;

--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.” */

SELECT
product_id
,product_name
,

CASE WHEN product_qty_type is '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 is '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 v
INNER JOIN vendor_booth_assignments vba
on v.vendor_id = vba.vendor_id
ORDER by vendor_name, market_date;


/* SECTION 3 */
Expand All @@ -60,15 +105,29 @@ 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
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. */

SELECT
customer_first_name
,customer_last_name
,sum(quantity*cost_to_customer_per_qty) as total_cost

from customer c
INNER JOIN customer_purchases cp
on c.customer_id = cp.customer_id
GROUP by c.customer_id
HAVING total_cost >= 2000
ORDER by customer_last_name,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,19 +141,49 @@ When inserting the new vendor, you need to appropriately align the columns to be
VALUES(col1,col2,col3,col4,col5)
*/

drop table if exists new_vendor;

CREATE temp TABLE new_vendor as
SELECT *

from vendor;


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

SELECT *
FROM new_vendor

ORDER by vendor_id;

-- 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('%Y',market_date) as year
,strftime('%m',market_date) as month


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

SELECT customer_id

,strftime('%Y',market_date) as year
,strftime('%m',market_date) as month
,sum(quantity*cost_to_customer_per_qty) as total_cost

FROM customer_purchases
WHERE strftime('%Y-%m',market_date) = '2022-04'
group by customer_id
ORDER by customer_id;
Binary file added 05_src/sql/farmersmarket.db-journal
Binary file not shown.