Monday, July 4, 2011

Static class VS Sealed class

1. Static and sealed classes cannot be inherited.
2. Static cannot be instantiated and but sealed class can be instantiated.
3. In Static class, only static members are allowed.
4. Sealed class will behave as a normal class, we can create instance, but we cannot inherit further.

Friday, April 29, 2011

Nth max salary

declare @N int
set @N = 2

SELECT Salary FROM dbo.Employee E1
WHERE @N = (SELECT Count(Salary) FROM dbo.Employee E2 WHERE E1.Salary <= E2.Salary)

USING Joins:

SELECT A.Salary, count(1) FROM dbo.Employee A
LEFT OUTER JOIN dbo.Employee B ON A.Salary <= B.Salary
GROUP BY A.Salary
HAVING count(1) = 1