我在SQL中有这个代码:
SELECT SUM(number), DAY(date) FROM conting GROUP BY DAY(date) ORDER BY DAY(date) ASC
然后我需要在房间里转换:
@Query("SELECT SUM(number), DAY(date) FROM Records GROUP BY DAY(date) ORDER BY DAY(date) ASC") fun getResumeData(): List<Graph>
Graph.kt
data class Graph (
@ColumnInfo(name = "DAY(date)") var index: Int,
@ColumnInfo(name = "SUM(number)") var value: Int
)
但它返回错误no such function: DAY
我该如何解决?
注意:
答案 0 :(得分:1)
Android(和Room)使用SQLite,而不是MySQL,因此您需要使用SQLite可用的功能构建查询。您可以使用SQLite的date()
和datetime()
函数执行类似操作,有关详细信息,请参阅https://www.sqlite.org/lang_datefunc.html。