Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Require a single query for my problem...

Status
Not open for further replies.

ShahKaran

Programmer
Aug 3, 2005
6
IN
Hi All,
Am trying to solve a query but am stuck at a point... the query is...

"Print details of 7 employees from emp talbe which have maximum sal"

Have found the way to print all the emps who have max sal but cant find a way to print 7 of them? (It doent matter if they are the first or last 7 ) . i want to print only 7 records.....
Should i go for a procedure or there happens to be another way to solve this problem


Regards,
Karan
 
Hi Mufasa,

Good one,, By the way am a professional working in a company. If u think that its a class assignment then be it.. ( And by the way am not cheating any one here... santa !! :) )
But am looking for a much efficient way to solve this query... if any help is provided it would be thankful... Else will solve it by the way i have wrote it in the first place.

Regards,
Karan
 
Karan,

Please don't take my inquiry personally. Tek-Tips requires that we either Red-Flag threads that appear to be student posts or we must otherwise determine that a thread poster is a professional. You have confirmed that you are a professional.

Here is code that efficiently resolves your need. I recommend your saving it to a script and running it from a script for the best aesthetic results. (I chose "tt_264.sql" as my script name.):
Code:
set echo off
set feedback off
set pagesize 0
prompt
select count(*)||' employees have the top salary of '||max(salary)
from employees
where salary = (select max(salary) from employees)
/
prompt
prompt Following are 7 of those top-paid employees
set pagesize 35
col employee_name format a20
select employee_name, salary
from (select rownum rn, first_name||' '||last_name employee_name, salary
        from employees
       where salary = (select max(salary) from employees))
where rn <= 7
/
set feedback on

SQL> @tt_264

13 employees have the top salary of 5250

Following are 7 of those top-paid employees

EMPLOYEE_NAME            SALARY
-------------------- ----------
Carmen Velasquez           5250
Midori Nagayama            5250
Audry Ropeburn             5250
Roberta Menchu             5250
Antoinette Catchpole       5250
Colin Magee                5250
Yasmin Sedeghi             5250
Let us know if this is what you wanted.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
Mufasa,
First of all... am sorry if by any means i have offened the laws by which this theads work. Am quite new to this threads. So now i'll take my last question as a learning point for future.

& for the solution i'll try it out & then let you know wether it will fit to the effective query type that i was looking for. But by having a glance at it right now, it seems to be perfect.

& Most of all , Thanx for your help. & makeing me aware of the rules of posting threads in this group.


Regards,
KAran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top