登陆

oracle 函数decode用法

admin 2019-11-01 300人围观 ,发现0个评论

create table student(

name varchar2(30),

gj varchar2(20),

score number(4,1)

);

insert inoracle 函数decode用法to 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 oracle 函数decode用法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.oracle 函数decode用法gj, 2, u.cj)) as 美国成绩,

sum(decode(u.gj, 3, u.cj)) as 俄罗oracle 函数decode用法斯成绩

From (select name as xm,

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

sum(score) as cj

from student

group by name,gj) u;

请关注微信公众号
微信二维码
不容错过
Powered By Z-BlogPHP