Skip to content

Assignment two#2

Open
anna-utm wants to merge 5 commits intomainfrom
assignment-two
Open

Assignment two#2
anna-utm wants to merge 5 commits intomainfrom
assignment-two

Conversation

@anna-utm
Copy link
Copy Markdown
Owner

No description provided.

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.

please review the comments :)

FROM customer_purchases
ORDER BY customer_id, market_date DESC)

SELECT * , ROW_NUMBER() OVER (PARTITION BY customer_id) as visit
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ensure the ORDER BY market_date DESC is inside the ROW_NUMBER() so that the most recent visit is labeled 1.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Hi there,

I've tried and it produces the exact same result as without the ORDER BY market_date DESC is inside the ROW_NUMBER(). Is my submission acceptable? Please advise. Thank you!

SELECT customer_id, market_date as most_recent_visit

FROM (

WITH visits AS (
SELECT DISTINCT customer_id, market_date
FROM customer_purchases
ORDER BY customer_id, market_date DESC)

SELECT * , ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY market_date DESC) as visit
FROM visits
ORDER BY customer_id, visit) mrv

WHERE mrv.visit = 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.

Wonderful!

customer_purchases table that indicates how many different times that customer has purchased that product_id. */


SELECT DISTINCT customer_id, product_id,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using DISTINCT here is unnecessary and may hide duplciates

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Hi again,

I've tried removing DISTINCT and it duplicate the resulting rows.

I got 9 rows for customer_id 1, product_1 times_purchased 9;
13 rows for customer_id 1, product_id 2, times_purchased 13, etc.

Please let me know if my code is acceptable. 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.

Just DISTINCT is unnecessary, but your script is acceptable :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please create a separate 'Date' table.
And please further explain prompt 3 (type 1&2 SCD)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Hi there,

Please see the revised diagram attached.
Thank you for your feedback!

Anna
SQL_Assignment2_Prompt3.pdf

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The question actually requires you to put the date table with the other 6 tables that you have created and show the relationship. But since you have demonstrated that you are mastering the knowledge and skills, I think you deserve a pass in here! :)

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