SQL does not display repeated columns

Source: Internet
Author: User

In the report, basically can be repeated information does not show, in SQL How to achieve such as the following circumstances?

A10a20b30b40b50
Shown as:

a1020b304050

SQL such as the following:

CREATE TABLE #a (part varchar (ten), price int) Goinsert into #a values (' A ', ten) insert into #a values (' a ', ") insert into #a val UEs (' B ', +) insert into #a values (' B ', +) insert into #a values (' B ', h) goselect * from #ago Select ", MIN (Price)  To #b the from #a the group by part goselect * FROM #a a select * from #bgo a Select Case when price in  (select Price from #b) Then part else "end, price from  #a  go  

References: http://bbs.csdn.net/topics/310112824

Main content:

Programme one:

If OBJECT_ID (' [tab] ') is not null drop table [tab]create table [tab] ([unit] varchar (6), [name] varchar (4), [Education] varchar (4)) Inser t [tab]select ' one workshop ', ' Zhang San ', ' undergraduate ' union allselect ' one workshop ', ' John Doe ', ' undergraduate ' union allselect ' one workshop ', ' Harry ', ' undergraduate ' union allselect ' two workshops ', ' The ' Kings ', ' Specialist ' Union allselect ' II workshop ', ' Liu Yi ', ' specialist ' select unit, name, education from (select unit, name = (select top 1 name from tab where TA. unit = Unit and TA.) Education), education, s1=0,s2= Unit, s3=0 from tab TA Group by Unit, Education Union Allselect '  , Name, ', s1=0,s2= unit, s3=1 from  tab TB where
    name <> (select top 1 name from tab where TB. Units = units and TB. Education = education)) Torder by s1,s2,s3/* unit     name   Education   ----------- ---Two workshop   of the Liu of the first workshop    Zhang San   undergraduate    John Doe    Harry   (the number of rows affected is 5) */   

Scenario Two:

Select name into #temp from (SELECT [Unit],max (name) as name from [Tab]group by [unit]) Tselect case when name in (SELECT * from #temp) then [unit] Else ' end, name, case when name in (SELECT * from #temp) then [education] Else ' endfrom [tab]




SQL does not display repeated columns

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.