我需要SQL帮助>!< SQL查询 [英] i need SQL HELP>!< sql query
问题描述
我有这个数据的表格
ID NUM
1 1
2 4
3 5
4 6
5 7
6 10
7 3
8 5
9 9
10 11
12 13
现在我想查询如何将返回此冒号
ID Num
2 4
5 7
10 11
11 12
我需要返回的是第一个和最后一个数字的数字如何在数组中/>
exp。如果我们有3 5 6 7 8 10我需要返回5和8
thnx很多帮助
看起来很相似: http: //www.xaprb.com/blog/2006/03/22/find-contiguous-ranges-with-sql/ [ ^ ]
首先制作一串Nums你想从sql中获取。
例如。
string Nums = 5,8;
sql查询如下所示
选择 * 来自 tbl 其中 Num in ( 5 跨度>,8)
等价C#代码
< pre lang =c#> cmd.commandtext = 从tbl中选择*其中Num in( + Nums + );
// 其中'Nums'是可变的,包含以逗号分隔的所选数字列表
快乐编码!
:)
i have tabel with this data
ID NUM
1 1
2 4
3 5
4 6
5 7
6 10
7 3
8 5
9 9
10 11
12 13
now i wanna query how will return this colons
ID Num
2 4
5 7
10 11
11 12
12 13
that what i need to return is the first and last number of numbers how are in array
exp. if we have 3 5 6 7 8 10 i need the return the 5 and 8
sorry for my bad english
thnx alot for help
This looks alike: http://www.xaprb.com/blog/2006/03/22/find-contiguous-ranges-with-sql/[^]
first make a string of Nums u want to fetch from sql.
eg.
string Nums = "5,8";
sql query is like below
select * from tbl where Num in (5,8)
equivalent C# code
cmd.commandtext = "select * from tbl where Num in (" + Nums + ")"; // where 'Nums' is variable having list of selected numbers separated by comma
Happy Coding!
:)
这篇关于我需要SQL帮助>!< SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!