MySQL——数据库测试小结

mac2024-01-27  33

数据库测试

选择题语法:

1.查询

   select ... from 表名 where 分组前的条件 group by 列 having 分组后的条件

2.SQL中的通配符进行字符串匹配的操作(模糊查询)表示

‘_’ (下划线) 表示:0个字符、1个字符

‘%’ 表示:0个字符、1个字符、多个字符

3.索引(index)

(1)索引应该根据具体的检索需求来创建,在选择性好的列上创建索引

(2)索引并非越多越好

(3)建立索引可使检索操作更迅速

//空值的操作: 1.name is null

2.namee is not null

3.not(name is null)

 

4.关于PreparedStatement和Statement的描述

(1)PreparedStatement比Statement执行效率更高

(2)PreparedStatement会预编译SQL语句

(3)Statement每次都会解析/编译SQL,确立并优化数据获取路径

(4)Statement执行扫描的结果集只与SQL有关

5.同构SQL和异构SQL

(1)同构SQL指的是两个SQL语句可编译的部分是相同的,只是参数不一样。

(2)异构SQL指的是两个SQL语句整个的格式都是不同的。

执行同构的SQL的调用接口:PreparedStatement

执行异构的SQL的调用接口:Statement

调用存储过程的接口:CallableStatement

 

6.数据库查询年月,可使用函数,查询年为year(列名),查询月份为month(列名)

例如:查询图书借阅的起始日期是2018年的信息:

select * from brrow_info where year(start_time)=2018

 

程序题:

程序题1:(1)两张表联合查询 (2)用name作为关联条件将两张表进行关联

select A.name,A.grade,B.age from A,B where A.name = B.name

程序题2:单表数据查询 分页

select max(salary) SecondHighestSalary //别名SecondHighestSalary from Employee where Salary <(select max(salary) from Employee)

程序题3:

员工表(staff)、部门表(depart)和薪资表(salary)。

部门表字段:depart_id,name

员工表字段:staff_id,name,age,depart_id 多对一

薪资表字段:salary_id(主键),staff_id(外键) 多对一 ,salary,month

(1)求每个部门2019-09 月份的部门薪资总额

select dep.name, sum(sal.salary) from salary sal join staff sta on dep.depart_id = sta.depart_id join salary sal on sta.staff_id = sal.staff_id where year(sal.month) = 2016 and month(sal.month) = 9 group by dep.depart_id

(2)求每个部门的部门人数,要求输出部门名称和人数

select dep.name, count(sta.taff_id) from staff sta join depart dep on dep.depart_id = sta.depart_id group by sta.depart_id

(3)求公司每个部门的月支出薪资数,要求输出月份和本月薪资总数

select dep.name, sal.month, sum(sal.salary) from depart dep join staff sta on dep.depart_id = sta.depart_id join salary sal on sta.staff_id = sal.staff_id group by dep.depart_id, sal.month

 

最新回复(0)