블로그 이미지
정홍주
Azure에 대한 내용뿐만 아니라 새로운 트렌드로 빅데이터, BI, SharePoint, 앱 등의 내용을 다룹니다.

calendar

        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

Notice

'String Group By'에 해당되는 글 1

  1. 2011.06.27 String Concat, String Group By
2011.06.27 08:52 SQL/T-SQL

커뮤니티에 약간 자주 String Concat, String Group By가 올라와서..,

 

USE AdventureWorks

GO

 

SELECT c.Name ID,  s.Name 

INTO #t

 FROM Production.ProductCategory c

JOIN Production.ProductSubcategory s ON c.ProductCategoryID=s.ProductCategoryID

 

 

SELECT * FROM #t

 

Bikes Mountain Bikes

Bikes Road Bikes

Bikes Touring Bikes

Components Handlebars

Components Bottom Brackets

Components Brakes

Components Chains

Components Cranksets

Components Derailleurs

Components Forks

Components Headsets

Components Mountain Frames

…..,

 

 

SELECT ID, STUFF(

     (SELECT  ',' + a.Name  AS [text()]

     from #t  a

     where a.ID = b.ID

     Order by a.Name

     for xml PATH('')),1,1,''   ) AS r

 from #t b

group by ID

ORDER BY ID


신고
posted by 정홍주
prev 1 next

티스토리 툴바