Skip to content

All Homeworks#1

Open
adithya28 wants to merge 18 commits intomainfrom
homework1
Open

All Homeworks#1
adithya28 wants to merge 18 commits intomainfrom
homework1

Conversation

@adithya28
Copy link
Owner

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

Establish relationship between 2 tables of the database. A crash course on SQL commands.
What did you learn from the changes you have made?

Learnt logical design of DB tables. learnt many SQL commands I didn't know existed.

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

well to store similar data, once could use a non-relational Database. I would use graph DBS these days as they offer a good balance between design complexity and performance.

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

None so far
How were these changes tested?

used draw.io to reference the relationship between tables. used DB Browser for SQLite to explore the tables and write queries.

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

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

@kaylielau
@dwz92

Copy link

@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.

HW1: 8/8

Copy link

@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:
WHERE Q2: FROM customer_purchases
8/8

Copy link

@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: incomplete 5/8
AGGREGATE Q2 use LEFT JOIN
DATE Q2 missing

Copy link

@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: 8/8
WINDOWED Q1
SELECT cp.*,
DENSE_RANK() OVER (PARTITION BY customer_id ORDER BY market_date) AS visit_number
FROM customer_purchases AS cp
ORDER BY customer_id, market_date

Copy link

@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 missing SELECT, FROM and WHERE statements
DELETE Q1 product_id = 7 not 33333
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

@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.

4 participants