❶ 用sql查询每个学生的所选课程的最高成绩 要求列出学号,姓名,课程编号,分数 已经得到如下结果 多谢咯
用了聚合函数就需要对其(group by )分组
select STUDENT.学号,姓名,课程名称,max(分数)
FROM GRADE JOIN STUDENT ON GRADE.学号=STUDENT.学号 JOIN CURRICULUM ON GRADE.课程编号=CURRICULUM.课程编号 group by STUDENT.学号,姓名,课程名称
❷ SQL-根据以下数据库列表 -查看每个学生成绩最高的是哪一科 怎么写急需 。
/*==============================================================*/
/* Table: stu_Score */
/*==============================================================*/
create table stu_Score (
id int identity,
stuid int not null,
Column_1 int null,
Column_2 int null,
Column_3 int null,
Column_4 int null,
constraint PK_STU_SCORE primary key (id)
)
select * from stu_Score
数据表结构是
对应的科目是一定
表名是 stu_Score
stuid 英语 数学 语文 体育
id stuid column1 column2 column3 column4
1 1 88 90 76 86
2 2 76 77 90 66
3 3 90 88 75 91
SELECT stuid ,
( SELECT MAX(maxScore),'1' as a
FROM (VALUES (column_1),( column_2),( column_3),( column_4) ) AS sd ( maxScore )
) AS maxScore,
case when ( SELECT MAX(maxScore)
FROM (VALUES (column_1),( column_2),( column_3),( column_4) ) AS sd ( maxScore )
)= column_1 then '英语' when ( SELECT MAX(maxScore)
FROM (VALUES (column_1),( column_2),( column_3),( column_4) ) AS sd ( maxScore )
)= column_2 then '数学' when ( SELECT MAX(maxScore)
FROM (VALUES (column_1),( column_2),( column_3),( column_4) ) AS sd ( maxScore )
)= column_3 then '语文' else '体育' end subject
FROM stu_Score
❸ 求SQL查询语言:查询所有学生平均成绩最好的课程的课程号和平均成绩
select top 1 avg(Grade)'平均成绩',Cno from SC where Cno=1001 or Cno=1002 or Cno=1003 group by Cno order by Cno desc
❹ 用sql 查询出各个科目中成绩最好的学生的名字
select
t1.姓名,t2.分数
from
table1
t1,
(select
max(分数)as
分数,学生编号
from
table2
group
by
学生编号)
t2
where
t1.学生编号=t2.学生编号
❺ MySQL 怎么用SQL语句写:按学号列出每个学生所选修课程中最高分的课程名称及其分数
漫画SQL——mysql必修课(956×540视频)网络网盘
链接: https://pan..com/s/1dZyKSIHepckKltyYMz1DWQ
若资源有问题欢迎追问~
❻ 试写一个SQL语句,查询出各科成绩最高分的同学(包括学生号,科目与成绩)
select 学生号 ,科目 ,成绩 max(成绩)
from 要查的表
group by 科目
注: max(成绩)是成绩 的别名 我把成绩当作最高成绩来做了
❼ 有一张表TABL里面有班级号、科目号、学生号、成绩,写一个SQL语句查询出每个班级每门科目成绩最好的学生
select 班级号,科目号,(select top 1 学生号 from TABL where 班级号=x.班级号 and 科目号=y.科目号 order by 成绩 desc) as 最好成绩的学生 from TABL x group by 班级号,科目号
❽ 如用使用sql语言列出每门课最高分的学生的信息
select 学生.学号, 学生.姓名, max(选课.成绩)over(partition by 选课.课程编码) as '最高成绩' , 选课.课程编码 ,课程.课程名称
from 学生,选课,课程
where 学生.学号=选课.学号 and 选课.课程编码=课程.课程编码
这样就可以把每门课程最高成绩的学生信息查询出来
可以在select 后面多加一列想要的学生信息
❾ sql server 中如何查询学生表中每位学生全部科目中最高分对应的那行数据呢 急急急 !
select t1.*
from 学生表 t1,
(select 学号,max(成绩)as 成绩 from 学生表 group by 学号)t2
where t1.学号=t2.学号
and t1.成绩=t2.成绩
❿ sql语句查询横排成绩表中成绩最好的学生姓名、科目和成绩
/*
让我们假设 这个表叫ExamResults.
name - 姓名
subjects - 科目
grades - 成绩
*/
--then the query is as following.
select
er1.name, er1.subjects, er1.grades
from ExamResults as er1, ExamResults as er2
where er1.name = er2.name and er1.grades > er2.grades