iteye_2177
iteye_2177
2009-10-11 08:23
浏览 236
已采纳

一条不理解SQL语句,查询树

SELECT a.org_id, a.org_name
FROM org a
WHERE a.org_parentid = 1
AND ((a.org_id in
(select org_id
from user_org
where user_id in (select user_.user_id
from user_, user_role, wf_step_role
where wf_step_role.role_id = user_role.role_id
and user_role.user_id = user_.user_id
and wf_step_role.step_id = 2))) OR
(SELECT COUNT(*)
FROM org b
WHERE b.org_id in
(select org_id
from user_org
where user_id in
(select user_.user_id
from user_, user_role, wf_step_role
where wf_step_role.role_id = user_role.role_id
and user_role.user_id = user_.user_id
and wf_step_role.step_id = 2))
and rownum < 2
START WITH b.org_id = a.org_id
CONNECT BY PRIOR b.org_id = b.org_parentid) > 0)
order by org_order

在OR后面的不是true就是False
请解释一下这条SQL意思,详细说明一下!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • wanghaolovezlq
    wanghaolovezlq 2009-10-11 08:28
    已采纳

    or是短路操作嘛

    如果or的左边是true,那就不对右边进行查询了,
    如果or的左边是false,才对右边进行查询,

    点赞 评论
  • tangyuanjian
    tangyuanjian 2009-10-11 10:38

    ((a.org_id in
    (select org_id
    from user_org
    where user_id in (select user_.user_id
    from user_, user_role, wf_step_role
    where wf_step_role.role_id = user_role.role_id
    and user_role.user_id = user_.user_id
    and wf_step_role.step_id = 2)))
    是假!

    点赞 评论
  • icefishc
    icefishc 2009-10-11 21:55

    sql 中 只有 true false maybe 3种情况。 count(*)又不能返回NULL, 也就是(count(*)....... ) 〉 n 不可能为maybe
    当然是true 或 false
    -_-|||你想问什么。。。

    点赞 评论

相关推荐