关于一个sql的写法

需求是这样的:
 有个学生表
create table student
(
id int primary key,
name varchar2(200)
);
有个成绩表
create table score
(
id int , --对应与student 的 id(仅为测试,表结构也没好好设计)
math int,
eng int,
time varchar(200)
);
insert into student values(1,'lipf');
insert into student values(2,'lixw');
insert into student values(3,'liyf');

insert into score values(1,47,534,'2000');
insert into score values(1,35,43,'2001');
insert into score values(1,56,5,'2002');
insert into score values(1,47,674,'2004');

insert into score values(2,47,43,'2000');
insert into score values(2,35,21,'2001');
insert into score values(2,56,5,'2002');
insert into score values(2,47,32,'2004');
如果某个学生的数学成绩大于英语成绩(不管在那一年),则学生的记录在页面上要变红。

select distinct id, name,min(flag)over(partition by name) xx  from 
(
select a.id,a.name, b.flag from student a
inner join (select distinct id, sign(math-eng) flag from score ) b
on a.id=b.id
)


这样子就会在记录后边加上一列,表示是否变红。

如果大家有更好的办法,欢迎讨论
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值