Get Top 10 Products by Sales

Write a stored procedure that returns the top 10 products by sales from a given table.

Problem

Given a table of products, write a stored procedure that returns the top 10 products by sales.
Example input:
| product_id | name       | sales |
|------------|------------|-------|
| 1          | Product 1  | 10    |
| 2          | Product 2  | 20    |
| 3          | Product 3  | 30    |
| 4          | Product 4  | 40    |
| 5          | Product 5  | 50    |
Example output:
| product_id | name       | sales |
|------------|------------|-------|
| 5          | Product 5  | 50    |
| 4          | Product 4  | 40    |
| 3          | Product 3  | 30    |
| 2          | Product 2  | 20    |
| 1          | Product 1  | 10    |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT TOP 10 * FROM products ORDER BY sales DESC;

/*

The solution above is optimal because it uses the TOP keyword to limit the number of rows returned, and the ORDER BY clause to sort the rows by sales in descending order.

*/

A.I. Evaluation of the Solution

The candidate's solution is optimal and demonstrates a complete understanding of how to write a stored procedure to return the top 10 products by sales.

Evaluated at: 2022-11-05 00:16:14