<返回更多

oracle 函数decode用法

2019-09-20    
加入收藏
oracle 函数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;

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>