日期:2014-05-19  浏览次数:20425 次

关于查询的一个小问题 很简单的 只是偶忘了怎么写 明早送分
有一个表   TEMP   有2个字段   a,b  
我想这么查询     如果a   为空或0的话   则查询结果为b  
如果a   不为空或0的话   则结果为b/a  
要求用一个select   语句写出来。。。。。。。。。。

select   (when   a=0   then   b   when   a   is   null   then   b   else   b/a   )as   ttt   from   Temp      
大概就是这么个意思吧     反正我忘了怎么写了

不要笑偶太菜哦。。。。。。。。。。。。


------解决方案--------------------
Select Case When a = 0 Or A Is Null Then b Else b/a End As ttt From [Temp]
------解决方案--------------------
select case when isnull(a,0)=0 then b else b/a endas ttt from Temp
------解决方案--------------------
case when isnull(a,0)=0 then b else b/a end
------解决方案--------------------
endas
-->
end as

------解决方案--------------------
select c = case when isnull(a, 0) = 0 then b else b/a end
from 表
------解决方案--------------------
我想了一下,我还是不回复了.

看来我是对的~~ 呵呵
------解决方案--------------------
select case when a= '0 ' or ais null then a/b else a end as ab from temp
------解决方案--------------------
case when isnull(a,0)=0 then b else b/a end

------解决方案--------------------
select c=case when isnull(a,0)=0 then b else b/a end
------解决方案--------------------
select c=case when isnull(a,0)=0 then b else b/a end
from temp