• 一段四表联查外加字符拼接的sql,留存备查


    select DISTINCT [P_ID],[P_CODE],[P_CODE_OLD],[P_NAME],[NATIVE_PLACE],[GENDER],[EDUCATION],[EMPLOY_DATE],[CITY],[IDENTITY_NUM],[OFFICE_NUM],[EMPLOY_TYPE],[P_TYPE],[PHONENO],[HOME_NUM],[DUTY],[BIRTHDAY],[EMAIL],[HOME_ADDR],[OFFICE_ADDR],[CREATER],[CREATE_TIME],[PHOTO],[UPDATER],[UPDATE_TIME],[REMARK],[FLAG],[CARD_NO],[ORG_ID],[ORG_NAME],[FACEFLAG],[FINGERFLAG],[CARDFLAG],[HIK_P_ID],[VEHICLE_PLATE] 
    from 
        (  
            SELECT  [P_ID],[P_CODE],[P_CODE_OLD],[P_NAME],[NATIVE_PLACE],[GENDER],[EDUCATION],[EMPLOY_DATE],[CITY],[IDENTITY_NUM],[OFFICE_NUM],[EMPLOY_TYPE],[P_TYPE],[PHONENO],[HOME_NUM],[DUTY],[BIRTHDAY],[EMAIL],[HOME_ADDR],[OFFICE_ADDR],[CREATER],[CREATE_TIME],[PHOTO],[UPDATER],[UPDATE_TIME],[REMARK],[FLAG],[CARD_NO],[ORG_ID],[ORG_NAME],[FACEFLAG],[FINGERFLAG],[CARDFLAG],[HIK_P_ID], 
            VEHICLE_PLATE=stuff
                               ( (SELECT ';'+VEHICLE_PLATE  FROM 
                                                               ( select t4.VEHICLE_PLATE, t2.* from 
                                                                                                  (select pv.VEHICLE_ID, t1.* from 
                                                                                                                                 ( select o.ORG_NAME,p.* from  T_DATA_PERSON p ,T_SYS_ORGANIZATION o 
                                                                                                                                   where 1=1 
                                                                                                                                   and p.ORG_ID = o.ORG_ID  
                                                                                                                                   and (p.FLAG is null or p.FLAG <> '1') 
                                                                                                                                   and p.UPDATE_TIME >= '2017/9/26 17:00:32' 
                                                                                                                                   and p.UPDATE_TIME <= '2017/10/26 17:00:32') t1
                                                                                                   left join T_DATA_PERSON_VEHICLE pv on t1.P_ID = pv.P_ID
                                                                                                   ) t2 
                                                                  left join (select * from T_DATA_VEHICLE v  where 1=1) t4 on t2.VEHICLE_ID = t4.VEHICLE_ID
                                                                ) tt  
                                  WHERE tt.P_ID=t.P_ID  FOR xml path('')), 1, 1, '') 
             FROM ( select t4.VEHICLE_PLATE, t2.* from 
                                                    ( select pv.VEHICLE_ID, t1.* from 
                                                                                    (select o.ORG_NAME,p.* from  T_DATA_PERSON p ,T_SYS_ORGANIZATION o 
                                                                                     where 1=1 
                                                                                     and p.ORG_ID = o.ORG_ID  
                                                                                     and (p.FLAG is null or p.FLAG <> '1') 
                                                                                     and p.UPDATE_TIME >= '2017/9/26 17:00:32' 
                                                                                     and p.UPDATE_TIME <= '2017/10/26 17:00:32') t1
                                                     left join T_DATA_PERSON_VEHICLE pv on t1.P_ID = pv.P_ID
                                                     ) t2 
                  left join (select * from T_DATA_VEHICLE v  where 1=1) t4 on t2.VEHICLE_ID = t4.VEHICLE_ID 
                 ) t
         ) x 
  • 相关阅读:
    工具:统计jQuery中各字符串出现次数
    读Ext之八(原生事件对象的修复及扩充)
    querySelector和getElementById通过id获取元素的区别
    读Ext之十(解析JSON)
    Safari/Chrome中placeholder属性实现不完整
    读Ext之十一(通过innerHTML创建元素)
    各浏览器中innerHTML实现差异(2)
    读Ext之五(Dom的低级封装)
    读Ext之十二(在各个位置插入元素)
    读Ext之四(事件的低级封装)
  • 原文地址:https://www.cnblogs.com/tlduck/p/7738046.html
Copyright © 2020-2023  润新知