Skip to main content

Top Product Lines

MediumPremium

Given the schema shown below, write a solution to find the product lines that have the highest sales volume, ranked in descending order (e.g. highest sales volume = #1, lowest sales volume = #10).

Sales volume is not equal to sales revenue. Sales volume measures the quantity of products or services sold over a certain period.

users products +---------------+---------+ +-----------------+---------+ +--| id | int | +-----| id | int | | | first_name | varchar | | | name | varchar | | | last_name | varchar | | +->| product_line_id | date | | | user_city | int | | | | stock | int | | | email | int | | | +-----------------+---------+ | +---------------+---------+ | | | | | | transactions | | product_lines | +---------------+---------+ | | +--------+--------+ | | id | int |<----+ +--| id | int | +---->| customer_id | int | | name | varchar| | product_id | int | +--------+--------+ | amount | int | | currency_code | varchar | | date | date | +---------------+---------+ exchange_rate +----------------------+---------+ | id | int | | source_currency_code | varchar | | target_currency_code | varchar | | rate | numeric | +----------------------+---------+

Your solution should return the product line name and the total number of products sold:

rank | name | volume -----+---------+------- int | varchar | int