我正在尝试为人员找到status =“a”的记录 但不包括同一个人拥有状态=“b”
的另一条记录的记录SELECT * FROM Person WHERE STATUS ='a' AND Person_id NOT IN(从Person中选择Person_id,其中STATUS ='b'且Person_id不为NULL)
感谢帮助
答案 0 :(得分:0)
您可以通过DetachedCriteria使用Criteria API编写子查询:
DetachedCriteria dc = DetachedCriteria.forClass(Person.class);
dc.setProjection(Property.forName("id")); // select person_id
dc.add(Property.forName("status").eq("b")); // where status = 'b'
Criteria c = session.createCriteria(Person.class);
c.add(Property.forName("id").notIn(dc)); // where id not in (above subquery)
c.add(Property.forName("status").eq("a")); // and status = 'a'
c.list(); // TODO: handle results