Top SQL Questions

Scott G

Total items ordered for each order

This technical problem involves writing a SQL query to find the total number of items ordered for each order in a database. The database consists of two tables, "orders" and "order_items ". The "orders" table includes the order_id for each order, while the "order_items" table includes the order_id and the number of items ordered for that particular order. The expected output is a table that lists the order_id and the total number of items ordered for each order.

Problem

Given two tables, "orders" and "order_items", write a SQL query to find the total number of items ordered for each order.
orders:
+------------+
| order_id   |
+------------+
| 1          |
| 2          |
| 3          |
+------------+
order_items:
+------------+-------------+
| order_id   | item_count  |
+------------+-------------+
| 1          | 3           |
| 2          | 1           |
| 3          | 2           |
+------------+-------------+
Example output:
+------------+-------------+
| order_id   | total_items |
+------------+-------------+
| 1          | 3           |
| 2          | 1           |
| 3          | 2           |
+------------+-------------+

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by AskAI
test

A.I. Evaluation of the Solution

The candidate's solution is incomplete and does not solve the problem. The general approach is not clear.

Evaluated at: 2022-11-30 23:15:55

Community solutions:

Check these solutions from our community and artificial intelligence:
The candidate's solution is correct and uses an optimal approach.