Test paying a must-see: 5 steps to teach people how to quickly crack the test database query problem

Mysql query problem, not only exit assessment rate, but also very much affect wage negotiations, so the position is very important 1. Almost all of the software test questions will have Mysql query exercise, high salaries large companies, since candidates, therefore the selection of a better testers, often set up twelve particularly difficult problem Mysql query. 2. If the other topics we have a good answer, but the answer is not good Mysql query challenges, and PK may be down in the interview competition, leading to their favorite companies and missed. Even if a competitor is not strong fluke, but also make us suffer on the back of wage negotiations. 3. On the other hand, if the practice is not only correct the problem Mysql query, fast and problem-solving, it will leave to the employer powerful technique a good impression so immediately throw off competitors. Not only it will take a favorable position on the wage negotiations, but also in their favor in the company's future development.

But embarrassing is that, after a lot of testing to get the novice title but often does not know how to solve problems, not to mention the problem Mysql query. To give you a better grasp Skills of database query, especially working with new technologies to introduce. This article is divided into the following steps:

  1. The first step in preparation for construction of the table statement
  2. The second step will be built into the input table statement navicat established three tables
  3. The third step is to understand three-step inquiry questions do problems
  4. The fourth step, do question the verification step
  5. The fifth step, summary

A first step - to build the table prepared statement

1. Prepare sql data

-- 员工表 employees
-- 工资表 salary
-- 部门表 departments
create table departments (
deptid int(10) primary key, 
deptname varchar(20) not null -- 部门名称
);
insert into departments values ('1001', '市场部');
insert into departments values ('1002', '测试部');
insert into departments values ('1003', '开发部');

create table employees (
empid int(10) primary key,
empname varchar(20) not null, -- 姓名
sex varchar(4) default null, -- 性别
deptid int(20) default null, -- 部门编号
jobs varchar(20) default null, -- 岗位
politicalstatus varchar(20) default null, -- 政治面貌
leader int(10) default null
);

insert into employees values ('1', '王昭君', '女', '1003', '开发', '群众', '9');
insert into employees values ('2', '诸葛亮', '男', '1003', '开发经理', '群众', null);
insert into employees values ('3', '张飞', '男', '1002', '测试', '团员', '4');
insert into employees values ('4', '白起', '男', '1002', '测试经理', '党员', null);
insert into employees values ('5', '大乔', '女', '1002', '测试', '党员', '4');
insert into employees values ('6', '孙尚香', '女', '1001', '市场', '党员', '12');
insert into employees values ('7', '百里玄策', '男', '1001', '市场', '团员', '12');
insert into employees values ('8', '小乔', '女', '1002', '测试', '群众', '4');
insert into employees values ('9', '百里守约', '男', '1003', '开发', '党员', '9');
insert into employees values ('10', '妲己', '女', '1003', '开发', '团员', '9');
insert into employees values ('11', '李白', '男', '1002', '测试', '团员', '4');
insert into employees values ('12', '孙膑', '男', '1001', '市场经理', '党员', null);

create table salary (
sid int(10) primary key,
empid int(10) not null,
salary int(10) not null -- 工资
);

insert into salary values ('1', '7', '2100');
insert into salary values ('2', '6', '2000');
insert into salary values ('3', '12', '5000');
insert into salary values ('4', '9', '1999');
insert into salary values ('5', '10', '1900');
insert into salary values ('6', '1', '3000');
insert into salary values ('7', '2', '5500');
insert into salary values ('8', '5', '2000');
insert into salary values ('9', '3', '1500');
insert into salary values ('10', '8', '4000');
insert into salary values ('11', '11', '2600');
insert into salary values ('12', '4', '5300');

Step two - will be built into the input table statement navicat established three tables

1) New Database test

2) Enter the sql statement to query editor, run

3) Create a data table and paste into excel in

Step three - Learn to do the query topic title three steps

-- 1.看题目字段来源于哪些表,如果是多表,就用内连接
-- (暂不用子查询,除非自己能明确能用子查询或题意要求用子查询)

-- 2.根据题意:灵活选择查询命令,多个查询命令排除先后顺序是
--  where过滤[的]
--  分组(1)显性:每,各 2)隐性:过滤总数[如人数或其他聚合函数]
--  haiving(的)
--  排序[最高的]
--  取值[前几名]

-- 3. 根据题意,select取字段

Four Step Four - do title verification step

Question 1: List the names and political affiliation of all female employees of the marketing department

1) do title step

 

2) to give the title answer

select deptname,count(*) from departments as d inner join employees as e on d.deptid=e.deptid where politicalstatus='党员' group by deptname

2. Display the highest wages of workers before three workers number and name

1) do title step

2) get an answer topics

select e.empid,empname,salary from salary as s inner join employees as e on s.empid=e.empid order by salary desc limit 3

V. Summary

-- 1.看题目字段来源于哪些表,如果是多表,就用内连接
-- (暂不用子查询,除非自己能明确能用子查询或题意要求用子查询)

-- 2.根据题意:灵活选择查询命令,多个查询命令排除先后顺序是
--  where过滤[的]
--  分组(1)显性:每,各 2)隐性:过滤总数[如人数或其他聚合函数]
--  haiving(的)
--  排序[最高的]
--  取值[前几名]

-- 3. 根据题意,select取字段
Published 682 original articles · won praise 1391 · Views 1.71 million +

Guess you like

Origin blog.csdn.net/itcast_cn/article/details/104655796