Given a table of products and their prices, write a SQL query to 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. 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 | +------------+---------+-------+
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. */
The candidate's solution is correct and demonstrates a good understanding of SQL.
Evaluated at: 2022-11-26 14:15:57