Merge data with the same content in two rows in a single table

Source: Internet
Author: User
Merge the data of two rows in a single table with the same content into one row for display. The value of the merge p1 and p2 fields. Createtabletest (p1varchar (10), p2varchar (10), p3varchar (10), p4varchar (10), p5varchar (10) None (selectaaa. p1, bbb. p2, aaa. p3, aaa. p4, aaa. p5from (selectRO

Merge the data of two rows in a single table with the same content into one row for display. The value of the merge p1 and p2 fields. Createtabletest (p1varchar (10), p2varchar (10), p3varchar (10), p4varchar (10), p5varchar (10) None (select aaa. p1, bbb. p2, aaa. p3, aaa. p4, aaa. p5 from (select RO

Merge the data of two rows in a single table with the same content into one row for display.

The value of the merge p1 and p2 fields.

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)) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.