zoukankan      html  css  js  c++  java
  • 一个很变态的SQL

    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

    嘻嘻

    part2.

    SELECT T1.A ,T1.B,T2.C
    FROM T1,T2
    WHERE T1.A = T2.A
    UNION
    (
    SELECT T1.A,T1.B,'' FROM T1
    MINUS 
    SELECT T2.A,T2.C,'' FROM T2
    )
    UNION
    (
    SELECT T2.A,'',T2.C FROM T2
    MINUS 
    SELECT T1.A,'',T1.B FROM T1
    )
    View Code

     part3.

    关于对表数据的查重SQL

    select a,count(a) from tablename order by a having count(a)>1

    SELECT 字段名, COUNT(*) AS Expr1
    FROM 表名
    GROUP BY 字段名

    HAVING COUNT(*) >1

  • 相关阅读:
    PS制作动感酷炫水人街舞照
    PS调出水彩画效果古装人物照片
    PS调出怀旧雨中特写的非主流照片
    PS制作墙壁上海报卷页图片效果
    PS绘制扁平化风格相机镜头UI图标
    PS调出甜美艺术外景女生照片
    PS调出冷绿色电影画面风格
    PS调出通透唯美阳光外景女生照片
    PS调出唯美冷色情侣婚纱写真照
    c#类中字段和方法中变量的声明问题
  • 原文地址:https://www.cnblogs.com/chuanqiMa/p/6956329.html
Copyright © 2011-2022 走看看