decode 实例

以往相关材料:

http://blog.csdn.net/arrowzz/article/details/17144651

http://blog.csdn.net/arrowzz/article/details/17144669



id,name,score
1,小明,胜
2,小明,胜
3,小李,负
4,小李,负
5,小明,负
6,小李,胜
7,小李,胜


效果
name,胜,负
小明,2,1
小李,2,2


创建表:
create table test20(
id integer,
name varchar2(20),
score varchar2(20)
);

插入相关数据:
insert into test20 values(1,'小明','胜');
insert into test20 values(2,'小明','胜');
insert into test20 values(3,'小李','负');
insert into test20 values(4,'小李','负');
insert into test20 values(5,'小明','负');
insert into test20 values(6,'小李','胜');
insert into test20 values(7,'小李','胜');

select语句:
select name 姓名,sum(decode(score, '胜', 1, 0)) 胜,sum(decode(score, '负', 1, 0)) 负from test20group by name;


=======================================================================

==========================================================================


PS:主要使用了 decode 函数


在逻辑编程中,经常用到If – Then –Else 进行逻辑判断。

在DECODE的语法中,实际上就是这样的逻辑处理过程。

它的语法如下:


DECODE(value, if1, then1, if2,then2, if3,then3, . . . else )


Value 代表某个表的任何类型的任意列或一个通过计算所得的任何结果。

当每个value值被测试,

如果value的值为if1,Decode 函数的结果是then1;

如果value等于if2,Decode函数结果是then2;等等。


事实上,可以给出多个if/then 配对。

如果value结果不等于给出的任何配对时,Decode 结果就返回else 。


需要注意的是,这里的if、then及else 都可以是函数或计算表达式。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545206.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

5种SpringBoot热部署方式,你用哪种?

来源 | my.oschina.net/ruoli/blog/1590148Spring Boot 中 5 种热部署方式如下:1、模板热部署2、使用调试模式Debug实现热部署3、spring-boot-devtools4、Spring Loaded5、JRebel接下来我们分别来看。1、模板热部署在 Spring Boot 中,模板引擎的页面默认…

IBM 前面板显示信息提示

ps1 指示灯:当此指示灯发亮时,表明电源1 出现故障。 ps2 指示灯:当此指示灯发亮时,表明电源2 出现故障。 temp 指示灯:当此指示灯发亮时,表明系统温度超出阈值级别。 风扇指示灯:当此指…

ContextMenu长按事件

/* ContextMenu菜单就是长按某一个组件,就会在屏幕的中间弹出ContextMenu,这里设置为长按文本框弹出ContextMenu菜单*/public class MyContextMenu extends AppCompatActivity {/** Called when the activity is first created. */final static int CONT…

observable_Java Observable deleteObserver()方法与示例

observable可观察的类deleteObserver()方法 (Observable Class deleteObserver() method) deleteObserver() method is available in java.util package. deleteObserver()方法在java.util包中可用。 deleteObserver() method is used to remove the given observer (obs) from…

偶尔所得代码片(进程和锁相关)

--杀死相关进程&#xff08;必须要用dba账号sys&#xff09; --alter system kill session session_id, serial#;alter system kill session 500,2568;--select lower(CHR(64ROWNUM)) from dual connect by ROWNUM <126--查进程 select * from v$process; --查锁 select * f…

熬夜都要看完的 Spring 干货!

在 Java 后端框架繁荣的今天&#xff0c;Spring 无疑是最最最火热&#xff0c;也是必不可少的开源框架&#xff0c;像腾讯、阿里、字节跳动等一线互联网公司都选择 Spring 作为基础的开发框架。而 Spring 生态圈里最让人兴奋的莫过于 Spring Boot 框架。他简化了使用 Spring 的…

2014值得期待的Erlang两本新书

在2014年的开头就有这样一个令人振奋的好消息,Erlang有一本新书即将出版 《The Erlang Runtime System》,其作者happi在2013年3月份发布了这本书的写作计划:"The plan is to have the book done by the end of 2013 and published early 2014. ",出版方是O’Reilly,依…

页面分栏LayoutInflater

/* 页面分栏*/ public class TabDemo extends TabActivity {/** Called when the activity is first created. */Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);TabHost tabHost getTabHost();LayoutInflater.from(this).inf…

这么简单的三目运算符,竟然这么多坑?

最近在一个业务改造中&#xff0c;使用三目运算符重构了业务代码&#xff0c;没想到测试的时候竟然发生 NPE 的问题。重构代码非常简单&#xff0c;代码如下&#xff1a;// 方法返回参数类型为 Integer // private Integer code; SimpleObj simpleObj new SimpleObj(); // 其…

Java 邮箱判断 正则表达式

import java.util.Scanner;public final class EmailCheck {public static boolean checkEmail(String email){String regex1 "[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9][.][a-zA-Z0-9]";//字母开头&#xff0c;后加字母或数字&#xff0c;后面加点&#xff0c;后面字母或数…

Java DataInputStream skipBytes()方法与示例

DataInputStream类skipBytes()方法 (DataInputStream Class skipBytes() method) skipBytes() method is available in java.io package. skipBytes()方法在java.io包中可用。 skipBytes() method is used to skip the given number of bytes of data from this DataInputStrea…

nagios客户端nrped服务方式启动脚本

1、平时配置nagios客户端nrped启动最常用的就是在/etc/rc.local文件配置&#xff1a;/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d2、但是还有更好的方式&#xff08;这样方便使用脚本启动或者关闭&#xff09;&#xff1a;在/etc/init.d目录下创建nrped脚…

用好MySQL的21个好习惯!

前言每一个好习惯都是一笔财富&#xff0c;本文分SQL后悔药&#xff0c; SQL性能优化&#xff0c;SQL规范优雅三个方向&#xff0c;分享写SQL的21个好习惯&#xff0c;谢谢阅读&#xff0c;加油哈~1. 写完SQL先explain查看执行计划&#xff08;SQL性能优化&#xff09;日常开发…

第四章图像增强

第四章图像增强1_图像增强的概念2_空间域增强2.1_图像增强的点运算2.1.1_灰度变换2.1.2_直方图均衡化2.1.3 直方图规定化1_图像增强的概念 什么是图像增强&#xff1a;图像增强是采用一系列技术去改善图像的视觉效果,或将图像转换成一种更适合于人或机器进行分析和处理的形式。…

Java DataInputStream readShort()方法(带示例)

DataInputStream类readShort()方法 (DataInputStream Class readShort() method) readShort() method is available in java.io package. readShort()方法在java.io包中可用。 readShort() method is used to read 2 bytes (i.e. 16 bit) of data input and returns a short va…

IP 对应 网址

IP 对应 网址 /* 网址和IP对应的小例子 */try {InetAddress address_1 InetAddress.getByName("www.baidu.com");InetAddress address_2 InetAddress.getByName("10.2.8.13");System.out.println(address_1.toString());System.out.println(address_2.t…

springboot发送qq邮件

springboot发送qq邮件1_开启邮箱相关权限并获取邮箱授权码2_实现功能2.1_添加mail的依赖2.1.1_创建工程时添加2.1.2_在工程中添加2.2_配置文件application.properties配置相关信息2.3_实现代码1_开启邮箱相关权限并获取邮箱授权码 进入账户 开启POP3/SMTP服务并生成授权码 …

反转链表-剑指offer-16

题目&#xff1a;定义一个函数&#xff0c;输入一个链表的头节点&#xff0c;反转该链表并输出反转后链表的头节点。分析&#xff1a;逐个头插&#xff0c;实现反转设置3个指针&#xff1a;head 头节点、prev 前一个节点、 cur 下一个节点注意&#xff1a;链表为空&#xff0c;…

getsimplename_Java类类getSimpleName()方法的示例

getsimplename类类getSimpleName()方法 (Class class getSimpleName() method) getSimpleName() method is available in java.lang package. getSimpleName()方法在java.lang包中可用。 getSimpleName() method is used to return the simple name of the underlying class as…

MyEclipse编码设置,中文乱码解决方法,UTF-8,GBK

在Myeclipse导入一个项目&#xff0c;有中文乱码问题&#xff0c;解决方法如下&#xff1a;一、将整个project设置编码UTF-8&#xff08;UTF-8可以最大的支持国际化&#xff09; windows->Preferences->general->Workspace->Text file encoding->Other框中的Tex…