Home > database >  The topic request to write SQL statements, searching the lowest score in each class classmate studen
The topic request to write SQL statements, searching the lowest score in each class classmate studen

Time:11-21

this is a PTA platform, full title the following
 
The create table tb_student (
Id int the not null primary key,
The name varchar (32)
);
The create table tb_score (
Stu_id int,
Score int
);
The create table tb_class (
Id int the not null,
The name varchar (32),
Stu_id int
);


below is I submitted before, according to "the error", could you tell me where is wrong? The right should be how to write?
My train of thought is to use correlated subqueries, into a "tb_class. The name" inside out "tb_class. The name" minimum scores, and then compared with outer score equal if it is the lowest grade students,

 
Select tb_student. Id as stu_id tb_student. Name as stu_name, b.n ame as class_name, a.s core as score
The from tb_student, tb_score as a, tb_class as b
Where tb_student. Id=a.s tu_id and a.s tu_id=b.s tu_id and a.s core=(
The select min (d.s core)
The from tb_score as d, tb_class as c
Where d.s tu_id=c.s. tu_id and b.n ame=c.n ame
Group by citigroup ame
);

CodePudding user response:

Using a window function Rank, ROW_NUMBER, can go to search