当前位置:首页 » 编程语言 » sql语句科目表怎么查成绩
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql语句科目表怎么查成绩

发布时间: 2022-05-24 14:09:10

‘壹’ sql学生表,科目表,成绩表,怎么查每个人各科目的总分

为什么都不喜欢给表结构
看我强大的想象能力~~
select sum(分数) as 总分,
(select 学生姓名 from 学生表 where a.学生id = 学生表.学生id),
(select 科目名称 from 科目表 where a.科目id = 科目表.科目id),
from 成绩表 a
group by a.学生id,a.科目id

‘贰’ 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 max(科目) as '最高分',min(科目) as 最低分,round(avg(科目),2) as '平均分' from 表

round(avg(科目),2) 意思是平均分保留两位小数,因为在多个科目中就可以出现小数

如果有一科或多科没有成绩使用avg就不正确,应该用以下语句:

select max(科目) as '最高分',min(科目) as 最低分,round(sum(科目)/科目数,2) as '平均分' from 表

因为avg有效果是对已有数据的统计平均。

‘肆’ 怎么用SQL语句查询每个学生选修的课程名及其成绩

查询选修了全部课程的学生姓名
:student 是学生表 course 是选课表 sc 是课程表
select sname
from student
where not exists
(select *
from course
where not exists
(select *
from sc
where sno =student.sno
and cno=course.cno)

‘伍’ sql语句科目表学生表和成绩表的查询

每科的总成绩?查询它干什么?要查的话这样查:

SELECT 科目表.KUMUID,KUMUName,SUM(CHENJI) AS SUM_CHENJI,AVG(CHENJI) AS AVG_CHENJI
FROM 科目表,成绩表
WHERE 科目表.KUMUID=成绩表.KUMUID
GROUP BY 科目表.KUMUID,KUMUName

由于是查每科的总成绩和平均分,所以和学生没有关系,不用关联学生表
----------------------------------------------------------------

不过我怀疑你是不是想查每个学生的总成绩和平均分,是这样查的:

SELECT 学生表.UID,UName,SUM(CHENJI) AS SUM_CHENJI,AVG(CHENJI) AS AVG_CHENJI
FROM 学生表,成绩表
WHERE 学生表.UID=成绩表.UID
GROUP BY UID,UName

=========================================================
对于楼主的补充的回答:
你所要的SQL语句我已经写了,这个查询由于是查询每个科目的总成绩,所以不需要查询学生的姓名,所以不应关联学生表。只需要用成绩表关联科目表(目的是查询出科目的名称)。然后直接使用分组汇总(就是用 GROUP BY 子句和SUM、AVG两个聚合函数实现的)。
分组查询是一种最基本的查询,现在的主流数据库都支持它。所以每一个学习数据库的人都应该很好的理解它。

‘陆’ 查询每个学生的各科成绩sql语句

1、查询每个学生的各科成绩sql语句:

select a.studentid,a.name,a.sex,v1.score as '语文',v2.score as '数学', v3.score as '英语',v4.score

as ‘哲学’, (v1.score+v2.score+v3.score+v4.score)/4 as ‘平均成绩’ from Stuednt a
left join

(select studentid,score from grade where cid=(select cid from course where cname='语文'))as v1

on a.studentid=v1.studentid

left join

(select studentid,score from grade where cid=(select cid from course where cname='数学'))as v2

on a.studentid=v2.studentid

left join

(select studentid,score from grade where cid=(select cid from course where cname='英语'))as v3

on a.studentid=v3.studentid

left join

(select studentid,score from grade where cid=(select cid from course where cname='哲学'))as v4

on a.studentid=v4.studentid

order by a.studentid

2、sql数据库介绍:

(1)SQL是Structured Query Language(结构化查询语言)的缩写。SQL是专为数据库而建立的操作命令集,是一种功能齐全的数据库语言。在使用它时,只需要发出"做什么"的命令,"怎么做"是不用使用者考虑的。

(2)SQL功能强大、简单易学、使用方便,已经成为了数据库操作的基础,并且现在几乎所有的数据库均支持SQL。

(3)SQL数据库的数据体系结构基本上是三级结构,但使用术语与传统关系模型术语不同。

(4)在SQL中,关系模式(模式)称为"基本表"(base table);存储模式(内模式)称为"存储文件"(stored file);子模式(外模式)称为"视图"(view);元组称为"行"(row);属性称为"列"(column)。

‘柒’ 简单SQL语句,查询成绩

select * from xs
inner join
(
select km,max(fs) as fs from xs group by km
)w
on xs.km = w.km and xs.fs = w.fs

这样行不?凭想象写的,请参考

‘捌’ 如何使用sql编写查询语句 用于查询学生的 各科成绩

declare
@sql
varchar(8000)
select
@sql='select
a.mname
as
学生姓名'
select
@sql=@sql+',sum(case
c.fname
when
'''+fname+'''
then
b.score
else
null
end
)as
'+fname
from
f
select
@sql=@sql+'
from
member
a
left
join
score
b
on
a.mid=b.mid
left
join
f
c
on
b.fid=c.fid
group
by
a.mname'
print
@sql
exec
(@sql)
费了好劲,真麻烦,头一次搞这个东西

‘玖’ 按照人名查出学生的各科成绩以及总成绩并按总成绩排名的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实现按总成绩倒叙排列。


(9)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'

‘拾’ 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