我做如下查询
select a.a1/b.b1
from a,b但如b1为0就会报错,如何做 能使得  如果B1为0,则查询结果为0

解决方案 »

  1.   

    select case b.b1 when 0 then 0 else a.a1/b.b1 end result
    from a,b
      

  2.   

    SELECT 
    case when b.b1=0 then 0 else a.a1/b.b1 end
    FROM a,b
      

  3.   

    access版本:select iif(b.b1=0,0,a.a1/b.b1) as result from a,b
      

  4.   

    SELECT 
    case when (a.a1=0) and (b.b1=0) then 0 
         when (a.a1<>0) and (b.b1=0) then 0
         else a.a1/b.b1 end
    FROM a,b
      

  5.   

    select case b.b1 when 0 then 0 else a.a1/b.b1 end result
    from a,b
      

  6.   

    SELECT 
    case when (a.a1<>0) and (b.b1<>0) then a.a1/b.b1
         else 0
         end
    FROM a,b