玩转SQLSERVER:探索ListAGG的强大功能
I’m trying to aggregate a ‘STRING’ field in SQLServer. I would like to find the same function LISTAGG like in Oracle .
Do you know how to do the same function or an another method?
For Example,
Field A | Field B
1 | A
1 | B
2 | A
And I would like that the result of this query will be
1 | AB
2 | A
解决方案
Starting in SQL Server 2017 the STRING_AGG function is available which simplifies the logic considerably:
select FieldA, string_agg(FieldB, ‘’) as data
from yourtable
group by FieldA
See SQL Fiddle with Demo
In SQL Server you can use FOR XML PATH to get the result:
select distinct t1.FieldA,
STUFF((SELECT distinct ‘’ + t2.FieldB
from yourtable t2
where t1.FieldA = t2.FieldA
FOR XML PATH(’’), TYPE
).value(’.’, ‘NVARCHAR(MAX)’)
,1,0,’’) data
from yourtable t1;
See SQL Fiddle with Demo
推荐阅读
-
玩转Oracle函数:探索LISTAGG的强大功能
-
玩转SQLSERVER:探索ListAGG的强大功能
-
玩转Oracle函数:探索LISTAGG的强大功能
-
玩转MySQL数据库:探索Cursor的强大功能
-
玩转开源硬件!探索多功能FPGA-JTAG的无限可能
-
玩转数据世界:探索eCharts的极坐标图功能
-
【摩尔线程+Colossal-AI强强联手】MusaBert登上CLUE榜单TOP10:技术细节揭秘 - 技术实力:摩尔线程凭借"软硬兼备"的技术底蕴,让MusaBert得以从底层优化到顶层。其内置多功能GPU配备AI加速和并行计算模块,提供了全面的AI与科学计算支持,为AI推理和低资源条件下的大模型训练等场景带来了高效、经济且环保的算力。 - 算法层面亮点:依托Colossal-AI AI大模型开发系统,MusaBert在训练过程中展现出了卓越的并行性能与易用性,特别在预处理阶段对DataLoader进行了优化,适应低资源环境高效处理海量数据。同时,通过精细的建模优化、领域内数据增强以及Adan优化器等手段,挖掘和展示了预训练语言模型出色的语义理解潜力。基于MusaBert,摩尔线程自主研发的MusaSim通过对比学习方法微调,结合百万对标注数据,MusaSim在多个任务如语义相似度、意图识别和情绪分析中均表现出色。 - 数据资源丰富:MusaBert除了自家高质量语义相似数据外,还融合了悟道开源200GB数据、CLUE社区80GB数据,以及浪潮公司提供的1TB高质量数据,保证模型即便在较小规模下仍具备良好性能。 当前,MusaBert已成功应用于摩尔线程的智能客服与数字人项目,并广泛服务于语义相似度、情绪识别、阅读理解与声韵识别等领域。为了降低大模型开发和应用难度,MusaBert及其相关高质量模型代码已在Colossal-AI仓库开源,可快速训练优质中文BERT模型。同时,通过摩尔线程与潞晨科技的深度合作,仅需一张多功能GPU单卡便能高效训练MusaBert或更大规模的GPT2模型,显著降低预训练成本,进一步推动双方在低资源大模型训练领域的共享目标。 MusaBert荣登CLUE榜单TOP10,象征着摩尔线程与潞晨科技联合研发团队在中文预训练研究领域的领先地位。展望未来,双方将携手探索更大规模的自然语言模型研究,充分运用上游数据资源,产出更为强大的模型并开源。持续强化在摩尔线程多功能GPU上的大模型训练能力,特别是在消费级显卡等低资源环境下,致力于降低使用大模型训练的门槛与成本,推动人工智能更加普惠。而潞晨科技作为重要合作伙伴,将继续发挥关键作用。
-
感恩毕业:玩转89C51单片机的GPIO功能探索
-
探索MySQL 8的强大功能:utf8mb4解锁多语言数据新世界(简化版)
-
Dotnet 工具包]探索 LiveCharts2:功能强大的跨平台图表库