码迷,mamicode.com
首页 > 数据库 > 详细

一个很变态的SQL

时间:2017-06-07 14:32:54      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:replace   review   alt   proc   union   instr   gif   stat   str   

技术分享
select max(s.operat_time) as pzTime
  from ws_state_record s
 where s.status = (select p1.node_id
                     from WS_PROCESS p1
                    where p1.role_id =
                          (select max(p2.role_id)
                             from WS_PROCESS p2
                            where p2.node_id in (10001,10002)))//业务表流程足迹
   and s.operat_orgtype = review


//------------------------测试01 --------------------------------
select  t.id,
        substr(t.team_id, 2, 4) as a,
       substr(t.team_id, 7, 4) as b,
       d.name as team_type_text,
       t.throughnodes,
       (select max(s.operat_time) as pzTime
  from ws_state_record s
 where s.status =
       (select p1.node_id
          from WS_PROCESS p1
         where p1.role_id =
               (select max(p2.role_id)
                  from WS_PROCESS p2
                 where p2.node_id in (t.throughnodes))) and s.bizdata_id = t.id
   and s.operat_orgtype = review) as pz_time
   
  from WS_TEAM_INFORMATION t
  left join DICT d
    on t.team_type = d.code


---------------------------------------------------------
select max(s.operat_time) as pzTime
  from ws_state_record s
 where s.status =
       (select p1.node_id
          from WS_PROCESS p1
         where p1.role_id =
               (select max(p2.role_id)
                  from WS_PROCESS p2
                 where p2.node_id in ( SELECT SUBSTR(throughnodes,0,INSTR(throughnodes,,)-1) FROM ws_team_information
  UNION
  SELECT SUBSTR(throughnodes,INSTR(throughnodes,,,1,ROWNUM)+1,5)
  FROM ws_team_information
  CONNECT BY ROWNUM<=LENGTH(throughnodes)-LENGTH(REPLACE(throughnodes,,,‘‘))))) 
   and s.operat_orgtype = review

-----------------------------------------最终版---------------------------------------------
select m1.id, m2.pzTime
  from (select t.id,
               substr(t.team_id, 2, 4) as a,
               substr(t.team_id, 7, 4) as b,
               t.throughnodes,
               d.name as team_type_text
          from WS_TEAM_INFORMATION t
          left join DICT d
            on t.team_type = d.code) m1
  left join

 (select s.bizdata_id, max(s.operat_time) as pzTime
    from ws_state_record s
   where s.status =
         (select p1.node_id
            from WS_PROCESS p1
           where p1.role_id =
                 (select max(p2.role_id)
                    from WS_PROCESS p2
                   where p2.node_id in
                         (SELECT SUBSTR(throughnodes,
                                        0,
                                        INSTR(throughnodes, ,) - 1)
                            FROM ws_team_information
                          UNION
                          SELECT SUBSTR(throughnodes,
                                        INSTR(throughnodes, ,, 1, ROWNUM) + 1,
                                        5)
                            FROM ws_team_information
                          CONNECT BY ROWNUM <=
                                     LENGTH(throughnodes) -
                                     LENGTH(REPLACE(throughnodes, ,, ‘‘)))))
     and s.operat_orgtype = review
   group by s.bizdata_id) m2
    on m1.id = m2.bizdata_id
View Code

嘻嘻

一个很变态的SQL

标签:replace   review   alt   proc   union   instr   gif   stat   str   

原文地址:http://www.cnblogs.com/chuanqiMa/p/6956329.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!