sql 中对分组的信息进行聚合。(sql server 2005)
2010-08-20 11:50
337 查看
代码with t as(
select 1 id, 'Child1' child
union
select 1 id, 'Child2'
union
select 1 id, 'Child3'
union
select 2 id, 'Child1'
union
select 2 id, 'Child2'
)
select id, stuff((select ','+child
from t a
where b.id = a.id
for xml path('')),1,1,'') children
from t b group by id
select 1 id, 'Child1' child
union
select 1 id, 'Child2'
union
select 1 id, 'Child3'
union
select 2 id, 'Child1'
union
select 2 id, 'Child2'
)
select id, stuff((select ','+child
from t a
where b.id = a.id
for xml path('')),1,1,'') children
from t b group by id
相关文章推荐
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
- SQL SERVER 2005中使用sql语句对xml 文件和其数据的进行操作(很全面)
- 【原】获取数据库(SQL SERVER 2005)的所有信息 Get all database information from SQL Server 2005 测试通过【想写基于数据库代码生成器可参考】
- SQL SERVER 2005 无法使用SQL SERVER MANAGERMET STUDIO 登陆(原因是没有使用默认端口进行远程连接所造成的)
- 教你如何在 sql server 2005 使用 sql 语句获取字段的说明信息
- 在数据库中 如何进行分类分组并总计SQL信息(转载)
- SQL Server Compact 与 SQL Server 2005 通过远程访问进行数据同步
- 取得SQL Server 2005各表、字段的说明等信息的SQL语句
- SQL Server 2005学习笔记⑦- 分页(按分组进行分页)
- sql 无法打开 :"在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) "
- 在SQL Server 2005中使用Try…Catch块进行T-SQL错误处理
- SQL 数据库 学习 028 查询-11 having --- 对分组之后的信息进行过滤
- (转)在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
- 【原】获取数据库(SQL SERVER 2005)的所有信息 Get all database information from SQL Server 2005 测试通过
- SQL语句查看列详细信息Sql Server 2005
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
- 【杂谈】在XP下安装SQL 2005开发版时出现:SQL Server 安装程序无法获取 ASPNET 帐户的系统帐户信息
- 错误:在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错) 解
- SQL Server 2005中的T-SQL增强
- Visual C# 2008+SQL Server 2005 数据库与网络开发-- 9.3 XML相关的SQL语句使用