我有一个查询,例如:
Select * from table where user = 'user1' or city = 'delhi';
我知道如何为单个用户执行此操作,但我不知道如何在以下查询中使用或
。
dao.queryBuilder()
.where(UserDao.Properties.UserId.eq(userId1))
.list();
最佳答案
对于版本 3.2.+,以下是使用 Where()
和 WhereOr()
条件组合的示例。以下是选择所有项目的假设查询:
- 具有“油漆”、“乳液”标签
- 属于特定类别
- 排除特定子类别
Where()
方法只接受一个查询条件,WhereOr()
方法可以接受多个查询条件(与 Dao 类中的属性数量一样多) , 以逗号分隔
String catgId = "AB12545";
String excludeSubCatgId = "SAB09990";
DaoSession daoSession = ((App) getApplication()).getDaoSession();
List<Item> = daoSession.getItemDao().queryBuilder()
.where(ItemDao.Properties.CategoryId.eq(catgId))
.where(ItemDao.Properties.SubCategory.notEq(excludeSubCatgId))
.whereOr(ItemDao.Properties.ItemTagCloud.like("%paint%"),
ItemDao.Properties.ItemTagCloud.like("%emulsion%"))
.orderDesc(ItemDao.Properties.ItemPrice)
.list();
关于java - 如何在 greenDAO 中使用 OR 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42671461/