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