groupBy

abstract fun groupBy(column: KQLiteColumn<*>): SelectStatement<T>

Same as calling groupBy(column, null)


abstract fun groupBy(column1: KQLiteColumn<*>, column2: KQLiteColumn<*>?): SelectStatement<T>

Adds a GROUP BY clause to the SELECT statement.

This clause groups rows that have the same values in specified columns into summary rows, like "find the number of employees in each department". It is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to perform calculations on each group.

You can group by one or two columns.

Example

    // Select the department ID and the count of employees in each department
val cursor =
Employees
.select(Employees.departmentId, COUNT(Employees.employeeId))
.groupBy(Employees.departmentId)
.execute()

// Process the results
cursor.forEach { row ->
val departmentId = row[Employees.departmentId]
val employeeCount = row[COUNT(Employees.employeeId)]
println("Department $departmentId has $employeeCount employees.")
}

Return

The SelectStatement instance, allowing for further chaining of query-building methods.

Author

MOHAMMAD AZIM ANSARI

Parameters

column1

The primary column to group the result set by.

column2

An optional second column to further group the result set.

See also