如何使用Room Dao中的计算字段订购记录

时间:2019-03-20 11:52:55

标签: android kotlin android-room

我的实体如下:

@Entity(tableName =  "PupilScore", primaryKeys = ["SubjectId", "PupilId"], indices =
            arrayOf(Index(value = ["SubjectId", "PupilId"], unique = true, name = "idx_PupilScores")))

    data class PupilScore (@NotNull @ColumnInfo(name = "SubjectId") var subjectId: String,
                                @NotNull @ColumnInfo(name = "PupilId") var pupilId: Long = 0,
                                @SerializedName("Score") @ColumnInfo(name = "Score") var score: Int = 0)

我想在PupilScoreDao类中编写一个查询SELECT PupilId, SUM(Score) as TotalScore FROM PupilScore GROUP BY PupilId ORDER BY TotalScore DESC,将查询结果返回为列表

尽管我可以返回列表,但无法返回有序列表。当在OrderBy中使用TotalScore时,Room会给出编译器错误。有什么建议吗?

0 个答案:

没有答案