Last active
December 19, 2015 18:29
-
-
Save cheptsov/5999327 to your computer and use it in GitHub Desktop.
Just added function and group by support to the Expose SQL library for Kotlin
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 (Cities.name, сount(Users.id)) from Cities join Users groupBy Cities.name forEach { | |
val (cityName, userCount) = it | |
if (userCount > 0) { | |
println("$userCount user(s) live(s) in $cityName") | |
} else { | |
println("Nobody lives in $cityName") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Produces:
SQL: SELECT Cities.name, COUNT(Users.id) FROM Cities LEFT JOIN Users ON Cities.id = Users.city_id GROUP BY Cities.name
Nobody lives in Prague
1 user(s) live(s) in St. Petersburg
2 user(s) live(s) in Munich