首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL查询计算的有关问题

2012-12-17 
SQL查询计算的问题表tableAidcyidamout11005552101666 3103777当cyid表示的值100表示RMB101表示HKD(汇率0.

SQL查询计算的问题
表tableA
id     cyid    amout
1      100      555
2      101      666 
3      103      777

当cyid表示的值100表示RMB   101表示HKD(汇率0.81)   102表示美元(汇率6.21),请问在对金额进行SUM的时候,将所有的金额转化为RMB呢。。

[最优解释]
select sum( case cyid when 100 then amount*1 when 101 then amount*0.81 when 102 then amount*6.21)
from tb
[其他解释]
select sum( case cyid when 100 then amount*1 when 101 then amount*0.81 when 102 then amount*6.21 end )
from tb

或者

select sum( amount*(case cyid when 100 then 1 when 101 then 0.81 when 102 then 6.21 end) )
from tb
[其他解释]
二楼的方法不错,顶一下

热点排行
Bad Request.