SQL一列的合并连起来
2024-08-31 16:00:39
CREATE TABLE #temp(
ID INT,
name NVARCHAR(max),
age int,
address NVARCHAR(300)
)
insert into #temp
select
ID,
name =
(
stuff(
(select ',' + SN from #temp where ID = A.ID and age = A.age for xml path('')),
1,
1,
''
)
) ,
age,
address
from #temp as A group by A.age,A.ID,A.address
drop table #temp
原始数据 :
id | name | age |
address |
1 | 张三 | 20 | 北京 |
2 | 李四 | 21 | 北京 |
3 | 王五 | 20 | 北京 |
#temp数据结果:
id | name | age | address |
1 | 张三,王五 | 20 | 北京 |
2 | 李四 | 21 | 北京 |
最新文章
- 记录Castle ActiveRecord访问Sqlite的配置
- SqlServer与MySql的一些常用用法的差别
- 网页闯关游戏(riddle webgame)--SQL注入的潘多拉魔盒
- Java基础的一次总结
- Javascript屏蔽回车提交表单
- java使用POI jar包读写xls文件
- selenium python 环境搭建
- QT5控件-QDateTimeEdit和类QDateTime
- entity framework如何控制并发
- Java开发从初级到中级
- webService 客户端调用及异常信息First Element must contain the local name, Envelope , but found definitions
- Jmeter4.0分布式测试时启动Jmeter.server时报错
- Thirft简单使用
- cmd应用基础 扫盲教程
- Tomcat源码分析 -- Tomcat整体架构
- html DOM簡介
- Window对象属性
- java中System.currentTimeMillis()
- Python3 turtle安装和使用教程
- CommonHelper 公共类
热门文章
- ztree实现根节点右击事件,显示添加删除
- POJ 2607 Fire Station
- Python学习第二天-编写购物车
- hadoop-14-进行libtirpc的rpm包安装
- 怎样解除内容审查程序的password
- USACO Section 1.3 : Calf Flac (calfflac)
- nj03---阻塞和线程
- bzoj1934: [Shoi2007]Vote 善意的投票(显然最小割)
- CSS中关于vertical-align垂直对齐
- The evolution of cluster scheduler architectures--转