我是 Android 和 Kotlin 的新手,所以我需要帮助。 这是我的数据类:
@Entity
data class Insurance(
@PrimaryKey(autoGenerate = true)
val uid: Int,
var date: String,
var msisdn: String,
var category: String,
var hitno: String,
var priceOfInsurance: Int
) {
override fun toString(): String {
return "Insurance(date=$date - msisdn$msisdn - category=$category - hitno1=$hitno " +
"- priceOfInsurance=$priceOfInsurance )"
}
这些是我的查询:
@Dao
interface InsuranceDao {
@Query("SELECT * FROM Insurance")
fun fetchAll(): LiveData<List<Insurance>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(arg: Insurance)
@Update(onConflict = OnConflictStrategy.REPLACE)
suspend fun update(arg: Insurance)
@Delete
suspend fun delete(arg: Insurance)
@Query("DELETE FROM Insurance")
fun deleteAllInsurance()
}
我的问题是我如何进行一个可以对冒号价格保险求和的查询。
你能试试这个吗:
const val tablename = “your table name”
const val column = “your column name”
const val QUERY =“select sum( $column ) from $tablename”
@Query(QUERY)
fun getSum(): Int