我需要将标准SQL查询转换为@Query
批注以与Room一起使用,但是我不知道该怎么做。
我有三个桌子...
访问列表
ID INTEGER
ListName TEXT
Active INTEGER
注册
ID INTEGER
FirstName TEXT
LastName TEXT
AccessListEnrollmentMapping
ID INTEGER
AccessListID INTEGER
EnrollmentID INTEGER
一个注册可以在多个AccessList上,AccessLits可以处于活动状态[1]或不处于活动状态[0],因此这是一个示例示例SQL查询,当使用DB Browser for SQLite时可以工作 :
select * from Enrollment where ID in (select EnrollmentId from AccessListEnrollmentMapping where AccessListId IN (SELECT ID FROM AccessList WHERE ID < 4 AND Active = 1));
这是我的@Query
批注:
@Query("select * from Enrollment where ID in (select EnrollmentId from AccessListEnrollmentMapping where AccessListId IN (:accessListIds))") // NEED TO CHECK FOR AccessList.Active == 1
public abstract List<Enrollment> selectEnrolleesPerAccessLists(List<Long> accessListIds);
但是,此查询返回活动和不活动AccessList上的所有注册。我不知道如何在注释中包含where AccessList.Active = 1
。