在SQL中可能吗? [英] Is it Possible in SQL ?

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

问题描述



我收集了以逗号分隔的数字。

例如: -

1,2,3,1,1 ,2,2,3,3,3,3,3,3,3,555



需要在SQL中编写脚本,返回结果如1,2 ,3,4,5我的意思是从这个数字集合中选择不同的数字而不将它们插入表格。







任何答案都将不胜感激。

Hi,
I have collection of comma separated numbers.
For ex:-
1,2,3,1,1,2,2,3,3,3,3,3,3,3,4,555

Need to write script in SQL which will return result like 1,2,3,4,5 I mean select the distinct numbers from this number collection without inserting them into tables.



Any answer would be appreciated.

推荐答案

你可以这样做:



You could do this:

DECLARE @nums varchar(max)
DECLARE @comma char(1)
DECLARE @xml xml

SELECT @nums = '1,2,3,1,1,2,2,3,3,3,3,3,3,3,4,5,5,5'
SELECT @comma = ','

SELECT @xml = CONVERT(xml,'<r><n>' + REPLACE(@nums,@comma,'</n><n>') + '</n></r>')

SELECT DISTINCT [Value] = X.num.value('.','int')
FROM @xml.nodes('/r/n') X(num)
ORDER BY [Value]


http://lmgtfy.com/?q=SQL+select+distinct+syntax [ ^ ]


这篇关于在SQL中可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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