休眠条件查询

发布于 2024-11-28 22:05:51 字数 905 浏览 1 评论 0原文

我有以下查询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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡淡的优雅 2024-12-05 22:05:52

您可以放置​​第一个 and 来进行连接,然后放置第二个,例如:

//pseudo code
tablea.foreignId = id

tableb.id = id

You can place a first and to do the join and a second one like:

//pseudo code
tablea.foreignId = id

tableb.id = id
日久见人心 2024-12-05 22:05:51

您想要的结构

((te.TeamId in (1) and ar.TeamReadOnly = 1) or te.TeamId is null)

将类似于:

Restrictions.or(
    Restrictions.and(
        Restrictions.in(x, x), Restrictions.eq(x, x)
    ),
    Restrictions.eq(x,x)
)

The structure you want for

((te.TeamId in (1) and ar.TeamReadOnly = 1) or te.TeamId is null)

will be something like:

Restrictions.or(
    Restrictions.and(
        Restrictions.in(x, x), Restrictions.eq(x, x)
    ),
    Restrictions.eq(x,x)
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文