软件测试工程师必备技能—数据库基本命令

1、插入学生及相关联信息

详见:https://blog.csdn.net/m0_64682777/article/details/121742968

软件测试工程师必备技能—数据库基本命令

2、增、删、改、查的基本语句(以下语句对照以上列表)

1、增

insert into Student (studentname,age,gender) velues (‘赵六’,’20’,’男’)

注解:一切增语句以【insert into表名(列名)velues(列值)】为基础;insert into是指动词,将xx插入到xx;‘表名’指要插入的信息到哪张表;(列名)指需要插入信息的名称;velues是名词值,值后边需要写明插入的值;(列值)指插入的详细信息;(列名)和(列值)呈因果关系。

2、删

delete from Student where studentName=’张三’

注解:一切删语句以【delete from表名where条件】为基础;delete from是指动词,从xx里删除;where是指条件,当满足xx条件时进行删除;语句解释为:删除‘学生’表中‘学生姓名=张三’。

3、改

update Student set age=18 where studentName=’张三’

注解:一切改语句以【update表名set更新值 where 更新条件】为基础;语句解释为:更改‘学生表’中的年龄为18{如果没有where后边的条件,那么‘学生表’的所有学生都会变为18},条件是学生姓名为’张三’。

4、查

select * from Student

注解:一切一般查询语句以【select * from表名】为基础;这种语句格式是对整张表的查询。

4.1精确查找

select * from Student where age

注释:查询所有年龄小于19的学生。

select * from Student where studentname=’张三’

注释:查询学生表内姓名是’张三’的学生

4.2倒序查找

select * from Student order by age desc

注释:查询所有学生并按照年龄倒序排序。order by指顺序,order by..desc指倒序。

select * from Score order by score desc

注释:查询所有成绩并按照成绩倒序排序。

4.3正序查找

select * from Student order by age asc

注释:查询所有学生并按照年龄正序排序。order by..asc指正序。

select * from Score order by score asc

注释:查询所有成绩并按照成绩正序排列。

select * from Student where age>18 order by age asc

注释:查询所有学生年龄大于18,结果按照正序排序。增加where查询条件。

select * from Score where score>70 order by score asc

注释:查询所有成绩大于70,结果按照正序排序。

4.4模糊查询

select * from Student where studentName like ‘%李%’

注释:查询所有名字中存在’李’的学生。like指包含,字段中包含’李’;’%%’指李字的左右可能有别的字段。

select * from Score where score like ‘%9%’

注释:查询所有成绩中存在’9’的成绩。

4.5总数查询

select count(1) from Student

注释:查询学生的总量。count指计数;count(1)总数;count(1)和count(*)意义相同,但count(1)效率更高。

select count(1) from subject

注释:查询科目的总量。

4.6排名查询(限制返回的行数)

select top 2 * from Student order by age dose

注释:查询年龄较大的前两名学生。top指排行排名;order by..dese指倒序。

select top 3 * from Score order by score dose

注释:查询成绩较高的前三个成绩。

select top 2 * from Student order by asc

注释:查询年龄较小的前两名学生。

select top 3 * from Score order by score asc

注释:查询成绩较低的前三名成绩。

selece top 5 * from Score order by score dose

注释:查询成绩较高的前五个成绩。

4.7.1分组查询【有域(domain)的约束下】

【注:域也称为属性,是约束’列’的取值范围(比如性别只能取值’男’或’女’)。】

select gender count(1) from Student group by gender

注释:根据性别分类并分别写出每组学生的数量。group by指分组;count(1)指总数。

4.7.2分组查询【列的取值范围较广,且其中有相同值】

select distinct score from Score

select score count(1) from Score group by score

注释:查询一共有多少种分值。distinct指有区别的;count(1)指总数;group by指分组

(字面解释:在成绩表中找出有区别的分数进行分类总结总数)

4.8.1.高级查询-多表查询(右外连接查询)

select Student. studentName, Score. score from Student

right join Score on Score. studentID=Student. studentID

注释:查询学生的分数

4.8.2.高级查询-多表查询(左外连接查询)

select Student. studentName, subject. subjectName, Score. score from Score

left join Student on Score. studentID=Student.studentID

left join Subject on Subject. subjectID=Score. subjectID

where Score. score

注释:查询不及格科目的学生。

4.8.3.高级查询-多表查询倒序排列

select Student. studentName, avg(Score. score) avg, sum(Score. score) sum fromStudent. Score

where Student.studentID=Score.StudentID

group by Student. studentName

order by sum desc

注释:每个学生的平均分和总分,并按照总分倒序排序

软件测试工程师必备技能—数据库基本命令

————————————————

版权声明:本文为CSDN博主「吴欲咋刚」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/m0_64682777/article/details/121742968

来源:吴欲咋刚

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年11月5日
下一篇 2021年11月5日

相关推荐