想问一下怎么处理SQL语句中除0啊,想用SQL语句来,不是程序中的异常`高手指教
就比如select a/d from table_a

解决方案 »

  1.   

    select a/d 
    from table_a
    where d<>0
      

  2.   

    --分开来处理就好啦
    select a/d from table_a where d<>0
    union all 
    select 0 from table_a where d=0
      

  3.   

    或者
    select case d when 0 then 0 else a/d end from table_a
      

  4.   

    不好意思了,刚才出去了,我意思是比哪表中有两个字段 a b
    想要select a/b from table 
    如果b=0的话,我就给他从新给一个字的话,要怎么写SQL啊