Skip to content

SQL module assignment 2 submission#2

Open
Cadherin wants to merge 1 commit intomainfrom
assignment-two
Open

SQL module assignment 2 submission#2
Cadherin wants to merge 1 commit intomainfrom
assignment-two

Conversation

@Cadherin
Copy link
Copy Markdown
Owner

@Cadherin Cadherin commented Apr 7, 2026

SQL - Assignment 2

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

Added code for assignment 2.

What did you learn from the changes you have made?

Store intermediary results in temp tables; perform subqueries; alter table by adding additional columns or updating values in a table; perform nested queries to extract insights that involved aggregation, ordering and ranking, etc.

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

For some questions, there are multiple approaches that achieve the same. For instance, instead of storing intermediary results into temp tables, some of the queries could be constructed differently but it would also make them a bit tougher to decipher at a later time. So I opted for using temp tables when I could.

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

N/A

How were these changes tested?

All queries were tested within SQLite.

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

N/A

Checklist

  • I can confirm that my changes are working as intended

Copy link
Copy Markdown

@anjali-deshpande-hub anjali-deshpande-hub left a comment

Choose a reason for hiding this comment

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

Excellent! 70/70

DROP TABLE IF EXISTS temp.recent_visit;
-- Make new temp table to store recent market visit date for each customer
CREATE TABLE temp.recent_visit AS
SELECT DISTINCT
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DISTINCT is not required here.




DELETE FROM product_units WHERE product_id = 24;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your query correctly filters by product ID condition. The requirement is to delete the older record for the whatever product you added. You can find the oldest record (e.g., using MIN(snapshot_timestamp)) and delete only that row.

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