SQL Query to find Nth maximum of Nth row?

1. Queries for Nth maximum Nth row?2. In One table there are 5 fields. empno, ename, deptcd, managr_id, salary.Select the departments whose sum of the salary greater than the sum of salaries of any department?3. When index will be usd in the Query?

Showing Answers 1 - 15 of 15 Answers

Ron

  • Jul 21st, 2006
 

1. Queris for Nth maximum Nth row?

Select * from (select column_name1, column_name1 from table_name order by column_name) where rownum <= N


2. In One table there are 5 fields. empno, ename, deptcd, managr_id, salary.
Select the departments whoose sum of the salary greater than the sum of salaries of any department?

Select deptcd, sum(salary) from table_name group by deptcd orderby salary desc

3. When index will be usd in the Query?
Index is used by the Optimizer when a query is fired in Oracle.

pavithra T.M

  • Sep 18th, 2006
 

how to find starting letters in names in sql query

e.g sachin tendulkar

i want to display S & T in this name

  Was this answer useful?  Yes

pavi

  • Sep 18th, 2006
 

write the query hike the sal of employee

1 year experence 10%

less than one year experence 5%

  Was this answer useful?  Yes

Jagan

  • Oct 12th, 2006
 

select salary

from (select rownum rank, salary

        from ( select salary f

 rom emp order by salary desc))where rank=&N
/

  Was this answer useful?  Yes

Jagan

  • Oct 12th, 2006
 

select salary

     from(select rownum rank, salary

            from ( select salary

                  from emp order by salary desc))

                           where rank=&N
/

this should do the job . . . exactly what you are asking

  Was this answer useful?  Yes

Ratheesh

  • Jun 1st, 2007
 

select a.dept from emp a ,emp b
having sum(a.salary)>sum(b.salary)
group by a.dept

  Was this answer useful?  Yes

dj_dj_dj

  • Aug 13th, 2009
 

RE: 1. Queris for Nth maximum Nth row?2. In One table there are 5 fields. empno, ename, deptcd, managr_id, salary.Select the departments whoose sum of the salary greater than the sum of salaries of any department?3. When index will be usd in the Query?*))select department, max(sum(salary)) from table_name group by department *) Function based index will be used for the above querry.

aswini kumar das

  • Nov 16th, 2011
 

select * from hr.employees e
where n-1 = (select count(salary) from hr.employees where e.salary < salary)

  Was this answer useful?  Yes

nehu

  • Feb 14th, 2012
 

The query to your second question will return all the departments even that department whose total salary is not greater than any department. I guess if the question is to find all departments whose total is greater than any department then the query should be

Code
  1. span style="color: #808080; font-style: italic;">/* hv declared the same cursor bcoz we cannt access the already open cursor in second loop*//* result is a table which store values of desired departments*/

  Was this answer useful?  Yes

nehu

  • Feb 15th, 2012
 

The query to hike the sal of employee

1 year experience 10%

less than one year experience 5%

:-

Code
  1. span style="color: #808080; font-style: italic;">/* empno is a unique key in table emp*//* it is necessary to put where clause here otherwise all salaries in table emp will be updated*/

  Was this answer useful?  Yes

KALYAN KUMAR

  • Feb 23rd, 2012
 

SELECT*FROM EMP WHERE ENAME LIKE S%T;

  Was this answer useful?  Yes

priyank

  • May 10th, 2012
 

Use Case in update statement

  Was this answer useful?  Yes

mahesh

  • Aug 12th, 2013
 


Code
  1.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions