Created
March 12, 2023 14:17
-
-
Save mgramin/46250b97b81abc2ff7a91f9e688a6c27 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
| select с.country_id | |
| , cnt.country | |
| , с.cities_per_country_count | |
| , floor(cities_per_country_count / cities_count * 100) as percent | |
| from (select country_id | |
| , count(1) as cities_per_country_count | |
| , sum(count(1)) over () as cities_count | |
| from city | |
| group by country_id) с | |
| join country cnt on cnt.country_id = с.country_id | |
| order by cities_per_country_count desc | |
| limit 5; | |
| insert into city(city, country_id) | |
| select unnest(array(select faker.unique_city() | |
| from generate_series(1, c.cities_count*3) as id)) as city | |
| , country_id | |
| from (select country_id | |
| , count(1) as cities_count | |
| from city | |
| group by country_id | |
| order by country_id) c; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment