博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
几种常用递归查询
阅读量:6040 次
发布时间:2019-06-20

本文共 2659 字,大约阅读时间需要 8 分钟。

向下查第几层

select max(LEVEL) as maxLevel
from T_lab a
start with a.lab_id ='2015050510303643710'
connect by prior a.lab_parentid = a.lab_id

<!-- 递归向下查询所有机构 -->
<select id="deptDataInit" parameterClass="map" resultClass="dto">
select deptname as text, deptid as id, parentid, type from EADEPT a where 1=1
<isNotEmpty prepend="AND" property="filtertype">
type != #filtertype#
</isNotEmpty>
start with a.deptid=#deptid# connect by prior a.deptid=a.parentid
order by type asc, sortno asc
</select>
<!-- 递归向上查询所有机构 -->
<select id="getParents" parameterClass="map" resultClass="dto">
select deptname as name, deptid as id, parentid, type from EADEPT a where 1=1
<isNotEmpty prepend="AND" property="filtertype">
type != #filtertype#
</isNotEmpty>
start with a.deptid=#deptid# connect by prior a.parentid=a.deptid
order by type asc, sortno asc
</select>

----------------------------------------------------------------------------------------------------------------
<sqlMap namespace="lab" >
<typeAlias alias="dto" type="org.eredlab.g4.ccl.datastructure.impl.BaseDto" />
<resultMap class="Dto" id="labParent">
<result property="id" column="id"/>
<result property="lab_userid" column="lab_userid"/>
<result property="lab_username" column="lab_username"/>
<result property="parentid" column="parentid"/>
<result property="name" column="name"/>
<result property="s_labfloor" column="s_labfloor"/>
<result property="s_labaddr" column="s_labaddr"/>
<result property="s_creater" column="s_creater"/>
<result property="d_createtime" column="d_createtime"/>
<result property="s_mark1" column="s_mark1"/>
<result property="children" column="id" select="lab.querylabchildren" javaType="java.util.List"/>
</resultMap>
<!-- 查询实验室 -->
<select id="querylabList" parameterClass="map" resultMap="labParent" remapResults="true">
select t.lab_id as id,t.lab_userid,t.lab_username,t.s_labname as name,t.lab_parentid as parentid,t.s_labfloor,t.s_labaddr,t.s_creater,
TO_CHAR(t.d_createtime,'yyyy-mm-dd') as d_createtime,t.s_mark1
from T_lab t where 1=1
<dynamic>
<isNotNull prepend="and" property="lab_parentid">
t.lab_parentid=#lab_parentid#
</isNotNull>
<isNotNull prepend="and" property="lab_id">
t.lab_id=#lab_id#
</isNotNull>
</dynamic>
order by t.lab_id
</select>
<!-- 查询下级实验室 -->
<select id="querylabchildren" parameterClass="String" resultMap="labParent" remapResults="true">
select t.lab_id as id,t.lab_userid,t.lab_username,t.s_labname as name,t.lab_parentid as parentid,t.s_labfloor,t.s_labaddr,t.s_creater,
TO_CHAR(t.d_createtime,'yyyy-mm-dd') as d_createtime,t.s_mark1
from T_lab t where 1=1 and t.lab_parentid=#id#
</select>

转载于:https://www.cnblogs.com/wei-java/p/4540076.html

你可能感兴趣的文章
Meteor 从一个列表页进入详情页怎样高速显示详情
查看>>
强密码正则表达式
查看>>
About Windows 10 April 2018 Update
查看>>
浙江大学PAT上机题解析之1015. 德才论 (25)
查看>>
Lintcode: First Bad Version
查看>>
WebAPI2使用AutoFac依赖注入完整解决方案。
查看>>
codeblocks中cocos2dx项目添加新的.cpp和.h文件后编译运行的方法
查看>>
二分查找的平均查找长度详解【转】
查看>>
No space left on device错误解决
查看>>
从npm 角度理解 mvn 的 pom.xml
查看>>
技术花絮
查看>>
责任心与态度比技术更重要
查看>>
贪婪与非贪婪模式
查看>>
OLTP与OLAP介绍
查看>>
hdu 4707 Pet 2013年ICPC热身赛A题 dfs水题
查看>>
分享几个linux系统版本的查看命令
查看>>
php调试工具总结
查看>>
iOS: Sorted Array with Compare
查看>>
Openstack配置文件管理的变迁之路
查看>>
安装好centOS5.5 后中文乱码
查看>>