日期:2014-05-18  浏览次数:20427 次

问一个SQL语句,会有帮忙写下,非常感谢!
有字段
a,b,c,d

传一个值V进来.

当V=a的时候取c   V=b的时候取d

我这么写的

select   c   from   tb   where   a=v
union  
select   d   from   tb   where   b=v


总感觉难看....求更好的写法...

------解决方案--------------------
select case when a=v then c else d end as result
from tb where a=v or b=v

------解决方案--------------------
进来学习一下楼上
------解决方案--------------------
学习中
------解决方案--------------------
写的挺不错 用CASE
------解决方案--------------------
非常好