1、查询出所有大连地区的学生的成绩。
2、查询从来没有参加任何考试的学生的信息。
3、查询有考试成绩纪录的学生的信息.
4、将所有大连地区学生的课程编号为3的课程成绩加10分。
5、删除所有C#课的成绩。
6、查询课程编号为3的课程的平均成绩,显示有此门课程成绩的学生编号,成绩及距平均分之间的差值。
7、查询参加了所有考试的学生的姓名。
8、查询有成绩纪录的学生人数。
9、查询有2门以上成绩的学生的姓名和联系方式
10、查询哪些学生有c#考试成绩,显示这些学生的姓名
11.查询出科目中教师的姓名,同时增加编号。
12.随机显示学生信息表中的两条数据:使用newid()函数
13.查询出联系电话为null的学生信息,联系电话用‘无’代替。
14.将查询出的地区为大连的都显示为null.
15.查询科目平均成绩超过70分的教师姓名。

新知识:

对空值进行显示操作:

  • isnull(A,‘aa’)函数可以将空值转换为有效的值。将列名A的值null改为‘aa’显示
  • nullif(A,‘aa’)函数可以根据指定的条件来生成空值。将列名A的值aa改为null显示

newid函数:

  •     
    使用newid()函数会产生随机行 
、查询出所有大连地区的学生的成绩。
    select s.number,c.score  from chengji as c ,student as s where c.number=s.number and s.diqu='大连'
    
select * from chengji where number inselect number from student where diqu='大连')

2、查询从来没有参加任何考试的学生的信息。
select * from student where number not in (select number from chengji)
3、查询有考试成绩纪录的学生的信息.
select * from student where number  in (select number from chengji)
4、将所有大连地区学生的课程编号为3的课程成绩加10分。
update chengji set score=score+10 where scorenumber=3
5、删除所有C#课的成绩。
delete chengji where scorenumber=(select scorenumber from score where kemu='C#')
6、查询课程编号为3的课程的平均成绩,显示有此门课程成绩的学生编号,成绩及距平均分之间的差值。
select number,score-(select avg(score) from chengji where scorenumber=3from chengji where scorenumber=3
7、查询参加了所有考试的学生的姓名。
select name from student where number inselect max(numberfrom chengji group by number)
8、查询有成绩纪录的学生人数。
  selectnumber ,name 
from student where number in
select max(numberfrom chengji   group by number having count(scorenumber)=(select count(*from score) )
9、查询有2门以上成绩的学生的姓名和联系方式。
select name,lianxidianhua from student where number inselect number from chengji group by number having count(scorenumber)>2)
10、查询哪些学生有c#考试成绩,显示这些学生的姓名。
select name from student where number inselect number from chengji where scorenumber =(select scorenumber from score where kemu='c#'))
给结果集添加编号
11.查询出科目中教师的编号,同时增加序号。
    
select 序号=(select count(*from score as a where a.scorenumber<=b.scorenumber ),teacherid  from score as b
    
select 序号=identity(1,1),teachername into #newtable from score
12.随机显示学生信息表中的两条数据:使用newid()函数
select top 2 * from student  order by newid()
13.查询出联系电话为null的学生信息,联系电话用‘无’代替。
select name,isnull(convert(char(20),lianxidianhua),''from student  
14.将查询出的地区为大连的都显示为null
select name,nullif(diqu,'大连'from student
15.查询科目平均成绩超过70分的教师姓名。
select teachername from teacherinfo where teacherid in 
(
select teacherid from score where scorenumber in
(
select scorenumber from chengji group by scorenumber having avg(score)>=70))

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2021-08-11
  • 2022-12-23
  • 2021-05-18
  • 2021-12-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2020-12-20
相关资源
相似解决方案