比较2个输入数字是否在2列范围内

时间:2019-11-21 06:35:00

标签: sql-server

我有ff表。

系列

julia> res       = [map(k->str2id_dic[k],x) for x in str_res]
15-element Array{Array{T,1} where T,1}:
 [4, 5, 6]           
 [7, 8, 9]           
 [10, 11, 12, 13, 14]
 Any[]               
 Any[]               
 Any[]               
 Any[]               
 Any[]               
 Any[]               
 Any[]               
 Any[]               
 Any[]               
 Any[]               
 [15]                
 Any[] 

和2个输入

startno | endno
1       | 99

我想选择我的2个输入在表中的输入范围内。

3 个答案:

答案 0 :(得分:1)

尝试一下。

SELECT * 
FROM Your_Table 
WHERE (StartNo BETWEEN @inputstart AND @inputend) OR (endno BETWEEN @inputstart AND @inputend)

如果您希望输入之间位于哪一列,请尝试一下。

SELECT MAX(CASE WHEN StartNo BETWEEN @inputstart AND @inputend THEN StartNo 
                WHEN endno BETWEEN @inputstart AND @inputend THEN endno END)
FROM Your_Table 

答案 1 :(得分:0)

尝试

declare @inputstart int = 2, @inputend int = 100;

with cte as (
select 1 as startno, 99 as endno
) select * from cte where @inputstart between startno and endno
    and @inputend between startno and endno

答案 2 :(得分:0)

假设我们已经创建了一个临时表

   Tower  Floor Unit Index
0      1    1.0    A   1A1
1      1    1.0    B   1B1
2      1    1.0    C   1C1
3      1    1.0    D   1D1
4      1    1.0    E   1E1
5      1    1.0    F   1F1
6      1    1.0    G   1G1

然后我们将所有记录插入到临时表中 例如1至100

CREATE TABLE #DeleteMe(startNo INT , endNo INT )

/ *这是您想要的开始主要部分。...* /

;WITH nums AS
   (SELECT 1 AS startNo,1 AS endNo  
    UNION ALL
    SELECT startNo + 1 AS startNo,endNo + 1 AS endNo
    FROM nums
    WHERE nums.startNo <= 99)

INSERT INTO #DeleteMe
SELECT *
FROM nums