① 用sql选出每个人成绩的最高纪录
查询每个人最高成绩SQL:
第一种:先使用group by和max得到最高分数和学科,然后再查询一下score表,找到学科和分数都相同的记录
select b.* from (select max(score) t,course from score group by course) a,score b where a.t=b.score and a.course=b.course
第二种:先得到相同学科的最高分数,再查询score表,找到最高分数的记录select * from score a where score=(select max(score) from score where course=a.course)
第三种:score表中,当学科一样的时候,不存在一条记录的分数小于其它记录的分数select * from score a where not exists(select * from score where a.course=course and a.score<score)
② 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 查询出成绩最高分
请问SQL 查询出成绩最高分
select 姓名,课程名,成绩 from tablename where 成绩=(select max(成绩) from tablename)
④ mysql:如图:sql语句应该怎么查其中一门科目的最高分、最低分,平均得分等
select count(if(评价="差",true, null)) as 差, count(if(评价="中等",true, null)) as 中等, count(id) as 全部, max(成绩) as 最高分, min(成绩) as 最低分, avg(成绩) as 平均分 from 成绩表 where 考试时间 = '期中考试' and 科目 = '英语';
⑤ SQL查询单科成绩最高的同学
SELECT child.abc,child.cource,a.name
FROM (select max(b.point) as abc,c.cource from `student` as a join `achievement` as b join `course` as c on a.sex = 1 and b.sid=a.id and b.cid=c.id group by c.cource) as child
join `student` as a join `achievement` as b join `course` as c on a.sex = 1 and b.sid=a.id and b.cid=c.id where child.abc=b.point and child.cource=c.cource
很繁琐,子查询和查询的都是同一个表同一个条件,答案包对
不要姓名要学号的话就把名字换一下
原理
子查询出最高分和科目,再用父查询把(同条件下)把最高分和科目配对