① 用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
很繁瑣,子查詢和查詢的都是同一個表同一個條件,答案包對
不要姓名要學號的話就把名字換一下
原理
子查詢出最高分和科目,再用父查詢把(同條件下)把最高分和科目配對