Find the top 5 most expensive items in our inventory

To find the top 5 most expensive items in our inventory, we can write a SQL query that orders the items by price in descending order and then limit the output to the first 5 results.

Problem

Write a SQL query to find the top 5 most expensive items in our inventory.
Input:
Item  | Price
------|-------
Item1 | 100
Item2 | 200
Item3 | 300
Item4 | 400
Item5 | 500
Item6 | 600
Output:
Item  | Price
------|-------
Item6 | 600
Item5 | 500
Item4 | 400
Item3 | 300
Item2 | 200

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT * FROM items ORDER BY price DESC LIMIT 5;

/*

The above solution is optimal because it uses the ORDER BY and LIMIT clauses to sort the items by price in descending order and then limit the results to the first 5 items.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL. The solution is optimal because it uses the ORDER BY and LIMIT clauses to sort the items by price in descending order and then limit the results to the first 5 items.

Evaluated at: 2022-11-13 12:15:23