1. SELECT * FROM STUDENTS
Result:
Now:
select sname from (select Row_Number() over (partition by sname order by sname) as ROWNO,
sname from student) p
order by ROWNO,sname desc
Result:
2.List All the Tables for All Databases Using System Tables
sp_msforeachdb 'select "?" AS db, * from [?].sys.tables'
or
sp_msforeachdb 'select * from ?.sys.tables'
3.Find Nth Highest Salary of Employee – Query to Retrieve
the Nth Maximum value
Note:where 'n' stands for nth highest salary.
Result:
Now:
select sname from (select Row_Number() over (partition by sname order by sname) as ROWNO,
sname from student) p
order by ROWNO,sname desc
Result:
2.List All the Tables for All Databases Using System Tables
sp_msforeachdb 'select "?" AS db, * from [?].sys.tables'
or
sp_msforeachdb 'select * from ?.sys.tables'
3.Find Nth Highest Salary of Employee – Query to Retrieve
the Nth Maximum value
SELECT Min(Salary) FROM emp
WHERE Salary IN
(SELECT TOP n Salary FROM emp ORDER BY Salary DESC)
No comments:
Post a Comment