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

推荐订阅源

J
Java Code Geeks
小众软件
小众软件
博客园 - 叶小钗
宝玉的分享
宝玉的分享
博客园_首页
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
Google DeepMind News
Google DeepMind News
U
Unit 42
F
Fortinet All Blogs
IT之家
IT之家
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 落叶潇潇雨

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