Get highest 3 salary in Oracle 10g

Hello and Welcome back.



This is my first blog since I returned  to Egypt  as I was working in KSA for year and half.



Here's how to get the highest three salaries in HR Schema using SQL.



# Old method was using ROWNUM , but it's not accurate  because it returns the first 3 rows only using the following code :

SELECT   *

  FROM   (  SELECT   last_name, salary

              FROM   employees

          ORDER BY   salary DESC)

 WHERE   ROWNUM <= 3

here's what you  get :

LAST_NAME SALARY
King 24,000
Kochhar 17,000
De Haan 17,000

But  using an other method using Dense_Rank() Over , returns results more accurate.
Here's the code:
SELECT   *
  FROM   (SELECT   last_name, salary,
                   DENSE_RANK () OVER (ORDER BY salary DESC) top_rank
            FROM   employees)
 WHERE   top_rank <= 3
here's what you get :
LAST_NAME SALARY TOP_RANK
King 24,000 1
Kochhar 17,000 2
De Haan 17,000 2
Russell 14,000 3
Thanks for  CodeProject Site

3 comments:

تدوينة تقني ارتقي التكنولوجيا (‪blog3tech‬‏) said...



تحميل أفضل برنامج سناب تيوب الاصفرsnaptube
تدوينة تقني | ارتقي التكنولوجيا

تدوينة تقني ارتقي التكنولوجيا (‪blog3tech‬‏) said...

https://www.adsense7profit.com/


بزنز ملك النت - ادسنس والربح من الفوركس الى تسويق وتجارة العملات, والمال تعديل
الوصف طرق الربح من ادسنس, الحصول على المال من اليوتيوب, كيف تربح من الفيس بوك, جوجل ادسنس, google adsense, العمل عن طريق الانترنت من المنزل, فوركس, تعلم الفوريكس,تحليل فوركس , العملات الرقمية, كيفية الربح من البيتكوين, السيوseo , تحسين محركات البحث, جلب ترافك وارشفة المواقع, امريكي, اعلانات ادسنس, كيفية الربح من جوجل ادسنس, كيفية الربح. تعديل

كيف الربح من جوجل ادسنس adsense

تحميل أفضل برنامج سناب تيوب الاصفر snaptube

Bhrugen Patel said...

If you are looking for the ultimate learning recourse for .NET developers then Dotnetmastery.com is here to provide you best online E-courses to learn the .Net and more courses online at best prices.

Learn blazor