当前位置:操作系统 > Unix/Linux >>

多行数据拼接成一条数据后再与其他表做左外连接

多行数据拼接成一条数据后再与其他表做左外连接
 
B表中除ID跟最后一个字段值不一样外,其他字段都是一样的,现在将重复的几条数据拼接成同一条数据并以逗号隔开,再用A表与查询的结果做左外连接。
 
[html] 
select yh.id, yh.xm, yh.jh, qy.ssfxj, qy.sspcs, qy.sssq  
  from T_YWCJ_YH yh  
  left join (select yhssqy.jh,  
                    yhssqy.xm,  
                    yhssqy.ssfxj,  
                    yhssqy.ssfxjdm,  
                    yhssqy.sspcs,  
                    yhssqy.sspcsdm,  
                    substr(catstr(yhssqy.sssq),  
                           2,  
                           length(catstr(yhssqy.sssq))) sssq  
               from T_YWCJ_YH_SSQY yhssqy  
              group by yhssqy.jh,  
                       yhssqy.xm,  
                       yhssqy.ssfxj,  
                       yhssqy.ssfxjdm,  
                       yhssqy.sspcs,  
                       yhssqy.sspcsdm) qy  
    on yh.jh = qy.jh  
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,