Skip to content

UofT-DSI | SQL - Assignment 2#2

Open
abeerkhe wants to merge 3 commits intomainfrom
assignment-two
Open

UofT-DSI | SQL - Assignment 2#2
abeerkhe wants to merge 3 commits intomainfrom
assignment-two

Conversation

@abeerkhe
Copy link
Copy Markdown
Owner

@abeerkhe abeerkhe commented Aug 21, 2025

Late submission confirmed with Thomas on Sunday as I was sick over the weekend and at start of week.

What changes are you trying to make? (e.g. Adding or removing code, refactoring existing code, adding reports)

Adding my assignment.

What did you learn from the changes you have made?

Got familiar with window functions, modifying tables, unions, and cross joins.

Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?

I iterated a number of approaches for many of the problems, especially those with nested statements. I.e., to use CTEs, temporary tables, or sub-queries.

Were there any challenges? If so, what issue(s) did you face? How did you overcome it?

The Cross Join and final Delete problem were challenging. Conceptually simple, but executing the operations in the right order to get the correct result. It took a lot of iterations and almost 'unit testing' individual parts of the queries to ensure the output was accurate before pasting it into the larger query.

How were these changes tested?

Piecemeal by sub-query (and variations to test how functions would work to create a specific sub-query) before testing it altogether for the final submission.

A reference to a related issue in your repository (if applicable)

I initially pushed to the assignment-one repository, then branched assignment-two from main, and accidentally overwrote my entire local assignment at the final hour. Fortunately I the pull request to the assignment-one had all the code still accessible.

Checklist

  • [ x ] I can confirm that my changes are working as intended

confirmed with Thomas on Sunday as I was sick over
the weekend and at start of week.
Copy link
Copy Markdown

@monzchan monzchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagram look great!
you may have to answer prompt 3 (SCD type 1 and 2).
The script looks great! you are almost there :)

SELECT
customer_id,
product_id,
COUNT() OVER (PARTITION BY customer_id ORDER BY product_id) AS product_purchase_count,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COUNT()requires a column or . So, you may consider COUNT() OVER (PARTITION BY.......)

Copy link
Copy Markdown
Owner Author

@abeerkhe abeerkhe Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please elaborate on this feedback?

The script above has COUNT() with OVER (PARTITION BY customer_id ORDER BY product_id) so I'm a bit unclear on the suggestion.

Thank you. :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the unclarity. COUNT( ) may need to indicate a column like COUNT(*) instead of leaving it blank, to avoid error at SQL

(SELECT product_id
FROM product_units
WHERE product_name='Churros'
ORDER BY snapshot_timestamp ASC LIMIT 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fail in some SQL engines. ORDER BY and LIMIT inside IN are not allowed. Consider MIN(snapshot_timestamp)

Copy link
Copy Markdown

@monzchan monzchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagram look great!
you may have to answer prompt 3 (SCD type 1 and 2).
The script looks great! you are almost there :)

Copy link
Copy Markdown

@monzchan monzchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You nail it!! Excellent work!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants