需要查询SQL Server 2000 [英] Need a query for sql server 2000

查看:95
本文介绍了需要查询SQL Server 2000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要在下面查询sql server2000.

表结构:

col1 Col2
1个
2 b
1 c
2天
1 e
3 f

输出应该是这样的:

col1 col2
1 a,c,e
2 b,d
3 f

Hi,

I need a query for below for sql server 2000.

table structure:

col1 Col2
1 a
2 b
1 c
2 d
1 e
3 f

Out put should be like this:

col1 col2
1 a,c,e
2 b,d
3 f

Help me on this.

推荐答案

也许我可以给你一个提示.
查看 [
http://stackoverflow.com/questions/273238/how-to-use-group-by-to-concatenate-strings-in-sql-server [> http://stackoverflow.com/questions/102317/how-to-get-multiple-records-against-one-record-on-relation [ ^ ]
Perhaps I can give you a hint.
Check out GROUP BY[^]. But you have to do a CONCAT of the value in "col2" in a GROUP BY.

http://stackoverflow.com/questions/273238/how-to-use-group-by-to-concatenate-strings-in-sql-server[^]

http://stackoverflow.com/questions/102317/how-to-get-multiple-records-against-one-record-based-on-relation[^]


尝试一下.
Try this.
SELECT   Col1, LEFT([Col2], LEN([Col2]) - 1) as [Col2]
           FROM  ( SELECT  DISTINCT Col1
                      FROM  tablename )  AS A

OUTER APPLY ( SELECT  RTRIM(B.Col2)  + ', '
                FROM  tablename B WHERE A.Col1 = B.Col1
                 FOR  XML PATH('') ) AS C ([Col2])


这篇关于需要查询SQL Server 2000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆