每位學生的最高成績
⑴ SQL查詢每課成績最高的學生的信息
select
distinct
*
from
(
select
需要抽取的欄位
from
學生成績內表容
a
where
a.語文
=
(select
max(語文)
from
學生成績表)
union
all
select
需要抽取的欄位
from
學生成績表
a
where
a.數學
=
(select
max(數學)
from
學生成績表)
union
all
select
需要抽取的欄位
from
學生成績表
a
where
a.英語
=
(select
max(英語)
from
學生成績表)
。。。)
b
如果需要包含學科成績,那還要做處理。
⑵ SQL查詢每課成績最高的學生的信息
大概思路是找出單科最高成績,再跟成績表關聯找出學生。
假設成績表有欄位科目ID、學生ID、學生成績三個欄位
大概以下SQL,可以參考下:
select 科目ID、學生ID、學生成績 b.最高成績 from 成績表 a
left join
(select 科目ID,max(學生成績) as 最高成績 from 成績表 group by 科目ID) b
on (a.科目ID=b.科目ID and a.學生成績=b.最高成績)
where b.最高成績 is not null;
⑶ C語言學生成績最高平均
下面的程序先輸入10個學生的數據,輸入三門課的成績完成後,計算每位學生的總分以及平均分。然後找出最高分學生。最後輸出最高分學生的數據,還有三門課的總平均成績。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#defineN10
structstu
{
intgrade[3];
charname[10];
charnumber[10];
intsum;
doubleave;
};
voidf_input(structstu*temp);
structstuf_max(structstu*temp);
voidf_print(structstus);
voidf_print_ave(structstu*temp);
intmain()
{
structstus[N];
structstus_max;
f_input(s);
s_max=f_max(s);
printf(" thesummaxis: ");
f_print(s_max);
f_print_ave(s);
return0;
}
voidf_input(structstu*temp)
{
inti;
intj;
for(i=0;i<N;i++)
{
intsum=0;
printf("pleaseinput%dstudentname: ",i+1);
scanf("%s",temp->name);
printf("pleaseinput%dstudentnumber: ",i+1);
scanf("%s",temp->number);
for(j=0;j<3;j++)
{
printf("pleaseinput%dgrade: ",j+1);
scanf("%d",&temp->grade[j]);
sum+=temp->grade[j];
}
temp->sum=sum;
temp->ave=sum/3.0;
temp++;
}
}
structstuf_max(structstu*temp)
{
structstu*max;
inti;
max=temp;
for(i=0;i<N;i++)
{
if((temp->sum)>(max->sum))
{
max=temp;
}
temp++;
}
return*max;
}
voidf_print(structstus)
{
inti;
printf("thestudentnameis:%s ",s.name);
printf("thestudentnumberis:%s ",s.number);
for(i=0;i<3;i++)
{
printf("thegrade[%d]is:%d ",i+1,s.grade[i]);
}
printf("thesumis:%d ",s.sum);
printf("theaverageis:%f ",s.ave);
}
voidf_print_ave(structstu*temp)
{
inti;
intsum_all=0;
doubleave_all;
for(i=0;i<N;i++)
{
sum_all+=temp->sum;
temp++;
}
ave_all=sum_all/(3.0*N);
printf(" theaverageofallgradesis:%f ",ave_all);
}
我跑過程序了,應該沒錯的,就是輸入學生信息的時候,由於有10位學生,可能輸入的信息比較多。先輸入姓名,然後是學號,最後是三門課程的成績。每次輸入完成後回車就可以了。可以自己跑一下程序,就看到結果了。
⑷ SQL查詢求每個同學的課程成績的最高分,查詢結果項包括:學生姓名、課程號及最高分
你好,你展示的第一種sql查詢方案,其意思是:
先根據score表中的sno分組求每個sno的最高分數。這求得的當然是每個同學的最高分啦,但是只是獲得了最高分,沒有指定是誰的最高分,導致在前面的【SELECT SNAME ,CNO,GRADE FROM Score Y,StudentWHERE (STUDENT.SNO=Y.SNO)】查詢結果集中的後面檢索條件【AND Y.GRANDE IN (所有人的最高分集合)】,這樣系統就會查詢分數在「所有人的最高分」里的結果集了。
而第二種方案,除了限定分數范圍(最高分),還限定了學生的編號(
SELECTMAX(GRADE)FROMSCOREWHERE
SNO=Y.SNO
GROUPBYSNO,sno=y.sno就是限定學生的編號。
),所以結果自然不同了。
根據你的要求,我給你提供一種查詢方式。其實原理是一樣的哦。
selectstu.sname,scr.cno,scr.gradefromstudentstu
leftjoinscorescronscr.sno=stu.sno
whereexists(select1from(selects.sno,max(s.grade)asmgfromscoresgroupbys.sno)twheret.sno=stu.sno
andt.mg=scr.grade)
希望能幫助你。
⑸ 在表格成績單中,(1)用max()函數求各學科的最高分;(2)求各學生的成績平均分
一、用MAX求各學科最高分的步驟如下:
1、在「英語」學科下方的單元格中輸入「=」;
⑹ 求一個oracle的sql語句,在成績記錄表中取每個同學的最高一次成績
用下面的制SQL語句可實現該功能:
select name as 姓名,sum(case when subject='語文' then fenshu else 0 end) as 語文,sum(case when subject='數字' then fenshu else 0 end) as 數字,sum(case when subject='英語' then fenshu else 0 end) as 英語 from score group by name
⑺ mysql中有student,course,scorse 三張表, 計算每個人單科的最高成績(學生,課程,成績)
獲取每一來個科目最高分的學生源
select sid,cid,max(score) from score group by cid;
然後分別和學生表、課程表聯合查詢取出科目名字和學生名字就ok了
寫成單條sql:
select * from (select s.sid,s.realname,a.cid,a.mscore from student as s right join (select sid,cid,max(score) as mscore from score group by cid)as a on a.sid = s.sid) as a1 left join ((select c.coursename,c.cid from course as c right join (select sid,cid as mscore from score group by cid)as a on a.cid = c.cid) ) as b1 on a1.cid = b1.cid;
⑻ 用sql 查詢出各個科目中成績最好的學生的名字
select
姓名
from
(select
*
from
(
select
a.學生編號,a.姓名
b.
學生編號,b.科目,b.分數
from
table1
a
right
join
table2
b
on
b.學生編號=a.學生編號
)c
group
by
c.科目
having
max(c.分數)
)
⑼ 每個學生有不同成績,sql查詢最高成績的排名
1.每個學生可以是參加了一次或者多次的考試,對吧?
2.你是使用什麼資料庫?版MySQL?Oracle?SQLServer?
3.若學生中權最高的成績都是相同的分數,如何排名?是給相同的名次還是依舊隨機增序的方式排序?
⑽ SQL語句執行問題:有一張表sc如下:查詢每位學生的最高成績。
對於每個學號,不存在比這個學號的分數低的數據全部查出來。
反之就是得到每個學號最高的分數了。
另外,你也可以
select sno,max(grade) from sc group by sno