Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3fe0023
Add Assignment 2 automated marking
danielrazavi Oct 9, 2026
28e6196
Accept alternative Q5 description column names
danielrazavi Oct 9, 2026
ab7519f
Test Assignment 2 with mixed correct and incorrect answers
danielrazavi Oct 9, 2026
f689001
Correct Q5 to verify grading reruns on updates
danielrazavi Oct 9, 2026
9d83169
Remind A2 students to enable GitHub Actions in their forks
danielrazavi Oct 9, 2026
72456c5
Merge pull request #481 from UofT-DSI/sql-automated-marking
Jiazhou-Bi Oct 13, 2026
21a9272
Clarify Assignment 2 output column names
danielrazavi Oct 15, 2026
e126332
Accept Q4 answers without optional purchase details
danielrazavi Oct 15, 2026
1e7d3d4
Allow descriptive query comments in assignment answers
danielrazavi Oct 15, 2026
a3cd528
Accept Q4 running counts that group same-day purchases
danielrazavi Oct 16, 2026
387711b
Accept Q3 latest visits without a displayed rank column
danielrazavi Oct 16, 2026
15be64b
Accept Q8 revenue aliases in any column position
danielrazavi Oct 16, 2026
97ea818
Support temporary product snapshots in Q9 through Q12
danielrazavi Oct 16, 2026
90aa43e
Bring latest autograder fixes into fork test branch
danielrazavi Oct 16, 2026
301107d
Exercise reviewer cases and collapsible grading feedback
danielrazavi Oct 16, 2026
4ba9a74
Test date-only Q4 running count after reviewer fixes
danielrazavi Oct 16, 2026
bb2e41b
Collapse SQL and output for correct assignment answers
danielrazavi Oct 20, 2026
18c75f8
Address Sergii's feedback: match result columns by values, not names
danielrazavi Oct 20, 2026
3bdda6d
Merge branch 'sql-automated-marking' of /Users/Dan/Documents/GitHub/s…
danielrazavi Oct 20, 2026
60fab85
Test arbitrary output aliases and column order across Q1 through Q8
danielrazavi Oct 20, 2026
c77b822
Verify renamed columns with wrong row relationships still fail
danielrazavi Oct 20, 2026
7ca2edf
Test an entirely incorrect Assignment 2 submission
danielrazavi Oct 20, 2026
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
10 changes: 8 additions & 2 deletions .github/workflows/sql_assignment_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ jobs:
let resultSection = `**Query ${result.number}: ${labels[result.status] || '⚪ Instructor review needed'}**\n\n`;
resultSection += `${result.feedback}\n\n`;
if (result.error) resultSection += fenced(result.error);
if (result.query) resultSection += fenced(result.query, 'sql');
if (result.result?.length) resultSection += fenced(JSON.stringify(result.result, null, 2), 'json');
let details = '';
if (result.query) details += fenced(result.query, 'sql');
if (result.result?.length) details += fenced(JSON.stringify(result.result, null, 2), 'json');
if (details && result.status === 'correct') {
resultSection += `<details>\n<summary>SQL and output</summary>\n\n${details}\n</details>\n\n`;
} else {
resultSection += details;
}
resultSection += '\n';
if (!appendSection(resultSection)) break reportLoop;
}
Expand Down
2 changes: 2 additions & 0 deletions 02_activities/assignments/DC_Cohort/Assignment2.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* 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:
- [ ] 🚨🚨🚨 After forking, open the **Actions** tab in your own SQL repository. If prompted, click **I understand my workflows, go ahead and enable them** before opening your assignment pull request. This enables automatic SQL feedback on your pull request.
- [ ] Create a branch called `assignment-two`.
- [ ] 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.
Expand Down Expand Up @@ -69,6 +70,7 @@ Steps to complete this part of the assignment:
- from [Github](./02_activities/assignments/assignment2.sql)
- or, from your local forked repository
- Complete each question, by writing responses between the QUERY # and END QUERY blocks
- Some questions build on your earlier queries or tables. Keep track of the column names you use so you can reference them correctly in later questions.


### Write SQL
Expand Down
178 changes: 13 additions & 165 deletions 02_activities/assignments/DC_Cohort/assignment2.sql
Original file line number Diff line number Diff line change
@@ -1,200 +1,48 @@
/* ASSIGNMENT 2 */
--Please write responses between the QUERY # and END QUERY blocks
/* SECTION 2 */

-- COALESCE
/* 1. Our favourite manager wants a detailed long list of products, but is afraid of tables!
We tell them, no problem! We can produce a list with all of the appropriate details.

Using the following syntax you create our super cool and not at all needy manager a list:

SELECT
product_name || ', ' || product_size|| ' (' || product_qty_type || ')'
FROM product


But wait! The product table has some bad data (a few NULL values).
Find the NULLs and then using COALESCE, replace the NULL with a blank for the first column with
nulls, and 'unit' for the second column with nulls.

**HINT**: keep the syntax the same, but edited the correct components with the string.
The `||` values concatenate the columns into strings.
Edit the appropriate columns -- you're making two edits -- and the NULL rows will be fixed.
All the other rows will remain the same. */
--QUERY 1




SELECT product_name FROM product;
--END QUERY


--Windowed Functions
/* 1. Write a query that selects from the customer_purchases table and numbers each customer’s
visits to the farmer’s market (labeling each market date with a different number).
Each customer’s first visit is labeled 1, second visit is labeled 2, etc.

You can either display all rows in the customer_purchases table, with the counter changing on
each new market date for each customer, or select only the unique market dates per customer
(without purchase details) and number those visits.
HINT: One of these approaches uses ROW_NUMBER() and one uses DENSE_RANK().
Filter the visits to dates before April 29, 2022. */
--QUERY 2




SELECT customer_id, market_date, 99 AS visit_number FROM customer_purchases;
--END QUERY


/* 2. Reverse the numbering of the query so each customer’s most recent visit is labeled 1,
then write another query that uses this one as a subquery (or temp table) and filters the results to
only the customer’s most recent visit.
HINT: Do not use the previous visit dates filter. */
--QUERY 3




SELECT customer_id, market_date, 99 AS visit_number FROM customer_purchases;
--END QUERY


/* 3. Using a COUNT() window function, include a value along with each row of the
customer_purchases table that indicates how many different times that customer has purchased that product_id.

You can make this a running count by including an ORDER BY within the PARTITION BY if desired.
Filter the visits to dates before April 29, 2022. */
--QUERY 4




SELECT *, 99 AS product_purchase_count FROM customer_purchases;
--END QUERY


-- String manipulations
/* 1. Some product names in the product table have descriptions like "Jar" or "Organic".
These are separated from the product name with a hyphen.
Create a column using SUBSTR (and a couple of other commands) that captures these, but is otherwise NULL.
Remove any trailing or leading whitespaces. Don't just use a case statement for each product!

| product_name | description |
|----------------------------|-------------|
| Habanero Peppers - Organic | Organic |

Hint: you might need to use INSTR(product_name,'-') to find the hyphens. INSTR will help split the column. */
--QUERY 5




SELECT product_name, NULL AS description FROM product;
--END QUERY


/* 2. Filter the query to show any product_size value that contain a number with REGEXP. */
--QUERY 6




SELECT * FROM product;
--END QUERY


-- UNION
/* 1. Using a UNION, write a query that displays the market dates with the highest and lowest total sales.

HINT: There are a possibly a few ways to do this query, but if you're struggling, try the following:
1) Create a CTE/Temp Table to find sales values grouped dates;
2) Create another CTE/Temp table with a rank windowed function on the previous query to create
"best day" and "worst day";
3) Query the second temp table twice, once for the best day, once for the worst day,
with a UNION binding them. */
--QUERY 7




SELECT market_date, 0 AS sales FROM customer_purchases GROUP BY market_date LIMIT 2;
--END QUERY



/* SECTION 3 */

-- Cross Join
/*1. Suppose every vendor in the `vendor_inventory` table had 5 of each of their products to sell to **every**
customer on record. How much money would each vendor make per product?
Show this by vendor_name and product name, rather than using the IDs.

HINT: Be sure you select only relevant columns and rows.
Remember, CROSS JOIN will explode your table rows, so CROSS JOIN should likely be a subquery.
Think a bit about the row counts: how many distinct vendors, product names are there (x)?
How many customers are there (y).
Before your final group by you should have the product of those two queries (x*y). */
--QUERY 8




SELECT vendor_name, product_name, 0 AS revenue FROM vendor CROSS JOIN product;
--END QUERY


-- INSERT
/*1. Create a new table "product_units".
This table will contain only products where the `product_qty_type = 'unit'`.
It should use all of the columns from the product table, as well as a new column for the `CURRENT_TIMESTAMP`.
Name the timestamp column `snapshot_timestamp`. */
--QUERY 9




CREATE TEMP TABLE product_units AS SELECT * FROM product;
--END QUERY


/*2. Using `INSERT`, add a new row to the product_units table (with an updated timestamp).
This can be any product you desire (e.g. add another record for Apple Pie). */
--QUERY 10




SELECT 1;
--END QUERY


-- DELETE
/* 1. Delete the older record for whatever product you added.

HINT: If you don't specify a WHERE clause, you are going to have a bad time.*/
--QUERY 11




DELETE FROM product_units WHERE 1 = 0;
--END QUERY


-- UPDATE
/* 1.We want to add the current_quantity to the product_units table.
First, add a new column, current_quantity to the table using the following syntax.

ALTER TABLE product_units
ADD current_quantity INT;

Then, using UPDATE, change the current_quantity equal to the last quantity value from the vendor_inventory details.

HINT: This one is pretty hard.
First, determine how to get the "last" quantity per product.
Second, coalesce null values to 0 (if you don't have null values, figure out how to rearrange your query so you do.)
Third, SET current_quantity = (...your select statement...), remembering that WHERE can only accommodate one column.
Finally, make sure you have a WHERE statement to update the right row,
you'll need to use product_units.product_id to refer to the correct row within the product_units table.
When you have all of these components, you can run the update statement. */
--QUERY 12




ALTER TABLE product_units ADD current_quantity INT;
UPDATE product_units SET current_quantity = -1;
--END QUERY



Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* 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:
- [ ] 🚨🚨🚨 After forking, open the **Actions** tab in your own SQL repository. If prompted, click **I understand my workflows, go ahead and enable them** before opening your assignment pull request. This enables automatic SQL feedback on your pull request.
- [ ] Create a branch called `assignment-two`.
- [ ] 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.
Expand Down Expand Up @@ -69,6 +70,7 @@ Steps to complete this part of the assignment:
- from [Github](./02_activities/assignments/assignment2.sql)
- or, from your local forked repository
- Complete each question, by writing responses between the QUERY # and END QUERY blocks
- Some questions build on your earlier queries or tables. Keep track of the column names you use so you can reference them correctly in later questions.


### Write SQL
Expand Down
Loading
Loading