541. CTE for monthly sales — CTE task 1

DBMS Published Updated 0 Views Verified
Write a MySQL 8.0 CTE query for this task. Prefer a readable CTE over a deeply nested subquery when it improves clarity.
Looking for the latest Sarkari Result 2026 updates? Check the latest government exam results, merit lists and result updates on Sarkari Resultess.
Sarkari Resultess
Questions & Answers

Answer & Explanation

4 Answers
Verified

Option A

Use TRUNCATE for the CTE result.
Additional Explanation
This option is incorrect for the stated requirement.
Sarkari Resultess
Editorial Answer 1
Verified

Option B

Use a correlated DELETE without any filter.
Additional Explanation
This option is incorrect for the stated requirement.
Sarkari Resultess
Editorial Answer 2
Verified Correct Answer

Option C

WITH monthly_sales AS (SELECT DATE_FORMAT(order_date,'%Y-%m') month,SUM(total_amount) revenue FROM orders WHERE status='completed' GROUP BY DATE_FORMAT(order_date,'%Y-%m')) SELECT * FROM monthly_sales ORDER BY month;
Additional Explanation
Correct implementation. Prefer parameterized queries in application code, validate affected rows for UPDATE/DELETE, and use transactions for related writes.
Sarkari Resultess
Editorial Answer 3
Verified

Option D

Use only a CROSS JOIN.
Additional Explanation
This option is incorrect for the stated requirement.
Sarkari Resultess
Editorial Answer 4