COUNT
Represents the SQL COUNT() aggregate function.
This function returns the number of rows in a group.
COUNT(*): (the default, when column isnull): Returns the total number of rows in the group, including rows with NULL values.COUNT(column): Returns the number of rows where the specifiedcolumnis not NULL.COUNT(DISTINCT column): Returns the number of distinct, non-NULL values in the specifiedcolumn.
The result of COUNT() is always an INTEGER value, Kotlin Long.
Example
// SELECT COUNT(*) FROM Employees;
val cursor1 =
Employees
.select(COUNT())
.execute()
println(cursor1[COUNT()])
cursor1.close()
// SELECT COUNT(city) FROM Employees;
val cursor2 =
Employees
.select(COUNT(Employees.city))
.execute()
println(cursor2[COUNT(Employees.city)])
cursor2.close()
// SELECT COUNT(DISTINCT city) FROM Employees;
val distinctCities = COUNT(Employees.city, distinct = true)
val cursor3 =
Employees
.select(distinctCities)
.execute()
println(cursor3[distinctCities])
cursor3.close()Content copied to clipboard
Return
A KQLiteColumn representing the count, which is always of type Long.
Author
MOHAMMAD AZIM ANSARI
Parameters
column
The column to count. If null, it performs a COUNT(*) which counts all rows. Defaults to null.
distinct
If true, only distinct (unique) non-NULL values in the column are counted. Defaults to false.