问题
I want to return multiple counts from Room
Select query in android
.
My query is like
Select Count(CASE WHEN x = '0' or x = '2'), Count(Case when a = '33' or a = '23') FROM my_table WHERE id=10
I want above query to return something as list which will contain values of both the above Count()
function. This can be easily done using SQLite
but I want to use it in room
.
回答1:
You can give names to the counts and return them as a class, like:
data class MyCounts(
@ColumnInfo(name = "first_count")
val firstCount: Int,
@ColumnInfo(name = "second_count")
val secondCount: Int
)
@Dao
interface MyDao {
@Query("SELECT COUNT(*) as first_count, COUNT(*) as second_count from my_table")
suspend fun getMyCounts(): MyCounts
}
来源:https://stackoverflow.com/questions/62382612/how-to-get-multiple-counts-from-room-database