表内容大概如下:
firstnumber,lastnumber,id
10000000 20000000 1
20000001 29999999 2
问:如何查询10000001---19999999 这个范围在以上范围。
是做判断的,如果所举例子的范围是在表中有交集,则不能被插入。
firstnumber,lastnumber,id
10000000 20000000 1
20000001 29999999 2
问:如何查询10000001---19999999 这个范围在以上范围。
是做判断的,如果所举例子的范围是在表中有交集,则不能被插入。
--
select * from tb where firstnumber<10000001 and lastnumber>19999999
1 460099093170001 460099093170005
2 460099093170006 460099093170010
3 460029834290000 460029834290001
4 111111111111111 222222222222228
5 333333333333333 444444444444444
6 111111111111109 111111111111110
7 444444444444445 555555555555555
在页面输入一个范围,而该范围如果在以上范围内,则不能被插入。请问如何写啊
declare @b int
select @b=1 from tb where firstnumber>=10000001 and lastnumber<=19999999
if(@b=1)
begin
print '不能插入'
end
else
begin)
insert into 表名(列名) values (值)
end
declare @max bigint
declare @min1 bigint
declare @max1 bigint
select @max1=max(firstnumber),id from tb group by id
select @min1=max(firstnumber),id from tb group by id
select @max2=max(lastnumber),id from tb group by id
select @max1=max(lastnumber),id from tb group by id
if @min1<=@min2 and @max1<=@max2
set @min=@min1
set @max=@max2
.....................
insert tb(firstnumber,lastnumber)
select @a,@b
where not exists
(select 1 from tb
where (@a<=firstnumber and @b>=firstnumber)
or (@a>=firstnumber and @a<=firstnumber)