JPA notEqual子查询语法

时间:2019-06-06 07:57:09

标签: subquery javax.persistence

我正在尝试向现有(工作)查询中添加第二个子查询

{{ 
    [ 
        person.address_1, 
        person.address_2, 
        person.zip_code + ' ' + person.station_city, 
        person.country_name 
    ].join('<br>') 
}}

所以我要添加第二个子查询

5 Place Charles Béraudier 
Gare de Lyon Part dieu
69003 LYON
France

这是粗略的整个查询

Query query;

CriteriaBuilder idBuilder = getCriteriaBuilder();
CriteriaQuery idQuery = idBuilder.createQuery(entityClass);

Root from = idQuery.from(entityClass);        
idQuery.select(from.get("id"));

Subquery<Long> subquery = idQuery.subquery(Long.class);
Root dateSQ = subquery.from(entityClass);

subquery.select(idBuilder.max(dateSQ.get("createdDate")));
subquery.groupBy(dateSQ.get("addressId"));

所以我已经做了类似的事情

AND address_id NOT IN
(Select address_id FROM People WHERE address_deleted = true)

对于

,这似乎是完全错误的
SELECT * FROM People
WHERE address_id IN
(select max date)
AND address_id NOT IN
(Select address_id FROM People WHERE address_deleted = true)

谁能指出我正确的方向?

0 个答案:

没有答案