Table: Experiments
| Column Name | Type |
|---|---|
| experiment_id | int |
| platform | enum |
| experiment_name | enum |
experiment_idis the column with unique values for this table.platformis an enum (category) type of values ('Android','IOS','Web').experiment_nameis an enum (category) type of values ('Reading','Sports','Programming').
This table contains information about the ID of an experiment done with a random person, the platform used to do the experiment, and the name of the experiment.
Write a solution to report the number of experiments done on each of the three platforms for each of the three given experiments. Notice that all the pairs of (platform, experiment) should be included in the output including the pairs with zero experiments.
Return the result table in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
experiment_id
PK
|
int | Unique identifier for each experiment |
platform
|
enum | Platform where experiment was conducted: Android, IOS, Web |
experiment_name
|
enum | Type of experiment: Reading, Sports, Programming |
Input & Output
| experiment_id | platform | experiment_name |
|---|---|---|
| 1 | Android | Reading |
| 2 | Android | Reading |
| 3 | Android | Reading |
| 4 | IOS | Programming |
| 5 | IOS | Programming |
| 6 | Web | Programming |
| platform | experiment_name | num_experiments |
|---|---|---|
| Android | Programming | 0 |
| Android | Reading | 3 |
| Android | Sports | 0 |
| IOS | Programming | 2 |
| IOS | Reading | 0 |
| IOS | Sports | 0 |
| Web | Programming | 1 |
| Web | Reading | 0 |
| Web | Sports | 0 |
The query creates all 9 possible combinations of platforms (Android, IOS, Web) and experiments (Programming, Reading, Sports). Then it counts actual occurrences: Android-Reading has 3 experiments, IOS-Programming has 2, Web-Programming has 1, and all other combinations have 0.
| experiment_id | platform | experiment_name |
|---|
| platform | experiment_name | num_experiments |
|---|---|---|
| Android | Programming | 0 |
| Android | Reading | 0 |
| Android | Sports | 0 |
| IOS | Programming | 0 |
| IOS | Reading | 0 |
| IOS | Sports | 0 |
| Web | Programming | 0 |
| Web | Reading | 0 |
| Web | Sports | 0 |
When the Experiments table is empty, the CROSS JOIN still generates all 9 possible platform-experiment combinations, but the LEFT JOIN finds no matches, resulting in all counts being 0.
Constraints
-
platformis one of'Android','IOS','Web' -
experiment_nameis one of'Reading','Sports','Programming' -
experiment_idis unique for each row