2025年SQL Server基本操作练习「建议收藏」

SQL Server基本操作练习「建议收藏」代码实现 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

代码实现:

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 -- 降序排序

结果实现:

编程小号
上一篇 2025-03-03 09:46
下一篇 2025-02-21 07:01

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/146244.html