The number of times that record duplication is processed. A is used for repeat once, followed by B, followed ....

Source: Internet
Author: User

The number of times record duplication is processed. Second, use B , In turn ....-- Create Table # TESTA (col1 varchar (10), col2 int, col3 varchar (20) insert into # testaselect '123', 1, 'adsf 'Union allselect '123', 2, 'sdfs' Union allselect '123', 3, 'tyuio 'Union allselect '123', 1, 'dfgg 'Union allselect '123', 1, 'sdfg' Union allselect '123', 2, 'vbmv' Union allselect '123', 3, 'tuyi' Union allselect '000000', 4, 'dfhfgh' Union allselect '000000', 1, 'ert 'Union allselect '000000', 2, 'hjkj 'Union allselect' 222 ', 1, 'sdfg' Union allselect '000000', 2, 'vbm' Union allselect '000000', 3, 'tuyi' Union allselect' 111 ', 1, 'ppp' -- Test -- creates a virtual table of strings for special processing of select top 26 identity (INT, 65,1) asciiidinto # asciiidfrom sysobjects A, sysobjects B -- create an automatic incremental copy select *, identity (INT, 1, 1) TID into # testaa from # Testa -- the number of times that duplicate values are obtained in ascending order *, (select count (*) from # testaa B where. col1 = B. col1 and. col2 = B. col2 and B. TID <=. TID group by B. col1, B. col2) doubletimefrom # testaa A -- test and query select C. col1, C. col2, C. col1 + isnull (D. asciichar, '') newcol1from (select *, (select count (*) from # testaa B where. col1 = B. col1 and. col2 = B. col2 and B. TID <=. TID group by B. col1, B. col2) doubletime from # testaa A) cleft join (select char (asciiid) asciichar, AsciiID-63 TID from # asciiid) Don C. doubletime = D. TID -- order by C. col1 -- display result/* col1 col2 newcol1111 1 111111 2 111111 3 111112 1 112222 1 222222 2 222222 3 222200 4 200111 1 111a111 2 111a222 1 222a222 2 222a222 3 222a111 1 111b */-- delete test environment drop table # testaddrop table # testaaddrop table # asciiid

 

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.