Skip to content

Committing Homework#1

Open
gzuo wants to merge 6 commits intomainfrom
homework
Open

Committing Homework#1
gzuo wants to merge 6 commits intomainfrom
homework

Conversation

@gzuo
Copy link
Copy Markdown
Owner

@gzuo gzuo commented May 16, 2024

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

Changes for homework

What did you learn from the changes you have made?

SQL

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

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

How were these changes tested?

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

Checklist

  • I can confirm that my changes are working as intended

Copy link
Copy Markdown

@amanda-ng518 amanda-ng518 left a comment

Choose a reason for hiding this comment

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

Your HW1 is good, please create a separate commit for HW2

Copy link
Copy Markdown

@amanda-ng518 amanda-ng518 left a comment

Choose a reason for hiding this comment

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

HW2:
Join Q1 missing "AS"
7/8

@gzuo gzuo changed the title Commiting homework_1 and homework_2 Committing Homework May 18, 2024
@gzuo
Copy link
Copy Markdown
Owner Author

gzuo commented May 18, 2024

HW2: Join Q1 missing "AS" 7/8
@amanda-ng518
Hi Amanda,

The following is my answer for Join Q1. I'm not sure if I understand your comment about missing AS. Do you mean that I need a AS before the table alias 'v' and 'vba'? My understanding is that the AS keyword is optional when you specify an alias for a table (from https://www.w3schools.com/sql/sql_alias.asp). Would you mind clarifying?

--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 v.vendor_name, vba.market_date

@amanda-ng518
Copy link
Copy Markdown

HW2: new score 8/8, well done!
You are write, "AS" can be optional, sorry for the confusion

Copy link
Copy Markdown

@amanda-ng518 amanda-ng518 left a comment

Choose a reason for hiding this comment

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

HW3: good
AGGREGATE Q2 may use LEFT JOIN
8/8

Copy link
Copy Markdown

@amanda-ng518 amanda-ng518 left a comment

Choose a reason for hiding this comment

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

HW4:
UNION use RANK OVER
8/8

Copy link
Copy Markdown

@amanda-ng518 amanda-ng518 left a comment

Choose a reason for hiding this comment

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

HW5: 8/8
INSERT Q2
INSERT INTO product_units (product_id, product_name,
product_size, product_category_id, product_qty_type, snapshot_timestamp)
SELECT
product_id,
product_name,
product_size,
product_category_id,
product_qty_type,
CURRENT_TIMESTAMP
FROM product AS p
WHERE product_id = 7

DELETE Q1
WITH older_record AS
(SELECT product_id
,MIN(snapshot_timestamp) AS snapshot_timestamp
FROM product_units
WHERE product_id = 7)
DELETE FROM product_units
WHERE (product_id =
(SELECT product_id
FROM older_record
)
AND snapshot_timestamp =
(SELECT snapshot_timestamp
FROM older_record
))

UPDATE Q1
ALTER TABLE product_units
ADD current_quantity INT;
UPDATE product_units
SET current_quantity = (
SELECT current_quantity
FROM (
SELECT p.product_id, COALESCE(quantity,0) as current_quantity
FROM product_units p
LEFT JOIN (
SELECT *
,ROW_NUMBER() OVER( PARTITION BY vi.product_id ORDER BY market_date DESC) AS rn
FROM vendor_inventory vi
) vi ON p.product_id = vi.product_id
WHERE rn = 1
OR rn IS NULL
) p
WHERE product_units.product_id = p.product_id);

Copy link
Copy Markdown

@amanda-ng518 amanda-ng518 left a comment

Choose a reason for hiding this comment

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

HW6: 8/8

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