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

推荐订阅源

Martin Fowler
Martin Fowler
Jina AI
Jina AI
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
I
InfoQ
L
LangChain Blog
The Cloudflare Blog
IT之家
IT之家
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
博客园 - 聂微东
美团技术团队
博客园_首页

博客园 - 落叶潇潇雨

Can't get WebApplicationContext object from ContextRegistry.GetContext(): Resource handler for the 'web' protocol is not defined xml序列化与反序列化 Asp.net 导出Excel How to debug Typescript in browser log4net使用的关键点 DataContractSerializer序列化与反序列化遇到的奇怪问题 图文安装Windows Template Library - WTL Version 9.0 WCF的传输安全(读书笔记) Asp.net mvc 各个组件的分离 同程旅游网开放平台SDK开发完成 csdn回到顶端 Timer的schedule和scheduleAtFixedRate方法的区别解析 android 主线程和子线程之间的消息传递 activity生命周期 瀑布流插件 CSS自适应宽度圆角按钮 ajaxFileUpload上传文件和表单数据 Ajax上传表单数据和文件 使用Rhino Mocks
SQL多行变一列
落叶潇潇雨 · 2013-08-01 · via 博客园 - 落叶潇潇雨

CREATE TABLE DEPT

(DeptNo INT IDENTITY(1, 1)NOT NULL ,

 Country VARCHAR(50) ,

 Location VARCHAR(50) NULL

)

SET IDENTITY_INSERT DEPT ON

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 1, 'User1', 'A' )

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 2, 'User1', 'B' )

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 3, 'User2', 'C' )

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 4, 'User2', 'D' )

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 5, 'User2', 'E' )

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 6, 'User3', 'F' )

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 7, 'User3', 'G' )

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 8, 'User3', 'H' )

INSERT  DEPT( DeptNo, Country, Location )VALUES  ( 9, 'User3', 'I' )

SET IDENTITY_INSERT DEPT OFF

--按某一列出结果的

SELECT  B.Country ,LEFT(Location, LEN(Location) - 1) AS list

FROM    ( SELECT    Country ,

                            ( SELECT Location + ',' FROM DEPT WHERE Country = A.Country ORDER BY  DeptNo FOR XML PATH('')

                            ) AS Location

          FROM DEPT A GROUP BY  Country

        ) B