mysql仿oracle的decode效果查询
以下代码在MYSQL中测试通过,MSSQL应该能跑通,未测试。
代码如下:
#创建表如下 create temporary table tmp (a int, b int ,c int); insert into tmp VALUES (1,10,1),(10,10,2),(10,100,2); #mysql执行 select sum(case when c = '1' then A else B end) from tmp #oracle执行 select sum(decode(c,'1',a,b)) from tmp #普通联合查询 select sum(d) from ( select a as d from tmp where c=1 union select b as d from tmp where c=2 )
相关推荐
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11
世樹 2020-11-11