Find the products with the highest price per unit.

Given a table of products and their prices, write a SQL query to find the products with the highest price per unit.

Problem

Given a table of products and their prices, write a SQL query to find the products with the highest price per unit.
Input:
Table: products
+------------+---------+-------+
| product_id | name    | price |
+------------+---------+-------+
| 1          | apple   | 0.50  |
| 2          | orange  | 0.75  |
| 3          | pear    | 1.00  |
| 4          | banana  | 0.25  |
+------------+---------+-------+
Output:
+------------+---------+-------+
| product_id | name    | price |
+------------+---------+-------+
| 3          | pear    | 1.00  |
+------------+---------+-------+

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT product_id, name, price
FROM products
ORDER BY price DESC
LIMIT 1;

/*

The solution above is optimal because it uses the ORDER BY and LIMIT clauses to sort the table by price in descending order and then return the first row.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL.

Evaluated at: 2022-11-26 14:15:57