Find the average price of all products in a database table.

Write a SQL query to find the average price of all products in a database table.

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 average price of all products.
Example input:
INSERT INTO products (id, name, price)
VALUES
(1, 'Product A', 10),
(2, 'Product B', 20),
(3, 'Product C', 30);
Example output:
20

Solution

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

/*

The above query is optimal because it is the simplest way to get the average price of all products.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a level of completeness. The candidate's approach is also optimal, as it is the simplest way to get the average price of all products.

Evaluated at: 2022-11-04 22:15:16