【数据库】MySQL相关操作

--批量插入数据
insert into 
actor (actor_id, first_name, last_name, last_update)
values 
(1,'PENELOPE','GUINESS','2006-02-15 12:34:33'),(2,'NICK','WAHLBERG','2006-02-15 12:34:33');

--找出所有员工当前(to_date='9999-01-01')具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示
select distinct salary from salaries 
where to_date='9999-01-01' order by salary desc;

--查找最晚入职员工的所有信息
select *from employees order by hire_date desc limit 0,1;

select *from employees where hire_date in (select max(hire_date) from employees);

select *from employees where hire_date = (select max(hire_date) from employees);

--查找入职员工时间排名倒数第三的员工所有信息
select *from employees order by hire_date desc limit 2,1;

--查找薪水涨幅超过15次的员工号emp_no以及其对应的涨幅次数t
select emp_no, count(emp_no) as t from salaries group by emp_no having t>15;

--获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'
select dept_manager.dept_no, dept_manager.emp_no, salaries.salary
from dept_manager, salaries
where dept_manager.emp_no = salaries.emp_no
and dept_manager.to_date = '9999-01-01'
and salaries.to_date = '9999-01-01';

--从titles表获取按照title进行分组,每组个数大于等于2,给出title以及对应的数目t
select title, count(emp_no) as t from titles group by title having t>=2;

--Write a SQL query to find all duplicate emails in a table named Person.(编写一个SQL查询来查找名为“人”的表中的所有重复邮件)
select email from person group by emial having count(email)>1;

--Write a SQL solution to output big countries' name, population and area.(编写一个SQL解决方案,输出大国的名字、人口和地区)
select name, population, area from world where area>3000000 and population>25000000;

select name, population, area from world where area>3000000
union
select name, population, area from world where population>25000000;


--Write a SQL query to get the nth highest salary from the Employee table(编写SQL查询,从雇员表中获得第N个最高工资)
set M=N-1;
select distinct salary from Employee order by desc limit M,1;

猜你喜欢

转载自blog.csdn.net/wxj_enchanted/article/details/84718326