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

请,各位高手大哥们,帮帮小弟解决一个SQL的条件表达式。
内容:       表A         字段       a             b               c                 d
                                            客户       客户         100             100
                                            无           客户         100             100
                                            客户       无             100             100

条件表达式:如果(a=客户   And   b=客户)结果是(C   *   1.17   +   d)   当(a=客户   And   b <> 客户)结果是(C   *   1.17)当(a   <> 客户   and   b=客户)结果是   d.


请大家帮帮忙,这条SQL的条件表达式怎样写。

------解决方案--------------------
select a,b,c,d, '结果 '=case when a= '客户 ' and b= '客户 ' then C * 1.17 + d
when a= '客户 ' And b <> '客户 ' then C * 1.17
when a <> '客户 ' and b= '客户 ' then d end
from 表A
------解决方案--------------------

select * ,case when a= '客户 ' And b= '客户 ' then C * 1.17 + d
when a= '客户 ' And b <> '客户 ' then C * 1.17
when a <> '客户 ' and b= '客户 ' then d end as xx
from tab
------解决方案--------------------
--这样?

select
case
when a= '客户 ' And b= '客户 ' then C * 1.17 + d
when a= '客户 ' And b <> '客户 ' then C * 1.17
when a <> '客户 ' and b= '客户 ' then d
end
from 表
------解决方案--------------------
case when a=客户 And b=客户 then C * 1.17 + d when a=客户 And b <> 客户 then C * 1.17 when a <> 客户 and b=客户 then d end

------解决方案--------------------
内容: 表A 字段 a b c d
客户 客户 100 100
无 客户 100 100
客户 无 100 100

条件表达式:如果(a=客户 And b=客户)结果是(C * 1.17 + d) 当(a=客户 And b <> 客户)结果是(C * 1.17)当(a <> 客户 and b=客户)结果是 d.
----
select case when a=客户 And b=客户 then C * 1.17 + d
case when a=客户 And b <> 客户 then C * 1.17
else d
end as kk
from t