Topic Description
Find out the salary of all employees when they enter the job, give emp_no and salary, and reverse them according to Emp_no
CREATE TABLE ' Employees ' (
' emp_no ' int (one) not null,
' birth_date ' date not null,
' first_name ' varchar no T null,
' last_name ' varchar NOT NULL,
' gender ' char (1) isn't null,
' hire_date ' date not null,
PRIMARY K EY (' emp_no '));
CREATE TABLE ' salaries ' (
' emp_no ' int (one) not null,
' salary ' int (one) not null,
' from_date ' date not Null,
' to_date ' date not NULL,
PRIMARY KEY (' emp_no ', ' from_date '));
Output:
emp_no |
Salary |
10011 |
25828 |
Omitted |
Omitted |
10001 |
60117 |
Problem Solving Solutions
first, we need to be clear about the conditions we need.The two tables first need to be associated with Emp_no because the demand is the salary at the time of the job, so the extra relationship is that the hire_date of the Employees table should be the same as the from_date of the salaries table. So notice here don't leave this constraint (small series I just dropped this ...) This query also examines the ordering, of course, we are familiar with the order by also the reverse DESC keyword
The above code is as follows:
Select Emp.emp_no,ss.salary
from employees as EMP, salaries as SS
where Emp.emp_no=ss.emp_no and
emp.hire_ Date = ss.from_date ORDER by
Emp.emp_no desc