mysql仿oracle的decode效果查询

时间:2024-01-12 22:04:00 

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
)

标签:decode,效果查询
0
投稿

猜你喜欢

  • Python 编程操作连载之字符串,列表,字典和集合处理

    2021-08-16 11:27:54
  • PHP适配器模式Adapter Pattern的使用介绍

    2023-06-10 12:28:21
  • python 解压、复制、删除 文件的实例代码

    2023-12-23 23:35:34
  • 让sql2005运行在独立用户下出现 WMI 提供程序错误的解决方式

    2024-01-13 13:12:50
  • python的sys.path模块路径添加方式

    2021-04-06 05:52:30
  • Python使用剪切板的方法

    2022-01-25 02:17:39
  • 如何创建 Firefox 的 Jetpack 扩展

    2009-10-13 20:55:00
  • M2实现Nodejs项目自动部署的方法步骤

    2024-05-13 10:05:21
  • Vscode常用快捷键列表、插件安装、console.log详解

    2023-02-11 01:29:04
  • asp连接access、sql数据库代码及数据库操作代码

    2023-07-07 13:37:26
  • Python基类函数的重载与调用实例分析

    2021-03-02 21:28:30
  • 详解Python下ftp上传文件linux服务器

    2023-12-31 19:02:37
  • python3中替换python2中cmp函数的实现

    2021-08-15 01:42:41
  • 为ckeditor编辑器加上传图片的功能

    2022-08-11 22:17:50
  • numpy中的converters和usecols用法详解

    2021-01-23 18:29:29
  • mysql存储过程原理与使用方法详解

    2024-01-25 10:20:05
  • 详解用Python处理Args的3种方法

    2023-01-21 17:10:10
  • 如何把数组转换成字符串?

    2009-11-06 13:49:00
  • 在Windows系统上搭建Nginx+Python+MySQL环境的教程

    2024-01-24 08:04:40
  • ubunt18.04LTS+vscode+anaconda3下的python+C++调试方法

    2023-04-01 16:46:37
  • asp之家 网络编程 m.aspxhome.com