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

sql查学分

发布时间: 2022-12-06 22:54:50

sql数据库 查询总学分超过6分的同学学号,姓名,选修课的门数,总学分 sq语句是什么

可以用分组汇总+having筛选实现,请参考下列写法:
courses(cid,cname,credits)
students(sid,sname)
sc(sid,cid,scores)
每科成绩60分以上方可获得学分
SQL语句
select a.sid as 学号,b.sname as 姓名,
a.cnt as 选修课的门数,a.total as 总学分
from students b,
(select t.sid,t.cid,count(1) as cnt,
sum(t.credits) as total from
(select distinct sc.sid,sc.cid,
courses.credits from sc,courses where
sc.cid=couses.cid and sc.scores>=60) t
group by t.sid,t.cid
having sum(t.credits)>6) a,
where a.sid=b.sid;

② 如何使用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在学生表中查询每个人的总分与平均总学分的差,要求显示学号、姓名、专业、总学分、与平均总学分的差

T-SQL语句如下:
Select 学号,姓名,专业,总学分,总学分-(select avg(总学分) from [学生选课系统].[dbo].[学生表] where 专业=A.专业) as 与平均总学分的差 From [学生选课系统].[dbo].[学生表] as A
(*注:以上语句是学生与其所属专业的平均总学分的对比,即平均总学分是按专业分开计算的)

如果不用考虑区分专业,而是直接跟全校学生的平均总学分比较的话,用下面的语句:
Select 学号,姓名,专业,总学分,总学分-(select avg(总学分) from [学生选课系统].[dbo].[学生表]) as 与平均总学分的差 From [学生选课系统].[dbo].[学生表] as A

④ 写sql查询语句----高手请进

if object_id('tempdb..#1') is not null drop table #1
SELECT S.Sno as 'Sno',
S.Sname as 'Sname',
S.Ssex as 'Sse',
S.Sage as 'Sage',
S.Sdept as 'Sdept',
SC.Cno as 'Cno',
SC.Grade as 'Grade',
C.Cname as 'Cname',
'Ccredit' = CASE WHEN SC.Grade >=60 then C.Ccredit ELSE 0 END
INTO #1
FROM Student S
LEFT JOIN SC SC ON SC.Sno = S.Sno
LEFT JOIN COURSE C ON C.Cno = SC.Cno

SELECT SELECT S.Sno as '学号',
S.Sname as '姓名',
S.Ssex as '性别',
S.Sage as '年龄',
S.Sdept as '系名',
SUM(S.Ccredit) as '学分'
FROM #1 S
GROUP BY S.Sno, S.Sname, S.Sex, S.Sage, S.Sdept

drop table #1

⑤ 使用sql语句查询学生姓名及其课程总学分 语句怎么写

回答这个问题最好是要有数据结构

这里假设数据结构为:

student(Sid,Name)

credits(Sid,Cid,credt)


实现代码

selecta.Sid,a.Name,b.sumCreditfromstudentsa,
(selectSid,sum(credit))b
wherea.Sid=b.Sid;

⑥ SQL查询每门课程最高分学生的学号,课程号,成绩

select t1.学号,t1.课程号,t1.成绩
from table t1
where t1.成绩 = (
select max(t2.成绩)
from table t2
where t2.课程号 = t1.课程号
group by t2.课程号
)

⑦ 用sql命令 求各学期开设的课程的总学分

假设表名为course,里面有字段course_name,course_score,term_id,(分别是课程名称,课程学分数,学期标号)
语句可以写成:
select term_id,sum(course_score) from course group by term_id;

⑧ 用SQL实现,查询course表中所有课程的总学时和总学分,要求列标题分别显示“总 学时和总学分

select 课程,sum(学时) 总学时,sum(学分) 总学分 from course group by 课程

⑨ SQL查询出所有课程的总学分

咋又是你

selectsum(credit)fromcourse

⑩ 查询每个学生的各科成绩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)。