SQL query on emp table to display the employee name, his salary, sum of his department salary

Write a SQL query on emp table to display the employee name, his salary, sum of his department salary and second highest salary of his department in different columns. This must be done for all the records in emp table. Any help??

Replies

  • [Prototype]
    [Prototype]
    Considering you're using MySQL,

    SELECT * FROM `emp`
    Are you trying to query from php and wants to display the results on the webpage?
  • Neeraj Sharma
    Neeraj Sharma
    [Prototype]
    Considering you're using MySQL,

    SELECT * FROM `emp`
    Are you trying to query from php and wants to display the results on the webpage?
    I am doing it on sqldeveloper. And I am not a noob that I dont know the query that you have given me. Please read my question again and then answer
  • Prashanth_p@cchi
    Prashanth_p@cchi
    select empname sal sum(sal) from emp group by deptno;
    select sal from emp e where sal <
    (select max(sal) from emp ea where ea.deptno = e.deptno) order by sal;

    I am not sure of the above. It has been more that two years, me writing a SQL Query. Hope it might help you in arriving at the solution.
  • Anoop Kumar
    Anoop Kumar
    select e.emp_name, e.Emp_sal,
    (select sum(e1.emp_sal) from emp_tab e1
    where e.dept_id=e1.Dept_id  group by e.Dept_id) as Salary_Sum,
    (Select emp_sal from emp_tab e2 where rownum=2 and
    e2.dept_id=e.dept_it order by e2.emp_salary  desc ) as Sec_High_salary
    from emp_tab e where e.emp_ID='XXXXX'
  • Prashanth_p@cchi
    Prashanth_p@cchi
    ianoop
    select e.emp_name, e.Emp_sal,
    (select sum(e1.emp_sal) from emp_tab e1
    where e.dept_id=e1.Dept_id  group by e.Dept_id) as Salary_Sum,
    (Select emp_sal from emp_tab e2 where rownum=2 and
    e2.dept_id=e.dept_it order by e2.emp_salary  desc ) as Sec_High_salary
    from emp_tab e where e.emp_ID='XXXXX'
    I think this should work... Nice!

You are reading an archived discussion.

Related Posts

Can anybody suggest any opensource IDE for running Django application??
Types of gas turbines and thier 1) Pressure Ratio 2) Air fuel ratio 3) Maximum Temperature in plant 4) Thermal Efficiency ?????????
https://www.instructables.com/id/EDC-The-pocket-knife/?ALLSTEPS

hey

am misgana daniel froom Ethiopia and am very happy that i joind crazy engineers.
what are languages or courses to be done for placements...??