Find the salary status of all employees

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.