Conversation
efantinatti
left a comment
There was a problem hiding this comment.
Dear Dionysius Indraatmadja
Session 1:
1 - OK.
Session 2:
2 - OK.
Session 3:
3 - Partial.
-- Cross Join - Q1: Missing CROSS JOIN. Your query results are not correct.
-- DELETE - Q1: Your query deletes everything not the oldest time entry.
Final:
4 - Check the aforementioned points prior to merging your feature branch 'assignment-two' to 'main'.
Mark: 64 points.
Hi, I'm confused why the cross join portion is not correct - I seem to be cross joining in this portion of the code:
Could you please clarify where the business logic is not correct? |
|
Hi @dnysius the question asks to use CROSS JOIN clause and you are not using it. You results are not correct to what is expected. |
Hi @efantinatti , from my understanding from some online resources such as https://stackoverflow.com/questions/3918570/what-is-the-difference-between-using-a-cross-join-and-putting-a-comma-between-th using the comma as in Could you provide me a link to a resource that explains the difference between these two? As for the results being not correct, could you please provide further details as to what is not correct aside from the CROSS JOIN clause? I followed the hints regarding multiplying the number of vendors and customers to check the row count. Thanks! |
|
Hi @dnysius Some key points: Common Table Expressions (CTEs): cte: Calculates five_sales_cost for each unique combination of vendor_id, product_id, and original_price from vendor_inventory. However, this CTE does not ensure the presence of distinct records before aggregation. The GROUP BY in this CTE is likely redundant unless other non-aggregated columns exist in the base table. The query introduces a Cartesian product between cte and cte2 because cte is not joined with cte2 in any way. This means that for every unique record in cte, the results are duplicated for each customer_id in cte2. Correctly associates vendor and product data to cte based on vendor_id and product_id. The GROUP BY aggregates results based on cte.vendor_id and cte.product_id, but the duplication from the Cartesian product inflates the results. |
|
Hi @efantinatti Before the grouping and aggregation, here is what I have after the cross join/cartesian product of cte and cte2:
In the preview, it shows that each vendor's products has had its cost multiplied by 5, and has been joined to each distinct customer id found in customer_purchases. In my understanding, this is what is meant by the question when it asks for the revenue per product for vendors selling 5 of each product to every customer on record. Could you let me know what is wrong with this data at this point in the query and what is the expected result? Thanks |
|
Hi @dnysius Your query is not summing up per vendor and product. Here is a simular query (based on your cte's) without CROSS JOIN that would produce the same expected result: WITH cte1 AS ( SELECT |
|
Hi @efantinatti Your query produces the following result: My query appears to produce the same result: Since the two queries produce the same result, would it be fair to say that my query is correct? Also, I am grouping by vendor and product (using vendor.vendor_name, and product.product_name instead of ids in your query), so it should be summing up per vendor and product. Let me know if you meant something different. If not, then could you let me know what the expected correct result should be, and I can troubleshoot from there? I'm not understanding what the issue is. |
|
Hi @dnysius Added Fixed your mark to 70 points and thanks for this discussion. Thank you |



What changes are you trying to make? (e.g. Adding or removing code, refactoring existing code, adding reports)
assignment two questions
What did you learn from the changes you have made?
sql querying up to window functions, insert/update
Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?
n/a
Were there any challenges? If so, what issue(s) did you face? How did you overcome it?
n/a
How were these changes tested?
fulfilled requirements
A reference to a related issue in your repository (if applicable)
n/a
Checklist