2014-05-19 72 views
-1

我有如下数据结构的数据..查找一行数据的范围SQL

_ID    _BEGIN   _END  
    7003   99210   99217   
    7003   10225   10324  
    7003   111111 

如果我得到10323作为输入,我怎么觉得返回第2行,因为数10323是10225(_begin)之间关系10324(_END)?

如果我得到111111作为输入将查询返回第3行,请问工作?

回答

2
select * from your_table 
where @input between _begin and _end 
0

如果_begin和_end可以为空:

select * 
from your_table 
where @input between coalesce(_begin,@input) and coalesce(_end,@input)