"Return the total value of all products in a database table"

Given a database table with a schema as shown above, write a SQL query that returns the total value of all products in the table.

Problem

Given a database table with the following schema:
CREATE TABLE products (
id INT NOT NULL,
name VARCHAR(255) NOT NULL,
price DECIMAL(10,2) NOT NULL,
quantity INT NOT NULL,
PRIMARY KEY (id)
);
Write a SQL query that returns the total value of all products in the table.
Example input:
ID | Name | Price | Quantity
1 | Product A | 10.00 | 2
2 | Product B | 20.00 | 3
3 | Product C | 30.00 | 4
Example output:
120.00

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT SUM(price * quantity) AS total_value FROM products;

/*

The above solution is optimal because it is a single query that does not require any joins or subqueries.

*/

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a good understanding of SQL. The solution is also optimal, as it is a single query that does not require any joins or subqueries.

Evaluated at: 2022-11-21 04:16:18