Skip to content

TITLE: UofT-DSI | SQL - Assignment 2#2

Open
lsmamy wants to merge 1 commit intomainfrom
assignment-2
Open

TITLE: UofT-DSI | SQL - Assignment 2#2
lsmamy wants to merge 1 commit intomainfrom
assignment-2

Conversation

@lsmamy
Copy link
Copy Markdown
Owner

@lsmamy lsmamy commented Aug 18, 2025

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

adding

What did you learn from the changes you have made?

making changes

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

All the other rows will remain the same.) */

SELECT *
,ifnull (product_name, 'unknown')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

product_name replacement is not required by the question. But, you may need to handle product_qty_type


SELECT *
,ifnull (product_name, 'unknown')
,coalesce (product_size, 'unit')
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 replace product_size with ' ' (blank) instead of 'unit' as required

ORDER BY market_date ASC
) AS visit
FROM customer_purchases;

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 also answer the question using ROW_NUMBER()

ORDER BY market_date DESC
) AS visit
FROM customer_purchases;

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 filter the result to the most recent visit. Consider using WHERE

SELECT product_name,
CASE
WHEN INSTR (product_name, '-') THEN
SUBSTR (product_name, RTRIM(LTRIM(INSTR(product_name, '-') + 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.

INSTR() returns position, not a string. Consider LTRIM(RTRIM(SUBSTR(product_name,INSTR(product_name,'-')+1)))

RANK () OVER (ORDER BY sales DESC) as rank_desc
FROM sales_table
)
SELECT market_date, sales FROM days_ranked_table WHERE rank_desc == 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.

syntax issue, should be single =

Before your final group by you should have the product of those two queries (x*y). */

/*
sorry this qeustion was too ambigous for me :( I dont know how to find out:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

First, count how many customers there are (y). Then, think about how many vendor-product combinations exist (x). The total revenue per product per vendor for all customers is like multiplying x * y before you do any grouping :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A 'date' table is required as per question
Please also complete prompt3 (type 1 & 2 SCD)

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