You can download the code for this example here:
OnyxDevTools/onyx-database-examples/querying/GroupByExample.
The Group By statement is often used with aggregate functions (count, min, max, sum, avg) to group the result-set by one or more columns.
Onyx Database 2.1.1 supports grouping by one or more attributes or derived attributes.
Both Kotlin and Java support this new feature. A Kotlin example can be found
OnyxDevTools/onyx-database-examples/querying/KotlinQueryBuilder.kt.
The group by will allow one or more fields. The fields can also be derived. For instance, you can group by replace("myAttribute", "\\s+", "").
In this example we have grouped by rushing yards to see how many players have specific yards. To do so, you must select rushingYards and count(player.playerId)
This will retrieve a List<Map<String, Object>>.
The data will be formatted as with the keys being the selections.
Another example of using Query functions without groupBy is to use the max() method to get the leading rusher.
The example above can also be written in Kotlin using the following:
Our goal is to bring about change by enabling people to use simple and quality software in order to make sad engineers happy.
Copyright ©2017 Onyx Development Tools, LLC. All rights reserved.