1715. Count Apples and Oranges

https://leetcode.com/problems/count-apples-and-oranges

Description

Table: Boxes

+--------------+------+
| Column Name  | Type |
+--------------+------+
| box\_id       | int  |
| chest\_id     | int  |
| apple\_count  | int  |
| orange\_count | int  |
+--------------+------+
box\_id is the primary key for this table.
chest\_id is a foreign key of the chests table.
This table contains information about the boxes and the number of oranges and apples they contain. Each box may contain a chest, which also can contain oranges and apples.

Table: Chests

+--------------+------+
| Column Name  | Type |
+--------------+------+
| chest\_id     | int  |
| apple\_count  | int  |
| orange\_count | int  |
+--------------+------+
chest\_id is the primary key for this table.
This table contains information about the chests we have, and the corresponding number if oranges and apples they contain.

Write an SQL query to count the number of apples and oranges in all the boxes. If a box contains a chest, you should also include the number of apples and oranges it has.

Return the result table in any order.

The query result format is in the following example:

ac

Last updated

Was this helpful?