
Answer-first summary for fast verification
Answer: SELECT ProductName, SUM(SalesAmount) AS TotalSales FROM SalesData GROUP BY ProductName ORDER BY TotalSales DESC;
Option B is the correct choice because it accurately groups the sales data by product name, which is essential for identifying top-performing products by name. It uses the SUM() function to calculate the total sales amount for each product and orders the results in descending order of total sales, making it easy to identify the highest earners. This approach meets the requirement for both accuracy and performance, as it avoids unnecessary calculations and focuses on the key metrics needed for analysis.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
As a Microsoft Fabric Analytics Engineer, you are tasked with optimizing the analysis of a retail company's sales data stored in Fabric. The dataset includes columns for product ID, product name, quantity sold, and sales amount. Your goal is to write a SQL query that not only calculates the total sales amount for each product but also ensures the results are presented in a way that highlights the top-performing products. Considering the need for accuracy and performance, which of the following SQL queries would you use to achieve this? Choose the best option that groups the data appropriately and orders the results in descending order of total sales. (Select one option)
A
SELECT ProductID, SUM(SalesAmount) AS TotalSales FROM SalesData GROUP BY ProductID ORDER BY TotalSales ASC;
B
SELECT ProductName, SUM(SalesAmount) AS TotalSales FROM SalesData GROUP BY ProductName ORDER BY TotalSales DESC;
C
SELECT ProductID, ProductName, SUM(SalesAmount) AS TotalSales FROM SalesData GROUP BY ProductID, ProductName ORDER BY TotalSales DESC;
D
SELECT ProductName, SUM(QuantitySold * SalesPrice) AS TotalSales FROM SalesData GROUP BY ProductName ORDER BY TotalSales DESC;
No comments yet.