需求是这样的:
这样子就会在记录后边加上一列,表示是否变红。
如果大家有更好的办法,欢迎讨论
有个学生表
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
)
这样子就会在记录后边加上一列,表示是否变红。
如果大家有更好的办法,欢迎讨论