基于依赖项对 select 实体的灵活搜索查询

Flexible Search query to select entity based on dependent

我有有订单的用户。我想 select 所有用户:
1.完全没有订单 2. 没有大于 x 日期的订单(所以如果用户有 10 个订单,其中一个小于通过日期 - 我仍然需要这个用户。
3. 为result

添加更多条件

我已经这样做了,但它没有按我需要的方式工作。首先,我使用 LEFT join 加入所有订单,然后检查 - 如果订单大于通过日期 - 我不选择一个项目。最后 "or" 检查我已经把自己搞糊涂了,不知道它在做什么(我们不能没有用户的订单)

select {c.pk}
from {User as c
left join Order as ord on {c.pk}={ord.user}}
where not exists
({{
  select {o.date} from {Order as o} where {o.date} >='24-Oct-2017'
}})
or {ord.user} is null

在您的 SubQuery 中缺少用户检查。添加{o.user} = {c.pk}