Monday, February 7, 2011

How to find 2nd Highest salary from emp table

CREATE TABLE EMP1 (ID INT IDENTITY (1,1)  ,SAL INT)
INSERT INTO EMP1 VALUES (2000)
INSERT INTO EMP1 VALUES (3000)
INSERT INTO EMP1 VALUES (4000)
INSERT INTO EMP1 VALUES (9000)
INSERT INTO EMP1 VALUES (1000)

----1.2nd Highest salary from emp table .
SELECT * FROM EMP1
select  *  from emp1  e1
where 1=(select count(distinct e2.sal)  from emp1 e2 where e2.sal > e1.sal)
----2.Identifying the duplicate Records in a table .
select * from emp1
SELECT sal,
 COUNT(sal) AS dupsal
FROM emp1
GROUP BY sal
HAVING ( COUNT(sal) > 1 )

No comments:

Search This Blog

DAX - Grouping on multiple columns and the count

Please go thorugh the below URL for entire soultion. http://community.powerbi.com/t5/Desktop/DAX-Grouping-on-multiple-columns-and-the-cou...