ctripcorp / SQLlin

A DSL ORM library for Kotlin Multiplatform.
Apache License 2.0
219 stars 10 forks source link

较为复杂点的查询语句 #78

Closed Matcha-xiaobin closed 2 months ago

Matcha-xiaobin commented 5 months ago

碰到个问题,请教下: 我在jetpack room数据库这边写的sql语句如下:

    @Query(
        "select * from video_history where favorite = 1 " +
                "and (case when :type >= 0 then data_type = :type else data_type >= 0 end) " +
                "ORDER BY (case when last_time > create_time then last_time else create_time end) DESC " +
                "limit :pageSize"
    )
    fun getFavoriteVideoList(pageSize: Int = 20, type: Int = -1): Flow<List<PlayHistoryBean>>

order by这里,需要根据两个字段来进行排序,优先last_time,如果last_time小于create_time,就按照create_time排序,如果我想用SQLlin实现,目前是不是无法直接实现? 如果能实现的话,我应该怎么写? 如果目前无法实现的话,那是否有其它写法可以做到?

Matcha-xiaobin commented 5 months ago

我看你文档中是有提到不支持子查询,我看了下,我这个应该是不包含子查询的吧?

qiaoyuang commented 2 months ago

这个功能暂时不支持,之后我会在文档里添加说明,后续我会考虑支持。