Before the project by querying the underlying data are then assembled TreeGrid business layer corresponding to the data structure. But the personal feeling, if provided excel export while providing a tree structure to show a total of more trouble, so he wrote a.
----树形结构orgcode不能重复,所以用orgCode+subejctstages组装 select m.orgCode || n.subejctstages orgCode, orgName, orglevel, case when length(m.orgCode) = 6 and n.subejctstages is not null then orgCode else pcode end pcode, subejctstages from (select distinct a.code orgCode, a.name orgName, a.orglevel, a.pcode from org a left join (select a.testid, a.testcampuscode from subjectregister a where a.testid = :testID and a.testcampuscode like :orgCode group by a.testid, a.testcampuscode having count(1) > 0) c on a.testid = c.testid --and a.code = c.testcampuscode and (a.code = c.testcampuscode or a.code = substr(c.testcampuscode, 0, 5) or a.code = substr(c.testcampuscode, 0, 2)) where a.testid = :testID1 a.code like and: orgCode1 and a.enable = :enable Not c.testcampuscode IS null and) m left the Join ( --- if the query results to add one, and when it is a specified number of columns of values, a temporary table can be assembled SELECT '' subejctstages from Dual Union SELECT '. 1' subejctstages from Dual Union SELECT '2' subejctstages from Dual) n- ON length (m.orgCode). 6 =