【发布时间】:2020-01-15 12:21:40
【问题描述】:
我有一个使用 Room 和 RxJava 的 Android 应用。
假设我有两个表box(id) 和ball(id, color, boxId)。
我需要一个查询来返回所有包含每种颜色的球数的框。
Flowable<List<BoxWithBallsCount>> getBallsWithCount();
有这个:
BoxWithBallsCount(Box box, BoxCount boxCount)
BoxCount(String ballColor, int count)
我创建了以下道
@Dao
public interface BoxDao {
@Query("SELECT * FROM box")
Flowable<List<Box>> getAll();
@Query("SELECT ball.color, count(*) FROM box WHERE ball.boxId = :boxId GROUP BY ball.color")
Flowable<List<BoxCount>> dificultQuery(String herdId);
}
现在我需要实现 main 方法:可流动的 returns BoxWithBallsCount 列表。
我该怎么做?
我尝试了很多 RX 方法,但找不到正确的方法。
谢谢
【问题讨论】:
-
我认为更好的方法是在原始查询中使用子选择?
SELECT * FROM t1 A, (SELECT count(*) AS count FROM t2 T2 where t1.id = t2.id) B WHERE A.id = B.id
标签: android rx-java rx-java2 android-room