SQL Query to Find Products with Price Greater than Average Price

This technical problem involves writing a SQL query to find products with a price greater than the average price of all products.

Problem

Given a database table with the following schema:
CREATE TABLE products (
id INTEGER PRIMARY KEY,
name TEXT,
price INTEGER
);
Write a SQL query to find the products that have a price greater than the average price of all products.
Example input:
id | name | price
1 | product1 | 10
2 | product2 | 20
3 | product3 | 30
4 | product4 | 40
5 | product5 | 50
Example output:
id | name | price
3 | product3 | 30
4 | product4 | 40
5 | product5 | 50

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT * FROM products WHERE price > (SELECT AVG(price) FROM products);

/*

The above solution is optimal because it only requires one query to the database.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a level of completeness. The solution solves the problem and uses the correct SQL syntax. The candidate's approach is efficient because it only requires one query to the database.

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