1. sql 数据管理与实现,(1)查询所有男同学的信息。 (2)查询有不及格课程的学生信息及不及格课程的名称和成绩
1,select * from 学生 where 性别='男'2.sekect * from 学生,成绩表 where 学生.学号=成绩表.学号 and 成绩表.成绩<603.create trigger tri_学生_delete on 学生 instead of delete as begin if exists(select * from 成绩表 where 学号 in (select 学号 from deleted)) print '成绩表中有该记录对应的学生的成绩'; else delete from 学生 where 学号 in (select 学号 from deleted) end2. SQL语句求助:统计各班每门课程成绩均不及格的同学人数
select
a.score
,count
as
人数
,col2
as
科目
from
(select
case
when
col1>=60
then
'及格'
else
'不及格'
end
as
score
,col2
from
tb
g
)
a
group
by
a.score,a.col2
3. SQL语句求助:统计各班每门课程成绩均不及格的同学人数
根据题目要求,简单分析可以知道,其实这条查询语句只使用“学生选课”和“学生”这两张表即可。此处应该使用“左连接”,用学生表中的班级字段进行“分组”,用COUNT()函数对分数小于60的同学的个数进行统计。
SELECT 学生.班级,COUNT(学生选课.成绩<60)
FROM 学生选课
LEFT JOIN 学生
ON 学生选课.学生ID=学生.学生ID
GROUP BY 学生.班级
你可以进行验证一下,如果不对,或者有更优化的方法,可以相互学习!
4. SQL查询出有成绩不及格的学生的学号,姓名,课程名。
select a.学号 , a.姓名 , b.课程名
from tbStudent a , tbCourse b , tbScore c
where c.成绩 < 60 and a.学号 = c.学号 and b.课程号 = c.课程号
5. 成绩表里有多门课程,查询成绩比该课程平均分低的同学的信息 sql语句查询
select 成绩,avg(成绩)having 成绩<avg(成绩)group by 成绩
6. 排错SQL:列出有二门以上(含两门)不及格课程的学生姓名及其平均成绩
因为你按照s.sname分了组并且用了聚集函数avg(sc.scgrade),就必须用group by按照s.sname分组才行啊,如果select中没有s.sname,只有聚集函数avg(sc.scgrade)的话肯定就是对的,但是不符合你题目的要求了。下面这个就是对的了,因为除了聚集函数的选择项都被分组了,在上面那个后面加上group by s.sname应该就对了,不过不知道sname是不是唯一键。
唉,也不知道自己说清楚没,不清楚的可以发信问我。
7. SQL数据库的问题目
这是在一个student数据库上建立的查询,你可以把邮箱告诉我,我把数据库文件发给你,当然如果你想自己建的话也行,下面是三张表。
sno sname ssex sage sdept
200215121 李勇 男 20 CS
200215122 刘晨 女 19 CS
200215123 王敏 女 18 MA
200215125 张立 男 19 IS
cno cname cpno ccredit
1 数据库 5 4
2 数学 NULL 2
3 信息系统 1 4
4 操作系统 6 3
5 数据结构 7 4
6 数据处理 NULL 2
7 PASCAL语言 6 4
sno cno grade
200215121 1 92
200215121 2 85
200215121 3 88
200215122 2 90
200215122 3 80
--1.查询所有年龄在20岁以下的学生姓名及其年龄。
select sname,sage
from student
where sage<20
--2.查询考试成绩有不及格的学生的学号。
select sno
from sc
where grade<60
--3.查询年龄不在19~22岁之间的学生姓名、系别和年龄。
select sname,sdept,sage
from student
where sage not between 19 and 22
--4.查询既不是信息系,也不是计算机科学系的学生的姓名和性别。
select sname,ssex
from student
where sdept not in ('IS','CS')
--5.查询所有姓刘学生的姓名、学号和性别
select sname,sno,ssex
from student
where sname like '刘%'
--6.在Course数据表中添加记录('8','DB_design','2',4),并查询以"DB_"开头,且倒数第3个字符为 i的课程的详细情况
select *
from course
where cname like 'DB\_%i__%' escape'\'
--7.在SC数据表中添加记录('200215123','1',null),并查询所有有成绩的学生学号和课程号
select sno,cno
from sc
--8.查询全体学生情况,查询结果按所在系的系号降序排列,同一系中的学生按年龄升序
select *
from student
order by sdept desc,sage asc
--9.计算2号课程的学生平均成绩。
select AVG(grade)
from sc
where cno='2'
--10在SC数据表中添加记录('200215123','1',23),统计出不及格的同学学号和不及格的门数。
select student.sno,count(grade)
from sc,student
group by student.sno
having grade<60
--11.查询选修1号课程的学生最高分数。
select MAX(grade)
from sc
where cno='1'
--12.查询学生200215121选修课程的总学分数。
select SUM(grade)
from sc
where sno='200215121'
--13.求各个课程号及相应的选课人数
select cno,COUNT(sno)
from sc
group by cno
--14.查询选修了2门以上(包括2门)课程的学生学号
select sno
from sc
group by sno
having count(*)>=2
--15.查询成绩大于等于90分的学生的学号和姓名
select student.sno,sname
from student,sc
where grade>90
--16.查询选修了“数据库”课程的学生的学号和姓名
select student.sno,sname
from student inner join sc on student.sno=sc.sno
where cno=(select cno from course where cname='数据库')
--17.查询选修了3号课程且成绩高于此课程平均成绩的学号和成绩
select student.sno,grade
from student inner join sc on student.sno=sc.sno
where cno='3'
and grade>(select AVG(grade) from sc)
--18.查询没有选修1号课程的学生姓名。
select sname
from student,sc
where cno!='1'
--1.建立计算机系选修了2号课程的学生视图V1
create view v1
as
select sno,sname,ssex,sage,sdept
from student,course
where sdept='cs' and cno='2'
--2.建立信息系选修了1号课程且成绩在90分以上的学生的视图V2
create view v2
as
select student.sno,sname,ssex,sage,sdept
from student,course,sc
where course.cno='2' and grade>90
--3.将每门课程的课程号和平均成绩定义为一个视图V3
create view v3(cno,avg_grade)
as
select cno,avg(grade)
from sc
group by cno
--三、创建和执行下列存储过程:
--o 创建语句格式:
--n CREATE Proc[ere] 存储过程名
--[{@参数名 数据类型}[=default][output]]
--As
--Sql语句[…n]
--o 执行语句格式:
--n [exec[ute]] 存储过程名[实参[,output][,…n]
--1.查询计算机系学生的考试成绩,列出学生的姓名、课程名和成绩。
select sname,cno,grade
from student,sc
where sdept='cs'
--2.查询某个指定系学生的考试成绩,列出学生的姓名、所在系、课程名和成绩。
select sname,sdept,cname,grade
from student,sc,course
where sdept='%'
--3.查询某个学生某门课程的考试成绩,列出学生的姓名、课程名和成绩。
select sname,cno,grade
from student,sc
where sname='%' and cname='%'
--4.查询某个学生某门课程的考试成绩,若没有指定课程,则默认课程为“数据库基础”。
select sname,cno,grade
from student,sc
where sname='%' and cname='%'
--5.统计指定课程的平均成绩,并将统计的结果用输出参数返回。
--6.创建带删除数据的存储过程,要求删除考试成绩不及格学生的修课记录。
--7.创建带修改数据的存储过程,要求将指定的课程的学分增加2分。
8. SQL统计每门课程的不及格人数
你的要求有点特别,要求 学号!
如果只是
统计每门课程的不及格人数下面的SQL就可以啦:
select cnum,count(cnum) as 不及格人数
from sc
where score < 60
group by cnum 注意:是对课程号分组哟,楼上的是错的。
如果你要输出学号:
Select sc.snum as 学号,
a.cnum as 课程号,
a.不及格人数
From sc,
(select cnum,count(cnum) as 不及格人数
from sc
where score < 60
group by cnum) as a
where sc.score<60 and sc.cnum=a.cnum
以上我相信是没有问题的,你测试一下!
如果OK,给分哟
呵呵
9. 查询信息系三门以上不及格课程的学生学号和姓名 用sql语句怎么写
请参阅以下sql
select[学号],[姓名]from[学生信息表]whereexists(
(select[学号]from[成绩表]where[课程]<60
groupby[学号]havingcount([课程])>=3)ast1
where[t1].[学号]=[学生信息表].[学号]
)
有疑问及时沟通
一般情况下,这样写就可以了
请采纳!