TOTAL

fun <T : Number?> TOTAL(column: KQLiteColumn<T>, distinct: Boolean = false): KQLiteColumn<T>

Represents the SQL TOTAL() aggregate function.

This function calculates the total of all non-NULL values in a group. It is similar to SUM(), but with a key difference: The result of TOTAL() for an empty group is 0.0.

Example

// Calculate the total length of all tracks
// SELECT TOTAL(length) FROM Tracks;
val cursor1 =
Tracks
.select(TOTAL(Tracks.length))
.execute()
println(cursor1[TOTAL(Tracks.length)]) // Result is a Double
cursor1.close()

// Calculate the total of distinct track lengths
// SELECT TOTAL(DISTINCT length) FROM Tracks;
val totalDistinctLength = TOTAL(Tracks.length, distinct = true)
val cursor2 =
Tracks
.select(totalDistinctLength)
.execute()
println(cursor2[totalDistinctLength])
cursor2.close()

Return

A KQLiteColumn representing the total with the same numeric type as the input column.

Author

MOHAMMAD AZIM ANSARI

Parameters

column

The column for which to calculate the total sum.

distinct

If true, only DISTINCT (unique) values in the column are considered. Defaults to false.

Type Parameters

T

The numeric type of the column values. Must be a subtype of Number.

See also