SUM
Represents the SQL SUM() aggregate function.
This function calculates the sum of all non-NULL values in a group. The result type of SUM() is the same as the input column's type. SUM() of an empty group is NULL.
Example
// Calculate the total length of all tracks
// SELECT SUM(length) FROM Tracks;
val cursor1 =
Tracks
.select(SUM(Tracks.length))
.execute()
println(cursor1[SUM(Tracks.length)])
cursor1.close()
// Calculate the sum of distinct track lengths
// SELECT SUM(DISTINCT length) FROM Tracks;
val sumDistinctLength = SUM(Tracks.length, distinct = true)
val cursor2 =
Tracks
.select(sumDistinctLength)
.execute()
println(cursor2[sumDistinctLength])
cursor2.close()Content copied to clipboard
Return
A KQLiteColumn representing the sum, with the same numeric type as the input column.
Author
MOHAMMAD AZIM ANSARI
Parameters
column
The column for which to calculate the sum.
distinct
If true, only DISTINCT (unique) values in the column are summed. Defaults to false.