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

SQL Server基本操作练习「建议收藏」代码实现:use test_0425goselect *from student– 查专业是什么学的select *from studentwhere stspecialty like’%学’– 查分72-87的 并且 专业是什么文的select *from studentwhere stscore like ‘[7-8][2-7]’ and stspecialty …

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

代码实现:

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



结果实现:

在这里插入图片描述
在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/170888.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号