现在有两个整数 a 和b,要判断a除以b在那个区间 ,如果 小于三分之一就等于a的三分之一,如果大于三分之一而小于等于三分之二就等于a的三分之二,其他情况为acase when a/b<1/3 then a/3 when 1/3<a/b<2/3 then a/3*2 else a end 这样写又不行,得怎么写好??
case when a/b <1/3 then a/3 when 1/3 <a/b and a/b<2/3 then a/3*2 else a end
1<a<3改成1<a and a<3就对了
case when a/b*1.0000 <1/3 then a/3*1.0000 when 1/3 <a/b <2/3 then a/3*2 else a end 1/3 <a/b AND a/b <2/3 这也只能这样吧感觉这样比较不行
declare @a int,@b int set @a=1 set @b=2 select case when @a/@b <1/3 then @a/3 when 1/3 <@a/@b and @a/@b <2/3 then @a/3*2 else @a end /*----------- 1(1 行受影响)*/
1/3 <a/b <2/3 --> 1/3 <a/b and a/b <2/3
case when cast(a as dec(18,2))/b <1./3 then cast(a as dec(18,2))/3 when 1./3 <cast(a as dec(18,2))/b <2./3 then cast(a as dec(18,2))/3*2 else a end
case when cast(a as dec(18,2))/b <1./3 then cast(a as dec(18,2))/3 when 1./3 <cast(a as dec(18,2))/b and cast(a as dec(18,2))/b <2./3 then cast(a as dec(18,2))/3*2 else a endmodify
case when 3*a<=b then a/3. when 3*a>2*b then a else 2*a/3. end测试: Select case when 3*a<=b then a/3. when 3*a>2*b then a else 2*a/3. end From (Select 5 As a,10 As b) t
set @a=1
set @b=2
select case
when @a/@b <1/3 then @a/3
when 1/3 <@a/@b and @a/@b <2/3 then @a/3*2
else @a end
/*-----------
1(1 行受影响)*/
Select case when 3*a<=b then a/3. when 3*a>2*b then a else 2*a/3. end From (Select 5 As a,10 As b) t