搜索
写经验 领红包
 > 美容

oacledecode函数的用法(oacle的decode方法)

导语:oracle 函数decode用法

create table student(

name varchar2(30),

gj varchar2(20),

score number(4,1)

);

insert into student (name, gj, score) values ('李二', '中国', 90);

insert into student (name, gj, score) values ('张无忌', '美国', 80);

insert into student (name, gj, score) values ('周芷若', '俄罗斯', 79);

insert into student (name, gj, score) values ('xx', '中国', 95);

insert into student (name, gj, score) values ('hh', '美国', 85);

insert into student (name, gj, score) values ('kk', '俄罗斯', 77);

select count(u.xm) as 总人数,

sum(decode(u.gj, 1, u.cj)) as 中国成绩,

sum(decode(u.gj, 2, u.cj)) as 美国成绩,

sum(decode(u.gj, 3, u.cj)) as 俄罗斯成绩

From (select name as xm,

decode(gj, '中国', 1, '美国', 2, '俄罗斯', 3) as gj,

sum(score) as cj

from student

group by name,gj) u;

本文内容由快快网络小葵创作整理编辑!