在Mysql中,
FIND_IN_SET
用于查找集合中的值。我在 SQLite 中尝试过 FIND_IN_SET
,但它不是 SQL 关键字。我用谷歌搜索过,但没有得到答案。如果有人知道,请告诉我 SQLite 中 FIND_IN_SET
的替代方案。
如果您只需要 true / false 值而不是索引,那么您可以使用
LIKE
子句:
(',' || column_name || ',') LIKE '%,value,%'
我们可以将查询之类的更改写入hibernate critearea
我的旧查询
select * FROM game_detail WHERE content_id=176 and FIND_IN_SET(12,group_master_id)
新查询
select *
FROM game_detail
WHERE content_id=176
and (group_master_id LIKE '%12,%'|| group_master_id LIKE '%,12,'|| group_master_id LIKE '%12')
可能我迟到了,但是有 instr(X,Y) 函数 https://www.sqlite.org/lang_corefunc.html#instr
我用它来设置行的顺序 UPDATE table SET row_order = instr('321', rowid) WHERE rowid in (1,2,3)
这是我的旧查询
String query = "SELECT a.content_id,a.content_name,a.image_name,a.image_path,a.rating,d.content_type_name"
+ "from content_master a, category_content_mapping b, "
+ "game_detail c, content_type_master d "
+ "where a.content_id=b.content_id "
+ "and c.content_id = a.content_id "
+ "and a.content_type_id = d.content_type_id "
+ "and b.category_id = '" + category_id + "' "
+ "and find_in_set('" + group_master_id + "',c.group_master_id) "
+ "and a.is_active='Y' and b.is_active = 'Y' and c.is_active = 'Y'"
+ "order by b.content_mapping_id DESC limit 0,3";
休眠中使用的标准,例如 find_in_set 的替代
Session session=new Configuration().configure().buildSessionFactory().openSession();
Criteria criteria=session.createCriteria(ContentMaster.class);
criteria.setFetchMode("CategoryContentMapping", FetchMode.JOIN);
criteria.setFetchMode("GameDetail", FetchMode.JOIN);
criteria.createAlias("categoryContentMappings","cat");
criteria.createAlias("contentTypeMaster", "ctm");
criteria.createAlias("gameDetails","game");
criteria.add(Restrictions.eq("cat.categoryMaster.categoryMasterId", 9));
criteria.add(Restrictions.disjunction()
.add(Restrictions.like("game.groupMasterId","%12,%"))
.add(Restrictions.like("game.groupMasterId","%,12,%"))
.add(Restrictions.like("game.groupMasterId","%12%")));
criteria.add(Restrictions.eq("isActive", "y"));
criteria.add(Restrictions.eq("cat.isActive", "y"));
criteria.add(Restrictions.eq("ctm.isActive", "y"));
criteria.addOrder(Order.desc("cat.contentMappingId"));