在Mysql中,FIND_IN_SET
用于查找集合中的值。我在SQLite中尝试了FIND_IN_SET
,但它不是SQL关键字。我用谷歌搜索,但我没有得到答案。如果有人知道,请告诉我SQLite中FIND_IN_SET
的替代方法。
答案 0 :(得分:12)
如果您只需要一个真/假值而不是索引,那么您可以使用LIKE
子句:
(',' || column_name || ',') LIKE '%,value,%'
答案 1 :(得分:4)
我们可以将更改等查询写入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')
答案 2 :(得分:0)
这是我的旧查询
String query =“SELECT a.content_id,a.content_name,a.image_name,a.image_path,a.rating,d.content_type_name” +“来自content_master a,category_content_mapping b,” +“game_detail c,content_type_master d” +“其中a.content_id = b.content_id” +“和c.content_id = a.content_id” +“和a.content_type_id = d.content_type_id” +“和b.category_id ='”+ category_id +“'” +“和find_in_set('”+ group_master_id +“',c.group_master_id)” +“和a.is_active ='Y'和b.is_active ='Y'和c.is_active ='Y'” +“由b.content_mapping_id命令DESC限制0,3”;
hibernate中的标准使用像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"));