Home > Database > Mysql Tutorial > 合并单表中某两行具有相同内容的数据

合并单表中某两行具有相同内容的数据

WBOY
Release: 2016-06-07 14:57:25
Original
1827 people have browsed it

合并单表中某两行具有相同内容的数据,变成一行数据来显示。 现为合并p1,p2字段的值。 createtabletest ( p1varchar(10), p2varchar(10), p3varchar(10), p4varchar(10), p5varchar(10) ) 无 (select aaa.p1, bbb.p2, aaa.p3, aaa.p4, aaa.p5 from (select RO

合并单表中某两行具有相同内容的数据,变成一行数据来显示。

现为合并p1,p2字段的值。

create table test
(
      p1 varchar(10),
      p2 varchar(10),
      p3 varchar(10),
      p4 varchar(10),
      p5 varchar(10)
)
(
select aaa.p1, bbb.p2, aaa.p3, aaa.p4, aaa.p5
  from (select ROW_NUMBER() OVER(ORDER BY ppp.p3) as RowNumber1, ppp.*
          from test ppp
         where ppp.p2 is null) aaa,
       (select ROW_NUMBER() OVER(ORDER BY qqq.p3) as RowNumber1, qqq.*
          from test qqq
         where qqq.p1 is null) bbb
 where
  (aaa.p3 = bbb.p3 and aaa.p4 = bbb.p4)
 ) 
union all
( 
      select * from test where (p3,p4) not in (select p3,p4 from test group by p3,p4 having count(*)>1)
) 
Copy after login
合并单表中某两行具有相同内容的数据 合并单表中某两行具有相同内容的数据
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template