SQL Query to Find Top 5 Most Expensive Items in "Electronics" Category

Write a SQL query to find the top 5 most expensive items in the "Electronics" category.

Problem

Write a SQL query to find the top 5 most expensive items in the " Electronics " category.
Input:
Table: Electronics
item_id | item_name | price
1 | TV | 500
2 | Laptop | 1000
3 | Tablet | 750
4 | Phone | 900
5 | Camera | 1200
Output:
item_id | item_name | price
5 | Camera | 1200
4 | Phone | 900
3 | Tablet | 750
2 | Laptop | 1000
1 | TV | 500

Solution

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

/*

The solution is optimal because it uses the ORDER BY clause to sort the results in descending order by price, and the LIMIT clause to limit the results to the top 5 most expensive items.

*/

A.I. Evaluation of the Solution

The solution is optimal because it uses the ORDER BY clause to sort the results in descending order by price, and the LIMIT clause to limit the results to the top 5 most expensive items.

Evaluated at: 2022-11-07 12:15:25