oralce写法: select WM_CONCAT(A.title) as citys from tmpcity A sql server写法: select stuff((select ','+A.title from tmpCity A FOR xml PATH('')), 1, 1, '') as citys MySQL写法: select GROUP_CONCAT(A.title) as citys from tmpcity A; --默认的逗号分隔 select GROUP…
使用过SQL Server 2000的人都知道,要想实现行列转换,必须综合利用聚合函数和动态SQL,具体实现起来需要一定的技巧,而在SQL Server 2005中,使用新引进的关键字PIVOT/UNPIVOT,则可以很容易的实现行列转换的需求. 在本文中我们将通过两个简单的例子详细讲解PIVOT和UNPIVOT的用法. PIVOT是行转列,用法如下: 假如表结构如下: id name quarter profile 1 a 1 10…
方法一:创建合并列函数 -------创建一个方法---------- CREATE FUNCTION dbo.Role_Name(@AdminID int) ) AS BEGIN ) SET @r = '' SELECT @r = @r + '/' +Role FROM (select a.AdminID,d.Role from r b inner join PA a on a.RenShiID=b.id inner join Role c on a.AdminID=c.adminID inn…