這是一道PTA平臺上的題,完整題目如下
create table tb_student (
id int not null primary key,
name varchar(32)
);
create table tb_score (
stu_id int,
score int
);
create table tb_class (
id int not null,
name varchar(32),
stu_id int
);

下面是我提交過的,顯示“結果錯誤”,請問錯在哪里?正確的應該怎么寫呢?
我的思路是用相關子查詢,傳入一個“tb_class .name”里面求出此“tb_class .name”的最小成績,然后與外層的分數比較如果相等就說明是最低成績的學生。
select tb_student.id as stu_id,tb_student.name as stu_name,b.name as class_name ,a.score as score
from tb_student ,tb_score as a,tb_class as b
where tb_student.id=a.stu_id and a.stu_id=b.stu_id and a.score=(
select min(d.score)
from tb_score as d , tb_class as c
where d.stu_id=c.stu_id and b.name=c.name
group by c.name
);
uj5u.com熱心網友回復:
使用開窗函式 Rank,ROW_NUMBER,可以去搜一下轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/31259.html
標籤:基礎類
