1. Write a query to select the second highest salary from a table.
SELECT max(salary) AS salary2 FROM orders WHERE salary < (SELECT max(salary) AS salary1 FROM orders)
2. Write a query to select the 5th highest salary from a table.
SELECT min(salary) AS high5 FROM employee WHERE salary IN(SELECT DISTINCT TOP 5 salary FROM orders ORDER BY salary DESC)
3. How to find duplicate records with the number they are duplicated?
SELECT Id, count (*) as number_records from table group by id having count (*) > 1.
4. Write a SQL Query to find first Week Day of month?
SELECT DATENAME(dw, DATEADD(dd, - DATEPART(dd, GETDATE()) + 1, GETDATE())) AS FirstDay
No comments:
Post a Comment