Skip to content

Conversation

@Jesse1919-hub
Copy link
Owner

@Jesse1919-hub Jesse1919-hub commented Nov 27, 2025

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

What did you learn from the changes you have made?

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

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

last 3 questions have not been answered.

@Jesse1919-hub
Copy link
Owner Author

Jesse1919-hub commented Nov 30, 2025 via email

Copy link

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

Great work!

only the customer’s most recent visit. */

SELECT customer_id, market_date,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY market_date DESC ) AS number_of_visit
Copy link

Choose a reason for hiding this comment

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

The query does not filter to only the most recent visit (number_of_visit = 1). Add a line "WHERE number_of_visit = 1" may help.

CREATE TABLE temp.sales_by_date AS
SELECT
market_date,
SUM(cost_to_customer_per_qty) AS total_sales
Copy link

Choose a reason for hiding this comment

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

The assignment asked for total sales per day, here should be ROUND(SUM(quantity * cost_to_customer_per_qty),2) AS toal_sales



DELETE FROM product_units
WHERE product_name = 'Banana Split'
Copy link

Choose a reason for hiding this comment

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

This deletes all rows with this product_name, not just the recent one. consider this:
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))

SELECT
v.vendor_name,
pc.product_category_name,
num_customers * 5 * vi.original_price AS total_revenue
Copy link

Choose a reason for hiding this comment

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

This formula assumes each vendor has every product and multiplies by a count, but it doesn’t correctly align with the actual product/vendor/customer relationships. This can lead to wrong revenue numbers if there are multiple products per vendor or multiple vendors per product.

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.

3 participants