惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
V
Visual Studio Blog
P
Privacy International News Feed
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
Webroot Blog
Webroot Blog
T
Threatpost
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
小众软件
小众软件
L
LINUX DO - 最新话题
C
Cisco Blogs
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
酷 壳 – CoolShell
酷 壳 – CoolShell
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
G
GRAHAM CLULEY
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
罗磊的独立博客
V
V2EX
博客园 - Franky
P
Proofpoint News Feed
SecWiki News
SecWiki News
腾讯CDC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)
S
Secure Thoughts
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题

博客园 - 潘伟

linux下快速查找文件大全 终于明白vi的用法了 什么是虚拟主机,为什么要使用虚拟主机? 一个存储前辈的一些业界知识(待了解) 10秒为任意数据库增加执行日志功能 - 潘伟 - 博客园 运动会的收获 从无奈到偷笑 一曲彩虹天堂 使用sql server中的全文索引经过大体的4个步骤 索引的创建 匹配符详解 数据库中的正则表达试 系统表的应用 使用SQLServer2000 发送邮件详细配置过程 求记录中的最新数据的方法! 关于sql mail的配置问题(微软技术支持) 数据库设计范式深入浅出 锁定数据库的一个表_概述 约束的使用
经常遇到的字段合并的问题
潘伟 · 2005-12-05 · via 博客园 - 潘伟

有表內容﹕
編號 內容
A    abc
A    aaa
A    dddd
B    1223
B    fkdjfd
....

實現結果﹕
A   abc,aaa,dddd
B   1223,fkdjfd
要求用一條SQL實現﹐如﹕select sum(內容) from table group by 編號

--该问题,写一个合并函数,后,分组合并既可!

--测试数据
create Table 表(編號 varchar(20),內容 varchar(20))
insert 表 select 'A','abc'
union all select 'A','aaa'
union all select 'A','dddd'
union all select 'B','1223'
union all select 'B','fkdjfd'


--处理分组合并函数学
Create Function JoinStr(@SNO as varchar(20))
returns varchar(200)
begin
declare @s as varchar(8000)
set @s=''
select @s=@s+','+ltrim(rtrim(內容)) from
(
select 內容 from 表 where 編號=@SNO
)
A
set @s=stuff(@s,1,1,'')
return  @s
end

--查询语句
select 編號,dbo.JoinStr(編號) as 内容 from 表 group by 編號

--测试结果:
編號     内容
A abc,aaa,dddd
B 1223,fkdjfd

======用SQL解决方法:

table1: News
-----------------------------------------------------------
rsid     title     subject     class
1        天空蓝了  ....        小学文章
-----------------------------------------------------------


table2: ModifyLogs
-----------------------------------------------------------
rsid     NewsID    Name        Memo
1        1         张三        有一些错别字,还需要修改
2        1         张四        成语和一些词语用错
-----------------------------------------------------------

我现在需要用一条语名查询出这样的结果
-----------------------------------------------------------
Unid    Title        subject   Class        Name
1       天空蓝了     .....     小学文章     张三,张四

-----------------------------------------------------------
就是说把只要是修改了该文章的老师的名称显示在一个字段中.....
请问如何实现......


declare @tname varchar(4000)
set @tname=''
select @tname=@tname +rtrim(b.Name)+',' from ModifyLogs b left join News a on a.rsid=b.NewsID
set @tname=left(@tname,len(@tname)-1)
print @tname

select distinct a.rsid as Unida,a.Title,a.subject,a.Class,@tname as name from News a
left join ModifyLogs b on a.rsid=b.NewsID