zoukankan      html  css  js  c++  java
  • 通过sql语句支持查询出TreeGrid需要的数据结构

      之前在项目中都是通过查询出基础数据,然后再业务层组装出TreeGrid对应的数据结构。但是个人感觉如果在提供树状结构展示的同时提供excel导出的共就比较麻烦,所以自己就写了一个。

      

    ----树形结构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
                        and a.code like :orgCode1
                        and a.enable = :enable
                        and c.testcampuscode is not null) m
              left join (
    ---如果要在查询结果中增加一列,并且这列的值为指定的几个值时,可以组装一个临时表
    select '' subejctstages
                           from dual
                         union
                         select '1' subejctstages
                           from dual
                         union
                         select '2' subejctstages
                           from dual) n
                on length(m.orgCode) = 6
    

      

  • 相关阅读:
    RAC环境下ORACLE序列缓存导致序列混乱
    zzu edu
    windows下的神器
    关于VO、PO的理解——JAVA的(PO,VO,TO,BO,DAO,POJO)解释
    enum学习
    maven 引入本地 jar
    eclipse F6和F8的问题
    记一个搜索网盘资源的网站
    多表查询, 聚集查询和分组查询
    winserver2008安装tomcat+mysql+httpd+redis环境
  • 原文地址:https://www.cnblogs.com/hobby0524/p/11989908.html
Copyright © 2011-2022 走看看