SQL Server数据库增删改查等语句实例(2)

本文是SQL Server数据库操作的续篇,重点介绍如何执行基本的增、删、改、查操作。通过实例,详细解释了如何插入数据、更新记录、删除条目以及查询信息,帮助读者深入理解SQL Server的数据管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接上一篇


31.将学号和姓名用下划线连接,显示在一列。(sql中的连接符用‘+’)
select stuno+'_'+stuname "学号_姓名"
from t_student; 

32.显示教授的所有资料
select*
from T_TEACHER
where teatitle='教授'
33.将所有的分数显示为与60分的差值,同时也显示原分数。
select  score,'score-60'=score-60
from T_SCORE
34.显示姓张的男生的姓名
select stuname,stusex
from T_STUDENT
where stuname like '张%' and stusex='男' 
35.查询高级职称以下的教师姓名,高级职称以下为副教授和讲师
select teaname
from T_TEACHER
where teatitle !='教授'
--或
select teaname
from T_TEACHER
where teatitle in('副教授','讲师')
36.学校需要请学生对教授的教学作评价,因此需要通知相关学生。请查询出:教授所教过的课程,有哪些学生选过?列出他们的姓名
select distinct coursename,teaname,stuname
from T_STUDENT,T_COURSE,T_TEACHER,T_SCORE
where T_STUDENT.stuno=T_SCORE.stuno 
  and T_COURSE.courseno=T_SCORE.courseno
  and T_COURSE.teano=T_TEACHER.teano
  and teatitle='教授' 
37.查询郭莉芳的哪些科目期末考试没有及格?列出这些科目的名称和分数
  select stuname,coursename,score
  from T_COURSE,T_STUDENT,T_SCORE
  where T_STUDENT.stuno=T_SCORE.stuno
    and stuname='郭丽芳'
    and T_COURSE.courseno=T_SCORE.courseno
	and type='期末' and score<60
38.统计学生姓名的数量
select count(distinct stuname)"学生数量"
from T_STUDENT 
39.查询学校有多少名教师
select count(distinct teaname) '教师数量'
from T_TEACHER
40.查询为“梁天”的教师讲了多少门课
select count (distinct coursename)
from T_COURSE,T_TEACHER
where T_TEACHER.teano=T_COURSE.teano and teaname='梁天'
41.查询参加过考试的学生数量
select count(distinct stuno) '参加考试学生数'
from T_SCORE
42.查询郭丽芳选了多少门课
select count(distinct courseno)
from T_STUDENT,T_SCORE
where T_STUDENT.stuno=T_SCORE.stuno and stuname='郭丽芳'
43.查询课程C002的期末考试平均分
select avg(distinct score)'平均分'
from T_SCORE
where courseno='c002' 
44.查询课程C003的期中考试总分
select sum( distinct score) '总分'
from T_SCORE
where courseno='c002' and Type='期中'
45.查询学校所有考试记录的总分
select sum(score)'总分'
from T_SCORE
46.查询课程C004的期末考试最高分
select max(score)
from T_SCORE
where courseno='c004' and Type='期末'  
47.查询每个教师讲授的课程数量,并将其姓名和课程数量显示出来
select teaname,count(courseno)"课程数量" 
from T_COURSE,T_TEACHER
where T_TEACHER.teano=T_COURSE.teano
group by teaname
48.查询郭丽芳每门课的平均分,显示课程名称和平均分
select coursename,avg(score)'平均分'
from T_SCORE,T_STUDENT,T_COURSE
where T_SCORE.stuno=T_STUDENT.stuno 
  and T_SCORE.courseno=T_COURSE.courseno
  and stuname='郭丽芳'
group by coursename


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值