Find all the information at the latest recruits
CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` char(1) NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`)); --------------------------------- select * from employees order by hire_date desc limit 1
Find recruits ranked third time information of all employees
CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` char(1) NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`)); ---------------------------------- select * from employees order by hire_date desc limit 1 offset 2(offset:第几行记录,从0开始)
Find all the staff have been assigned sectors last_name and first_name
CREATE TABLE `dept_emp` ( `emp_no` int(11) NOT NULL, `dept_no` char(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL, PRIMARY KEY (`emp_no`,`dept_no`)); ---------------------------------- CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` char(1) NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`)); ------------------------------------ select last_name,first_name,dept_no from dept_emp join employees on dept_emp.emp_no = employees.emp_no
Find all employees last_name and first_name and the corresponding department number dept_no, but also show employees are not assigned specific sectors
CREATE TABLE `dept_emp` ( `emp_no` int(11) NOT NULL, `dept_no` char(4) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL, PRIMARY KEY (`emp_no`,`dept_no`)); CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` char(1) NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`)); --------------------------------- select last_name,first_name,dept_no from employees left join dept_emp on dept_emp.emp_no = employees.emp_no
Find the entry salary of all employees when given emp_no and salary, and in reverse order according to emp_no
CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` char(1) NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`)); CREATE TABLE `salaries` ( `emp_no` int(11) NOT NULL, `salary` int(11) NOT NULL, `from_date` date NOT NULL, `to_date` date NOT NULL, PRIMARY KEY (`emp_no`,`from_date`)); --------------------------------- select e.emp_no,salary from employees e left join salaries s on e.emp_no = s.emp_no and e.hire_date = s.from_date order by e.emp_no desc
Five MySQL --- 1 day
Guess you like
Origin www.cnblogs.com/luo-bo/p/11129532.html
Ranking