I want to simulate this query using kotlin exposed framework:
SELECT max(episodes.season_number) FROM episodes WHERE episodes.parent_id = 944947
I tried the next one query:
fun countSeasonsForParentId(id: Int) = transaction {
EpisodeTable.slice(EpisodeTable.season)
.select { EpisodeTable.parentId eq id }
.map { it[EpisodeTable.season] }.maxOrNull()
}
But this query just results in:
SELECT episodes.season_number FROM episodes WHERE episodes.parent_id = 944947
and the max value is selected in the code.
How to perform finding max value on the side of the database and map it to Int
?