SQLserver 区间内查询,分组,模糊查询,排序查询练习附加 date函数

use stuinfo

--查询t_score表中没有选修课程号是5和7的学生信息。
select * 
from t_score
where  C_number  like '[^5,7]%' 

--查询t_course表学时在70到80之间(包含70、80)的课程信息。
select * 
from t_course
where Hours between 70and 80

--在t_student表中查询姓‘李’的学生的姓名、地址及电话。
select S_name,Address,Phone
from t_student
where S_name like'李%'
--查询t_course表学时是72且学分是6的课程信息。

select * 
from t_course
where Hours=72 and Credit=6


--在t_student表中查询所有男学生的姓名、出生年月和年龄

select S_name,Birthday,YEAR(GETDATE())-YEAR(Birthday) as 年龄
from t_student

--在t_student表中查询所有年龄大于35岁的女学生的姓名和年龄。
select YEAR(GETDATE())-YEAR(Birthday) as 年龄,S_name
from t_student
where YEAR(GETDATE())-YEAR(Birthday)>35 and Sex='女'

--查询各年份出生的学生人数。
select YEAR(Birthday) as 年份,count(*) as 学生人数
from t_student
group by YEAR(Birthday)

--在t_score表中查询每位同学的平均分,并按平均分从高到低排列。
select S_number,AVG(Score) as avg
from t_score
group by S_number 
order by AVG(Score)


--在t_score表中查询获得课程平均分超过80分的课程信息(显示课程号、课程平均分)。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值