MySql exercise 11.1

MySql exercise 11.1


Implement the following query on the employee table in MySql exercise 10.2 :

1. Find out the details of all managers with department number 10 and all salespeople with department number 20.

select * from employ where (deptno=10 and job='经理')or(deptno=20 and job='销售员');

2. Find out the details of all managers with department number 10, all salespeople with department number 20, and all employees who are neither managers nor salespeople but whose salary is greater than or equal to 2000.

select * from employ where (deptno=10 and job='经理')or(deptno=20 and job='销售员')or(job not in('经理','销售员')and sal>2000);

3. Employees who have no bonus or bonus less than 100

select * from employ where comm<100 or comm is null;

4. Query the detailed information of all employees, sort by number in ascending order

select * from employ order by empno asc;

5. Query the detailed information of all employees and sort them in descending order by salary, and sort them in ascending order by entry date if the salary is the same

select * from employ order by sal desc,hiredate asc;

6. Query the average salary of each department

select deptno,avg(sal)from employ group by deptno;

7. Query the number of employees in each department

select deptno,count(*)from employ group by deptno;

8. Query the maximum wage, minimum wage, and number of people for each job, and sort them in ascending order of number. If the number of people is the same, sort them in descending order of minimum wage.

 select * from employ group by job order by count(*) asc,sal desc;

Guess you like

Origin blog.csdn.net/m0_46653702/article/details/109439428