❶ 1查询成绩表的总分数,平均分,最低分和最高分。用sql语句怎么写
1. 计算每个人的总成绩并排名(要求显示字段:姓名,总成绩)
select name,sum(cast(score as bigint)) as allscore from stuscore group by name order by allscore desc
2. 计算每个人的总成绩并排名(要求显示字段: 学号,姓名,总成绩)
select stuid,name,sum(cast(score as bigint)) as allscore from stuscore group by stuid,name order by allscore desc
3. 计算每个人单科的最高成绩(要求显示字段: 学号,姓名,课程,最高成绩)
SELECT t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,(SELECT stuid,max(score) as maxscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid and t1.score=t2.maxscore
4. 计算每个人的平均成绩(要求显示字段: 学号,姓名,平均成绩)
select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,(select stuid,avg(cast(score as bigint)) as avgscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid
❷ 怎么用sql语句做加法得到学生的总成绩
select学生.学号as姓名,sum(成绩.分数)as总分from学生leftjoin成绩on成绩.学号=学生.学号groupby学生.学号完全手打,若有疑问直接留言,我会持续关注的,保证好评率~
❸ SQL按学号查询每人的各科总成绩,感激不尽
SELECT A.XH,A.XM,SUM(B.KSCJ) AS ZF,AVG(B.KSCJ) AS PJF
FROM STU_INFO A,XK B
WHERE A.XH=B.XH
AND B.KKNY='20011'
GROUP BY A.XH,A.XM
❹ 查询每位同学的课程门数、总成绩、平均成绩”的SQL语句是什么
SQL语句如下:
SELECT 学号, Count(课程编号) AS 课程总数, Sum(成绩) AS 总分数, Avg(成绩) AS 平均分
FROM 成绩表
GROUP BY 学号;
SQL常用操作语句如下:
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’
排序:select * from table1 order by field1,field2 [desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
❺ SQL求选修课程在两门以上并且都及格的学生号及总平均分
我只会oracle的写法,其他数据库可能会有所区别,请注意。而且就算这种写法,因为无法实验可能也有些出入,应该需要调试
select 学生号,avg(分数) from table where 分数>=60 group by 学生号 having count(*)>1
分数>60保证及格,这里首先查询的是及格的学生,及格的学生如果count(*)>1,那么他的选课一定是两门或者两门以上(我假定的选课表是一个学生一个课程一行)。不过这里有一个问题,假设一个学生选了三门课程,两门及格一门不及格,那么是不是需要统计,按照你的需求
“两门以上并且都及格”,现在这个语句好像与你的要求不是那么符合。
所以还有一个版本
select table.学生号,avg(table.分数) 平均分 from table,(select 学生号,count(*) 选课数 from table group by 学生号 having 选课数>1)a where table.分数>60 group by 学生号 having table.学生号=a.学生号 and a.选课数=count(*)
❻ 按照人名查出学生的各科成绩以及总成绩并按总成绩排名的sql语句
按照人名查出学生的各科成绩以及总成绩并按总成绩排名的sql语句示例如下:
selectA.name ,
(selectB.scorefromtable_scoreBwhereB.type='数学'andA.id=B.id) as数学 ,
(selectB.scorefromtable_scoreBwhereB.type='语文'andA.id=B.id) as语文,
(selectB.scorefromtable_scoreBwhereB.type='英语'andA.id=B.id)as英语,
(selectSUM(B.score)fromtable_scoreBwhereA.id=B.id)assum_score
fromtable_studentAorderbysum_scoreDESC
以上sql语句首先把学生表和成绩表联合查出每个学生的数学、语文、英语成绩,然后通过selectSUM(B.score)fromtable_scoreBwhereA.id=B.id查出每个学生的总成绩。
最后orderbysum_scoreDESC实现按总成绩倒叙排列。
(6)sql选课考试总成绩扩展阅读
上述sql语句重点是对as关键字的使用- Alias(别名),通过使用 SQL,可以为列名称和表名称指定别名(Alias)。
表的 SQL Alias 语法
SELECT column_name(s) FROM table_name AS alias_name;
列的 SQL Alias 语法
SELECT column_name AS alias_name FROM table_name;
Alias 实例: 使用表名称别名
假设我们有两个表分别是:"Persons" 和 "Proct_Orders"。我们分别为它们指定别名 "p" 和 "po"。
现在,我们希望列出 "John Adams" 的所有定单。
我们可以使用下面的 SELECT 语句:
SELECT po.OrderID, p.LastName, p.FirstName FROM Persons AS p, Proct_Orders AS poWHERE p.LastName='Adams' AND p.FirstName='John'
❼ SQL 统计每个学生的选课门数和考试总成绩,求各位大大指教
selecta.姓名.count(c.课程号)as选课门数,sum(c.成绩)as总成绩from学生表a,课程表b,成绩表cwherea.学号=c.学号andb.课程号=c.课程号groupbya.姓名
❽ 1查询成绩表的总分数,平均分,最低分和最高分。用sql语句怎么写
---1. 计算每个人的总成绩并排名(要求显示字段:姓名,总成绩)
select name,sum(cast(score as bigint)) as allscore from stuscore group by name order by allscore desc
---2. 计算每个人的总成绩并排名(要求显示字段: 学号,姓名,总成绩)
select stuid,name,sum(cast(score as bigint)) as allscore from stuscore group by stuid,name order by allscore desc
---3. 计算每个人单科的最高成绩(要求显示字段: 学号,姓名,课程,最高成绩)
SELECT t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,(SELECT stuid,max(score) as maxscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid and t1.score=t2.maxscore
---4. 计算每个人的平均成绩(要求显示字段: 学号,姓名,平均成绩)
select distinct t1.stuid,t1.name,t2.avgscore from stuscore t1,(select stuid,avg(cast(score as bigint)) as avgscore from stuscore group by stuid) t2 where t1.stuid=t2.stuid
---5. 列出各门课程成绩最好的学生(要求显示字段: 学号,姓名,科目,成绩)
select t1.stuid,t1.name,t1.subject,t2.maxscore from stuscore t1,(select subject,max(score) as maxscore from stuscore group by subject) t2 where t1.subject=t2.subject and t1.score=t2.maxscore
---6. 列出各门课程成绩最好的两位学生(要求显示字段: 学号,姓名,科目,成绩)
select distinct t1.* from stuscore t1 where t1.stuid in(select top 2 stuscore.stuid from stuscore where subject = t1.subject order by score desc)order by t1.subject
---7. 统计报表(要求显示字段: 学号,姓名,各科成绩,总分,平均成绩)
select stuid as 学号,name as 姓名,sum(case when subject='语文' then score else 0 end) as 语文,sum(case when subject='数学' then score else 0 end) as 数学,sum(case when subject='英语' then score else 0 end) as 英语,sum(cast(score as bigint)) as 总分,(sum(cast(score as bigint))/count(*)) as 平均分 from stuscore group by stuid,name order by 总分 desc
---8. 列出各门课程的平均成绩(要求显示字段:课程,平均成绩)
select subject,avg(cast(score as bigint)) as avgscore from stuscore group by subject
---9. 列出数学成绩的排名(要求显示字段:学号,姓名,成绩,排名)
select * from stuscore where subject ='数学' order by score desc
---10. 列出数学成绩在2-3名的学生(要求显示字段:学号,姓名,科目,成绩)
select t3.* from(select top 2 t2.* from (select top 3 name,subject,score,stuid from stuscore where subject='数学' order by score desc) t2 order by t2.score) t3 order by t3.score desc
---11. 求出李四的数学成绩的排名
declare @tmp table(pm int,name varchar(50),score int,stuid int)
insert into @tmp select null,name,score,stuid from stuscore where subject='数学' order by score desc
declare @id int
set @id=0;
update @tmp set @id=@id+1,pm=@id
select * from @tmp where name='李四'
---12. 统计各科目及格人数
select subject,
(select count(*) from stuscore where score<60 and subject=t1.subject) as 不及格,
(select count(*) from stuscore where score between 60 and 80 and subject=t1.subject) as 良,
(select count(*) from stuscore where score >80 and subject=t1.subject) as 优
from stuscore t1 group by subject
---13.统计如下:数学:张三(50分),李四(90分),王五(90分),赵六(76分)
declare @s varchar(1000)
set @s=''
select @s =@s+','+name+'('+convert(varchar(10),score)+'分)' from stuscore where subject='数学'
set @s=stuff(@s,1,1,'')
print '数学:'+@s
❾ 用SQL语句查询各选修课程的最高分、最低分、平均分和选课人数。
SELECT CNAME,CTEACHER, 最高分, 最低分,平均分, 选课人数
FROM
( SELECT MAX(SCGRADE) AS 最高分,
MIN(SCGRADE) AS 最低分,
AVG(SCGRADE) AS 平均分,
COUNT(SNO) AS 选课人数
ROM C
ROUP BY CNO
) AS z