代码实现:

use test_0425
go

select *from student

-- 查专业是什么学的
select *from student
where stspecialty like'%学'

-- 查分72-87的  并且 专业是什么文的
select *from student
where stscore like '[7-8][2-7]' and stspecialty like'_文' and stsex is not null

-- 查分数在72-87之间  并且 学号是 4 10 17中的 
select *from student
where stscore between 72 and 87 and stno in(4,10,17)
order by stscore desc	-- 降序排序

-- exists返回一个真值或假值
select  stno , stname from student
where exists(select *from student where stsex='女')

-- 按照性别分组并统计数量
select stsex as '性别' ,count(stsex) as '数量' , avg(stscore) as '平均分', sum(stscore) as 总分 from student
group by stsex

-- 筛选操作  方法一:case 函数
select *,
评价=case
when stscore>=90 then '优秀'
when stscore>=80 and stscore <90 then '良好'
when stscore>=70 and stscore <80 then '可以'
when stscore>=60 and stscore <70 then '加油'
when stscore>=1 and stscore <60 then '加油'
else '牛逼'
end

from student
order by stscore desc	-- 降序排序



结果实现:

SQL Server基本操作练习_SQL Server教程
SQL Server基本操作练习_SQL Server_02