如何仅根据字段中的某些条件选择项目ID [英] How do I select Item ids based on some condition in field only

查看:68
本文介绍了如何仅根据字段中的某些条件选择项目ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL 2008中我想根据一些标准选择项目数量。问题我的数据库很大,所以我得到了数千行,但我希望它在这样的一个字段中

假设我得到项目ID 1,2,3,56,60,61,62,63,64,65,66,67,68,69,70,90,91,92,93,121,123,...... br />
我希望这应该如下

1-3,56,60-70,90-93,121,123,......

这里

每当序列是他们的项目ID时,它应该显示第一个项目ID -

和最后一个项目ID。



请帮助我这个

感谢advanc

IN SQL 2008 I want to select the number of items based upon some criteria.The problem my data base is huge so I am getting thousand of rows, But I want it in one field like this
suppose I am getting Item Ids 1,2,3,56,60,61,62,63,64,65,66,67,68,69,70,90,91,92,93,121,123,....
I want this should be as follows
1-3,56,60-70,90-93,121,123,......
Here
Whenever sequence is their in item ids, it should display first item id with "-"
and last item id.

Kindly help me on this
Thanks in advanc

推荐答案

与上次相同的答案。



根据您的评论,我认为在cte中选择您的数据然后将其视为您想要找到岛屿的列表,将会有所帮助。





[ ^ ]



是关于寻找岛屿的精彩文章。我不明白这与你原来的问题有什么关系。



[ ^ ]



涵盖选择单个字符串的范围。你想要的是一个有点疯狂的IMO。最好在代码中执行此操作。
Same answer as last time.

Based on your comments, I think selecting your data in a cte and then treating it like a list you want to find islands in, will help.


[^]

Is a great article on finding islands. I don't see how this relates to your original question.

[^]

Covers selecting a range to a single string. What you want is a little crazy IMO. Your better off doing this in code.


这篇关于如何仅根据字段中的某些条件选择项目ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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