P / VO OA Interview Question: SQL to Get Top 10 Selling Categories by Total Sales in 2024

17 Views
No Comments

SQL to Get Top 10 Selling Categories by Total Sales in 2024

category (

category_id INTEGER PRIMARY KEY,
category_name VARCHAR(100) NOT NULL

)

table (

product_id INTEGER PRIMARY KEY,
product_name VARCHAR(200) NOT NULL,
category_id INTEGER,
FOREIGN KEY (category_id) REFERENCES categories

)

sales (

product_id INT,
period_date DATE,
sales FLOAT

)

Write an SQL query to get the top 10 selling categories by total sales in 2024.

This is a standard SQL aggregation and join problem. The goal is to connect the categories, products, and sales tables, filter sales records to 2024, sum sales by category, sort the results in descending order, and return the top 10 categories. The key steps are joining on the product and category keys, grouping by category, and applying an ordered limit to produce the final ranking.

END
 0