我还不太熟悉Oracle方式的SQL语句,请高手帮个忙吧!String sql ="select a.Id, a.Deptname, ";sql +="decode((select count(1) from Aclorganization b where b.parentid =a.id),'0','true','false') re ";sql +="from Aclorganization a where a.parentid = ? order by a.deptorder asc ";
decode((select count(1) from Aclorganization b where b.parentid =a.id),'0','true','false') re
from Aclorganization a
where a.parentid = ?
order by a.deptorder asc 通过表的自关联查询每个部门有没有下级部门,其中:
1. decode为类型转换函数,如果子查询范围0,则返回True,否则为False
2. a.parentid = ? 为查询条件,?是需要传入的条件值参数
3. order by a.deptorder asc 按照deptorder升序排列
4. 子查询select count(1) from Aclorganization b where b.parentid =a.id是按照b表的第一个字段进行Count计算,b.parentid =a.id是b表的上级ID等于a表的id
re就是是否存在下级部门decode((select count(1) from Aclorganization b where b.parentid =a.id),'0','true','false')的别名啊
楼主可能是不了解decode 函数的使用,可以查下帮助文档