Last active
December 16, 2021 12:06
-
-
Save Sedose/c13819ddd835fbaf9fac5864d183fff8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --1st solution | |
| select warehouse, count(warehouse) as number_of_boxes | |
| from boxes | |
| group by warehouse | |
| union ( | |
| select code, '0' | |
| from warehouses | |
| where code not in ( | |
| select warehouse | |
| from boxes | |
| ) | |
| ); | |
| --2nd solution | |
| with warehouses_with_boxes (warehouse_code, number_of_boxes) | |
| as ( | |
| select warehouse, count(warehouse) as number_of_boxes | |
| from boxes | |
| group by warehouse | |
| ) | |
| select warehouse_code, number_of_boxes | |
| from warehouses_with_boxes | |
| union ( | |
| select code, '0' | |
| from warehouses | |
| where code not in ( | |
| select warehouse_code | |
| from warehouses_with_boxes | |
| ) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Select the warehouse codes, along with the number of boxes in each warehouse. | |
| !!!Take into account that some warehouses are empty | |
| (i.e., the box count should show up as zero, instead of omitting the warehouse from the result). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment