Question

Quis -2 EMPLOYEES EMPLOYEE ID NUMBER(6.0 FIRST NAME VARCHAR NTE) CONSTRAINT EMPLASTNAME NN NOT NULL ENA LAST NAME VARCHAI CON
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the response below:

A. To fetch the employees names having the second highest salary: It uses a nested query.The first part of the query iterates through the maximum of all salaries excluding the maximum salary which is calculated by the second part of the query.

SELECT FIRST_NAME,LAST_NAME, MAX(SALARY) AS salary
  FROM EMPLOYEES
 WHERE salary < (SELECT MAX(SALARY)
                 FROM EMPLOYEES);

B. To return the difference between employee salary and average salary of the employees working in the same department as employee. The first part of the query stores the employee details and salary difference between employee's salary and average salary of employees working in the same department as object x. The second part of the query calculates the average salary of employees working in the department = x.DEPARTMENT_ID and stores it in object y.
SELECT x.EMPLOYEE_ID,
           x.FIRST_NAME, 
           x.LAST_NAME, 
           x.DEPARTMENT_ID, 
          (x.SALARY- y.SALARY) as sal_diff
FROM EMPLOYEES AS x
INNER JOIN (
     SELECT DEPARTMENT_ID, avg(SALARY) as SALARY from EMPLOYEES group by    
             DEPARTMENT_ID) as y
    ON x.DEPARTMENT_ID= y.DEPARTMENT_ID
Add a comment
Know the answer?
Add Answer to:
Quis -2 EMPLOYEES EMPLOYEE ID NUMBER(6.0 FIRST NAME VARCHAR NTE) CONSTRAINT EMPLASTNAME NN NOT NULL ENA...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lesson 10Create the DEPARTMENT tables based on the following: Column Name   ID      Name Data Type     Number...

    Lesson 10Create the DEPARTMENT tables based on the following: Column Name   ID      Name Data Type     Number Varchar2 Length        7      25 Populate the DEPARTMENT table with data from the DEPT table. Include only columns that you need. Create the EMPLOYEE table based on the following table chart: Column Name    ID      LAST_NAME     FIRST_NAME     DEPT_ID Data Type      Number Varchar2      Varchar2       Number Length         7       25            25             7 Modify the EMPLOYEE table to allow for longer employee last names. Confirm your modification. Confirm that both the...

  • Query #2:       List the name of the project and total number of hours worked on by...

    Query #2:       List the name of the project and total number of hours worked on by all the employees on this project, also report the number of employees working on each project. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null,...

  • 1,List the first and last name of the donators that donated in December 2009. 2. List...

    1,List the first and last name of the donators that donated in December 2009. 2. List the ID's of the volunteers that have not worked. 3. List the ID, first name, and last name of any employees who works in the Finance department. 4. List all the different prices suppliers have for 'Tasty Meat' product. 5. Select the store ID and store phone number for all stores in 'St.Paul'. 6. List the member first and last name, address, city, zip...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT