休眠条件查询
我有以下查询sql查询:
select * from Articles ar
left join ArticleTeamRelationships atr on atr.ArticleId = ar.ArticleId
left join Team te on te.TeamId = atr.TeamId
inner join ArticleCategoryRelationships acr on acr.ArticleId = ar.ArticleId
inner join ArticleCategory ac on ac.CategoryId = acr.CategoryId
where ac.CategoryId = 3
and ((te.TeamId in (1) and ar.TeamReadOnly = 1) or te.TeamId is null)
这是我到目前为止所写的:
Criteria childCriteriaCategory = criteria.createCriteria("articleCategory", Criteria.INNER_JOIN);
childCriteriaCategory.add(Restrictions.like("categoryId", categoryId));
Criteria childCriteriaTeam = criteria.createCriteria("team", Criteria.LEFT_JOIN);
childCriteriaTeam.add(Restrictions.in("teamId", teamId));
Criterion teamReadOnly = Restrictions.eq("teamReadOnly", true);
criteria.add(teamReadOnly);
如何在第一个括号和“或”内写“和”?
I have the following query sql query:
select * from Articles ar
left join ArticleTeamRelationships atr on atr.ArticleId = ar.ArticleId
left join Team te on te.TeamId = atr.TeamId
inner join ArticleCategoryRelationships acr on acr.ArticleId = ar.ArticleId
inner join ArticleCategory ac on ac.CategoryId = acr.CategoryId
where ac.CategoryId = 3
and ((te.TeamId in (1) and ar.TeamReadOnly = 1) or te.TeamId is null)
This is what I've written so far:
Criteria childCriteriaCategory = criteria.createCriteria("articleCategory", Criteria.INNER_JOIN);
childCriteriaCategory.add(Restrictions.like("categoryId", categoryId));
Criteria childCriteriaTeam = criteria.createCriteria("team", Criteria.LEFT_JOIN);
childCriteriaTeam.add(Restrictions.in("teamId", teamId));
Criterion teamReadOnly = Restrictions.eq("teamReadOnly", true);
criteria.add(teamReadOnly);
How can I write the "and" inside the first brackets and the "or"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以放置第一个
and
来进行连接,然后放置第二个,例如:You can place a first
and
to do the join and a second one like:您想要的结构
将类似于:
The structure you want for
will be something like: