i need department wise top 2 employees salary.which logic
i will use

Answer Posted / nag

select distinct(sal), deptno from
(select * from emp a where 1 = (select count(distinct sal)+1
from emp b where b.sal > a.sal and b.deptno = a.deptno) and
deptno is not null
union
select * from emp a where 2 = (select count(distinct sal)+1
from emp b where b.sal > a.sal and b.deptno = a.deptno)and
deptno is not null)
order by deptno,sal

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is mdf ldf and ndf?

560


Explain the select statement in sql?

611


What are character functions in sql?

494


what are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee (eno int(2),ename varchar(10)) ? : Sql dba

611


Why we use joins in sql?

536






What is pl sql variable?

502


What is trigger and types?

562


Are subqueries faster than joins?

573


C. Normalize the following data up to the 3rd Normal form. Create the tables and insert the data given. Emp_ID Name Dept_Name Salary Course_Title Date_Completed 100 Adam Marketing 48,000 SPSS 6/19/2008 Surveys 10/7/2008 140 Bob Accounting 52,000 Tax Acc 12/8/2008 110 Cathy IT SQL Server 1/12/2008 C# 4/22/2008 190 Dan Finance 150 Emily Marketing 55,000 SPSS 6/16/2008 42,000 Analysis 8/12/2008 Queries 1. Find all Names who have completed the SPSS Course. 2. Find employee with max salary. 3. Find employee with 2nd max salary. 4. Find all employees in Dept “Marketing”. 5. Find all the employees who have taken more than 2 courses. 6. Find all the employees who have completed the courses before month of September.

2171


What version is sql?

553


What is the difference between having and a where in sql?

570


What are schema-level triggers?

575


Which version of sql do I have?

558


What are the types of triggers in sql?

496


Does sql profiler affect performance?

553