Skip to content

adding assign 2#2

Open
ecervinka wants to merge 2 commits intomainfrom
assignment-two
Open

adding assign 2#2
ecervinka wants to merge 2 commits intomainfrom
assignment-two

Conversation

@ecervinka
Copy link
Copy Markdown
Owner

@ecervinka ecervinka commented Apr 8, 2026

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

adding assignment 2

What did you learn from the changes you have made?

that I keep accidentally clicking Yes to All when the SQL save pop-up comes up and overwriting my entire file. So now I save a backup in a word doc as I go

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

maybe row_number for the window function question

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

lots of syntax issues, and second guessing myself so there's a lot of work-checking included/commented out

How were these changes tested?

running extra code and then commenting it out

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

Checklist

  • I can confirm that my changes are working as intended YES

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.

Well done so far. Could you also please add answer to Section 4 in the .md file?




SELECT DISTINCT -- unique values
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. The requirement is to filter before April 29, 2022. The WHERE clause should be market_date < '2022-04-29'


--subquery
FROM (
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.


FROM customer_purchases

WHERE market_date > '2022-04-29' --adding date filter
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good except the filter should be '<'


DELETE FROM product_units
--SELECT * FROM product_expanded -- can help you determine you are looking at the right rows before running a deletion
WHERE product_id = 100 ;
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 and uses a timestamp 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.

UPDATE product_units
SET current_quantity = COALESCE(

(SELECT quantity
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 gives syntax error because you cannot give a subquery inside COALESCE() function. The inner subquery can return multiple rows. You are also missing comma before 0 in the COALESCE call.

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