mysql sub query complex query

Course Title

MySQL database technology

experiment

score

 

Experiment name

Experiment 5: Complex Queries

student ID

 

Name

 

class

 

date

 

Purpose:

1. Master the basic syntax of select statement;

2. Master the use of join queries and subqueries;

experiment platform:

MySQL+SQLyog;

Experiment content and steps:

The following operations are performed in the YGGL database.

First, the subquery exercise:

1. Find out about employees who work in the finance department.

 

2. Use the method of sub-query to find the situation of all employees whose income is less than 2,500 yuan.

 

3. Find the names of employees in R&D who are at least the age of all employees in Marketing.

 

4. Use a subquery to find the names of employees in the R&D department who earn more than all employees in the marketing department.

 

5. Find the name of the employee who earns more than all the employees in the advertising department.

 

6. Use subquery in order by to query employee name, gender and seniority information, and request to press

Actual income is sorted from largest to smallest.

 

Second, the connection query exercise:

1. Check the status of each employee and their salary.

 

2. Use the inner join method to query the department of the employee named "Wang Lin".

 

3. Use the inner join method to find information on all employees who do not work in the advertising department.

 

4. Use the outer join method to find the monthly income of all employees.

 

5. Find the names and salary details of employees in the advertising department who earn more than $2,000.

 

6. Check the names and salaries of employees born before 1966 in the R&D department.

 

 

Experiment summary (conclusion or problem analysis):

      select * from `employees` where  department number IN(select  department number FROM departments where department number=1);

 

select * from employees e,`salary`s

where e.number =s.number and income<2500

 

select 姓名  from employees e,departments d

where 出生日期>=all(SELECT 出生日期 from employees e, departments d

where e.部门号=d.部门号 and d.部门名称='财务部')

and e.部门号=d.部门号 AND d.部门名称='研发部';

 

select 姓名  from employees e,departments d,salary s

where 收入>all(select 收入 FROM employees e,departments d, salary s

where e.部门号=d.部门号 and s.编号=e.编号 and d.部门名称='市场部')

 and e.部门号=d.部门号 and s.编号=e.编号 and d.部门名称='研发部';

 

 

SELECT 姓名 from `employees` e where 部门号 in(

SELECT 部门号 FROM salary s where 

 收入>=all (select 收入 from salary where 编号 

 IN(select 编号 from employees e where  部门号=(select 

 部门号 from departments where 部门名称='研发部'))));

 

 SELECT 姓名,性别 from employees e,`salary`s

 where s.编号=e.编号 ORDER BY 收入 desc;

 

select * from employees e,salary s 

where s.编号=e.编号;

 

select 部门名称 from employees e 

inner join departments d  on e.部门号=d.部门号

where e.姓名='王加';

 

select* from employees e 

inner join departments d  on e.部门号=d.部门号

where d.部门号!='广告部';

 

select * from employees e left outer join salary s 

on s.编号=e.编号;

 

 

select * from employees e inner join salary s 

on s.编号=e.编号 inner join departments d on  

e.部门号=d.部门号 where s.收入>2000;

 

 

select * from employees e inner join salary s 

on s.编号=e.编号 inner join departments d on  

e.部门号=d.部门号 where e.出生日期>'1966' and d.部门名称='研发部';

 

 

 

 

 

 

        

 

 

 

     

 

 

 

            

 

 

 

 

 

 

 

 

 

 

 

 

            

            

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324718024&siteId=291194637