Answer:
SELECT product_name, SUM(DISTINCT quantity) AS total_quantity
RANK() OVER (PARTITION BY total_quantity ORDER BY product_name) AS rank,
DENSE_RANK () OVER (ORDER BY quantity DESC) AS dense_rank
FROM Order_items
JOIN products ON Order_items.product_id = products.product_id
GROUP BY product_id
Step-by-step explanation:
The SQL query returns four columns namely, product name, total quantity, rank and dense rank. The query uses the rank and the dense rank function to return the rows according to numeric ranks.