Query to display the nth highest paid employee

Hi All,
Can anybody explain this query?
SELECT empno,ename,sal FROM emp X WHERE &N = (SELECT COUNT(DISTINCT sal) FROM emp WHERE sal >= x.sal);
Thanks in Advance.....
Dins

HIi friend,
This is a correalated subquery and the query will be processed like as below..
for x in(select * from emp a)
loop
count the no of distinct salaries in emp such taht the sal is greater then or equal to x.sal
if (that count <=n)
then
keep the record
end if
end loop
Hope it will help.
Regards
Timir

Similar Messages

  • Query for selecting the 4 highest marks of the student

    query for selecting the 4 highest marks of the student

    Guys dont start an argument,
    tey this one; please
    Hi,
    Try this
    Top 4
    Select ename,
    sale
    From dept d,
    emp e1
    Where d.deptno = e1.deptno
    And &p > (Select Count(e2.sal)
    From emp e2
    Where e2.sal > e1.sal
    And e2.deptno = e1.deptno
    Order By 1,2
    Bottom 4
    Select ename,
    sale
    From dept d,
    emp e1
    Where d.deptno = e1.deptno
    And &p > (Select Count(e2.sal)
    From emp e2
    Where e2.sal < e1.sal
    And e2.deptno = e1.deptno
    Order By 1, 2
    &P you use any value say 3,4,5,6
    This is top N analysis
    Regards
    Umesh

  • Very Important (Query to display the output in required format)

    CREATE TABLE TEMP(X VARCHAR2(10),Y VARCHAR2(100));
    INSERT INTO TEMP('RIDER1','2001-12;2002-32;2003-42');
    INSERT INTO TEMP('RIDER2','2001-52;2003-72');
    SELECT * FROM TEMP
    Initial Out Put in 2 columns X/Y_
    X Y
    RIDER1 2001-12;2002-32;2003-42
    RIDER2 2001-52;2003-72
    Write a Query to display the above data in the format below in 3 columns A/B/C*
    A B C
    Rider1 2001 12
    Rider1 2002 32
    Rider1 2003 42
    Rider2 2001 52
    Rider2 2003 72

    So your old version doesn't support Regular expression. It will be very easy and efficient if you could use regular expression.
    SQL> SELECT x,TRIM(REGEXP_SUBSTR(col2,'[^-]+', 1, 1)) col2,
      2           TRIM(REGEXP_SUBSTR(col2,'[^-]+', 1, 2)) col3
      3   FROM (
      4     SELECT DISTINCT x,regexp_substr (y, '[^;]+', 1, level) col2 
      5     FROM temp 
      6     CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (y, '[^;]+'))  + 1
      7     ORDER BY 1,2
      8        );
    X          COL2
    COL3
    RIDER1     2001
    12
    RIDER1     2002
    32
    RIDER1     2003
    42
    X          COL2
    COL3
    RIDER2     2001
    52
    RIDER2     2003
    72But for your version you can use something like
    SQL> /* By curtesy Frank Kulash */
    SQL> SELECT x,SUBSTR(the_value,1,INSTR(the_value,'-',1)-1) col2,
      2           SUBSTR(the_value,INSTR(the_value,'-',1)+1)col3
      3  FROM (
      4        SELECT DISTINCT x,SUBSTR(y,
      5                            DECODE(level,
      6                                   1,
      7                                   1,
      8                                   INSTR(y, ';', 1, level - 1) + 1),
      9                            DECODE(INSTR(y, ';', 1, level),
    10                                   0,
    11                                   length(y),
    12                                   instr(y, ';', 1, level) -
    13                                   DECODE(level,
    14                                          1,
    15                                          0,
    16                                          INSTR(y, ';', 1, level - 1)) - 1)) the_value
    17                FROM temp
    18              CONNECT BY level <=
    19                         LENGTH(y) - LENGTH(REPLACE(y, ';')) + 1
    20          )
    21  ORDER BY 1,2,3                     
    22       ;
    X          COL2
    COL3
    RIDER1     2001
    12
    RIDER1     2002
    32
    RIDER1     2003
    42
    X          COL2
    COL3
    RIDER2     2001
    52
    RIDER2     2003
    72
    SQL>

  • SQL Query to find the Notify upon Completion employees

    Hi,
    I am looking for a query to find the names of the employees/users who are notified upon the completion of the Concurrent Programs. I know how to find the concurrent program details but not able to find notify upon completion employees details. Please help me.
    Thanks,
    KM

    Thanks Scott for responding. There is no any custom code. Here is the navigation to reach there:
    System Administrator -> Requests -> View -> Specific Requests -> Open any request ->View Details -> Options -> Notify the following people
    I am looking for the query to find these notified people using SQL Query.Query FND_CONCURRENT_REQUESTS table (NOTIFY_ON_PP_ERROR column) -- http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_CONCURRENT_REQUESTS&c_owner=APPLSYS&c_type=TABLE
    Thanks,
    Hussein

  • Designing a query and displaying the query output

    The goal is to create a report (in HTML form) of all the jobs
    (and job-related information) for a given department.
    I envision the department name as a hyperlink to a report
    based on the unique DepartmentID.
    For example, the “Sales” department might contain
    these jobs:
    VP of Sales
    Associate Salesperson
    Sales Assistant
    Each job requires a set of skills and a specific skill level.
    “Persuasion skill” could vary as follows:
    VP of Sales: ADVANCED persuasion skill
    Associate Salesperson: MODERATE persuasion skill
    Sales Assistant: BASIC persuasion skill
    “Communication skill” could vary as follows:
    VP of Sales: EXPERT communication skill
    Associate Salesperson: ADVANCED communication skill
    Sales Assistant: NOT REQUIRED
    And so on…
    Each job has roughly 20 skills that are related to it.
    I’d like to display this information in a table with
    the skills listed in rows, the job titles listed in column
    headings, and the skill level (e.g., ADVANCED) located in the
    appropriate cell where the skill and job title intersect. That way,
    the reader can easily compare skill levels across jobs.
    The requisite tables are below. (A field name preceded by
    “frn_” is the foreign key related to another
    table’s primary key.)
    Table: Departments
    Fields: DepartmentID, DepartmentName
    Table: Jobs
    Fields: JobID, JobTitle, frn_DepartmentID
    Table: Skills
    Fields: SkillID, SkillName
    Table: Skill_Levels
    Fields: Skill_LevelID, Skill_Level_Description
    Table: JobSkills (this table “links” a job,
    skill, and skill level)
    Fields: JobSkillID, frn_JobID, frn_SkillID, frn_Skill_LevelID
    I'm not sure how to do this, so thank you for any help!
    Luke

    You're correct; I want to display the data as you described,
    with one slight change.
    Instead of the words "expert" or "basic," the proficiency
    ratings should be displayed as numbers, e.g., "1" for "basic, "3"
    for moderate, and "5" for expert. (Table: KSAProfRatings contains
    fields for both, i.e, Field: PRStatement for "basic", "moderate",
    "expert" etc. and Field: PRRating for "1", "2", "3", etc. I want to
    use Field: PRRating)
    Table: KSAs contains Field: KSAStatement, which contains the
    skills. In addition to skills, Field: KSAStatement also contains
    knowledges and abilities.
    So, in addition to the skills that I mentioned above, there
    might be a knowledge, such as "Knowledge of company products &
    services," and an ability, such as "Ability to communicate
    effectively." These knowledges and abilities receive a proficiency
    rating just like the skills.
    There is conceptual overlap among knowledges, skills, and
    abilities (KSAs), so I had referred only to "skills" for clarity.
    The query that I posted reflects the actual table names,
    e.g., Table: KSAs instead of Table: Skills, and Table:
    KSAProfRatings instead of Table: Skill_Levels (see my first post),
    but the principle is the same.

  • Query to display the tables with referential integrity

    Hello,
    I need to display the Tables which are having referential integrity..
    Like need to dispaly the parent and child tables
    Please give me some idea on this..
    Thanks,

    Here's a nice query you can use:
    with temp_constraints as (
    select table_name
    ,      constraint_name pkey_constraint
    ,      null fkey_constraint
    ,      null r_constraint_name
    from   user_constraints
    where  constraint_type = 'P'
    union all
    select a.table_name
    ,      a.constraint_name pkey_constraint
    ,      b.constraint_name fkey_constraint
    ,      b.r_constraint_name
    from   user_constraints a, user_constraints b
    where  a.table_name = b.table_name
    and a.constraint_type = 'P'
    and b.constraint_type = 'R'
    select rpad( '*', (level-1)*2, '*' ) || table_name relation
    from   temp_constraints
    start with fkey_constraint is null
    connect by pkey_constraint <> r_constraint_name
    and prior  pkey_constraint = r_constraint_name;From http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:661009003696#tom69115451356231

  • I want to include/display the absence details for employee

    Hi
    I want to display the absence details for an employee in the payslip.
    Please guide.
    Minal

    Hi
    I think you got the solution .
    Please do one thing tell the note number and close the thread.
    So that it may be useful for others.
    Manoj Shakya

  • Query to display the exact match product at top or increase the nearness

    Hello All,
    I am using the iStore search and it is returning results for Part Number and Description search. If I am searching a particular Part Number , it is displaying the particular product and its related products. I need the exact matched product in the first row (topmost).
    When I checked the back-end query, It is using contains for powerful search.
    How can I display the exact match product at top or increase the nearness in search.
    Please help.
    I have seen a similar thread in the forum.
    Contains: exactly match
    Thanks in advance,
    Muhammed Aslam
    Edited by: tpmuhammedaslam on Jan 10, 2013 3:48 AM

    Hello Muhammed Aslam,
    If fuzzy search is enabled, then cannot search by part number.
    The seeded query for iStore product search is based on the description as follows:
    Product Search (Section Search - R12)
    select * from
    (select T.*, RowNum as row_num
    from (select inv_item_id INVENTORY_ITEM_ID
    ,description DESCRIPTION
    ,0 CATEGORY_ID
    ,nearness NEARNESS
    ,concatenated_segments CONCATENATED_SEGMENTS
    ,primary_uom_code PRIMARY_UOM_CODE
    ,primary_unit_of_measure PRIMARY_UNIT_OF_MEASURE
    from (SELECT * FROM (select /*+ FIRST_ROWS leading(i) INDEX (x,IBE_SECTION_SEARCH_U1) */
    distinct i.inventory_item_id, i.description, 0
    ,x.inventory_item_id inv_item_id, score(100) nearness
    ,mtl_system_items_b_kfv.concatenated_segments,
    mtl_system_items_b_kfv.primary_uom_code,
    mtl_system_items_b_kfv.primary_unit_of_measure
    from ibe_ct_imedia_search i,ibe_section_search x
    ,mtl_system_items_b_kfv
    where contains (i.indexed_search, :1 , 100) > 0
    and i.language = userenv('LANG')
    and i.organization_id = :2
    and i.web_status='PUBLISHED'
    and x.inventory_item_id = i.inventory_item_id
    and i.inventory_item_id = mtl_system_items_b_kfv.inventory_item_id
    and i.organization_id = mtl_system_items_b_kfv.organization_id
    and x.minisite_id = :4
    and x.organization_id =:5
    order by nearness desc ) WHERE rownum < :6
    ))T
    where rownum where row_num >= :8
    Product Search (Category Search - R12)
    select * from
    (select T.*, RowNum as row_num
    from (select inventory_item_id INVENTORY_ITEM_ID
    ,description DESCRIPTION
    ,category_id CATEGORY_ID
    ,nearness NEARNESS
    ,concatenated_segments CONCATENATED_SEGMENTS
    ,primary_uom_code PRIMARY_UOM_CODE
    ,primary_unit_of_measure PRIMARY_UNIT_OF_MEASURE
    from (select i.inventory_item_id, i.description, i.category_id
    ,score(100) nearness
    ,mtl_system_items_b_kfv.concatenated_segments
    ,mtl_system_items_b_kfv.primary_uom_code
    ,mtl_system_items_b_kfv.primary_unit_of_measure
    from ibe_ct_imedia_search i,
    mtl_system_items_b_kfv
    where contains (i.indexed_search, :1 , 100) > 0
    and i.language = userenv('LANG')
    and i.web_status='PUBLISHED'
    and i.organization_id = :3
    and exists (select 1
    from ibe_dsp_section_items s,ibe_dsp_msite_sct_items b
    where s.section_item_id = b.section_item_id
    and b.mini_site_id = :4
    and s.inventory_item_id = i.inventory_item_id
    and (s.end_date_active > sysdate or s.end_date_active is null)
    and s.start_date_active < sysdate)
    and rownum < :5
    and i.inventory_item_id = mtl_system_items_b_kfv.inventory_item_id
    and i.organization_id = mtl_system_items_b_kfv.organization_id
    order by nearness desc ))T
    where rownum where row_num >= :7
    Regards,
    Debbie

  • SQL query to display the price of an ITEM

    Hi to all:
    Can some one guide me which tables I have to use to display the price of specific item?
    Ali

    Hi,
    If you want to find out the price for that item which is included in the price list, then use the following tables.
    qp_list_headers - Price List Headers details
    qp_list_lines - price list line details ( link PRODUCT_ATTR_VALUE with the inventory_item_id of the item)
    Regards,
    Jyoti

  • Query to retrieve the second highest managers salary

    select * from employees where salary=(select max(salary) from employees e where employee_id=e.manager_id and salary<(select max(salary) from employees)
    this is not executing . . .can anyone suggest new one

    Hi,
    987184 wrote:
    hii,
    it is displaying as invalid character at sal_rank=2
    select salary from (
    ( select salary
    , dense_rank() over (order by salary) as sal_rank
    from employees
    where job_id = 'PU_CLERK'
    where sal_rank = 2;
    /You have unbalanced parentheses. You have 4 left '('s, but only 3 right ')'s
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as query results, as well as code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    Why do you end the statement with a ';', and then a '/'?  Won;t either of them do what you want, without the other?
    Remember that the default sorting order is <b>ASC</b>ending (smallest first).  In this problem, don't you want <b>DESC</b>ending order (largest first)?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Query to display the following output

    Hello,
    I am using Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production.
    My table structure is
    Loaneenumber varchar2(10),
    Loaneename varchar2(50),
    Loantype varchar2(30),
    Balance_amount number(12,2),
    Remarks varchar2(200)
    Sample data
    insert into test values ('01002S001', ' Srinivas K.' , ' Advance', ' 25000', '200708 Outstanding loans');
    insert into test values ('01002S001', ' Srinivas K.' , ' Advance', ' 22500', '200607 Outstanding loans');
    insert into test values ('01002S001', ' Srinivas K.' , ' Advance', ' 5000', 200506 Out Standing Loan For Advance);
    I need to display output as follows
    Loaneenumber Loaneename Loantype Inputs0708 Inputs0607 Inputs0506
    01002S001 Srinivas K. Advance 25,000 22,500 5,000
    Years 200708, 200607 are in remarks column. Can I use like operator in decode function?
    For one year data I have written the following query
    SELECT loaneenumber,
    loaneename,
    loantype,
    balance_amount as "Inputs0708"
    FROM cmsloanissuetransaction
    WHERE balance_amount >0
    AND loantype NOT IN ( 'Bank Loan' ,
    'LOANS 2001-02',
              'LOANS 2002-03',
              'LOANS 2003-04',
              'LOANS 2004-05')
    AND loancategory ='RYOT'
    AND (remarks NOT LIKE '200506%' AND remarks NOT LIKE '200607%')
    How to display three years data side by side?
    Regards
    Krishna
    Edited by: KRKP on Sep 17, 2008 9:08 PM

    Try this..
    SELECT loaneenumber,
    loaneename,
    loantype,
    (case
    when remarks LIKE '200708%' then balance_amount) as "Inputs0708" ,
    (case
    when remarks LIKE '200607%' then balance_amount) as "Inputs0607" ,
    (case
    when remarks LIKE '200506%' then balance_amount) as "Inputs0506" ,
    FROM cmsloanissuetransaction
    WHERE balance_amount >0
    AND loancategory ='RYOT'

  • HR BAdi to display the header data of employee (PA30)

    Hello All,
    I am using transactions PA30 and PA20 to change the HR master data. I will explain my problem as follows.
    1) Transaction pa30. Enter personal number. Press enter. Screen will display employee basic info at header, just before selecting the any infotype. SSN number is also displayed for USA employee.
    2) I will select infotype 0002, change the SSN number, save it. before saving, in function module exit:EXIT_SAPFP50M_002 (INCLUDE ZXPADU02) , i am encrypting the SSN number and then stores it in DB.
    3) In BADI HRPAD00INFTY(BEFOE_OUTPUT), i am taking same encrypted SSN number form DB, decrypt it, and showing on screen.
    But the header part is still showing encrypted value. It is not decrypting the value before display. After investigation i found that, while displaying header part, mentioned Badi is getting called. I want to decrypt he same before display in header part only. It is working fine with detailed part (Means 0002 infotype screen).
    Which Badi should i use to decrypt the SSN number, before display it in header part??
    Any help??
    Thanks,
    Prashant

    Hi Prashant,
    The Badi method is triggering before the PBO, Means before infotype screen 3000
    In your requirement you have to implement the method AFTER_INPUT rather than BEFORE_OUTPUT in the same BADI implementation
    This will work, Try it out.
    Thanks
    Pavan
    Edited by: pavan kanike on Jan 30, 2009 7:34 PM

  • Query on display the Alv output,...................its urgent pls help

    hi friends,
        Here is my query on a Alv Report output display
      I have two internal tables i_vbak and i_vbap
    i_vbak contains the fields and value as
    vbeln     kunnr    auart  audat                   bstnk   vkorg
    1000066         1000071  ze0r   20070918       Itest1     PA11
    1000067         1000072  ze0r   20070919       SLA-Test1  PA11
    i_vbap contains the field and value as
    VBELN             MATNR             ARKTX
    1000066    SAMPLE MATERIAL1   Sample Material for reports
    1000066    SAMPLE MATERIAL    Sample Material for reports
    1000066    TEST   MATERIAL       Test Material for reports
    1000067    SAMPLE MATERIAL    Sample Material for reports
    1000067    TEST MATERIAL         Test Material for reports
    1000067    SAMPLE MATERIAL1   Sample Material for reports
    I have a another internal table called inv_final which contain all these fields and respective values to display in the alv output.Here i am giving only two field how it whould come in alv output.
    Sold to Patry(kunnr)  Sales Doc No(vbap-vbeln)    Material Name(matnr)
    1000071                  1000066                  Sample Material1
    1000071                  1000066                  Sample Material
    1000071                  1000066                  Test Material
    1000072                  1000067                  Sample Material 
    1000072                  1000067                  Test Material
    1000072                  1000067                  Sample Material1
    If anybody have done similay kind of repore than help me with the code,or else if anybody having any idea to solve this out than help me.I have only prob with the logic bofore the final table display in the alv output.
    Helpful answer will be rewardad generously.
    Thanks a lot
    mrutyun^

    Hi
    Put all the fields in to an internal table and disply only your required fields.
    Kuntal

  • Query to display the user's and their group's

    Hi ---Is there a way to list the user and the roles that were assigned to them by running a query on the Data base? also can we configure development obiee environment to use prod security so that if removed from prod, will also be removed form dev?

    user007009 wrote:
    Hi ---- my bad. version is 11g and currently not using WLS LDAP but through LDAP server(AD) configured in Web logic console.
    Also regarding not possible if using WLS Ldap.
    Where does these user data gets saved then?? xml?,database table?, ff?.. or was it mentioned in the oracle documentation that we can't get the info??..please throw some light..
    any idea on what actually is the source for the page security>realms>users and groups? ... they might be saving it some where and i am having hard time finding it in the Oracle Documentation as well.I suggest you read this : http://docs.oracle.com/cd/E23943_01/core.1111/e10043/introroles.htm
    And https://blogs.oracle.com/robreynolds/entry/security_in_obiee_11g_part_1 to know more about Security. The default users would be in identity store.
    If you want to get the list of WLS users and WLS groups then have a look at : http://mverzijl.wordpress.com/2012/08/23/weblogic-wlst-get-users-and-groups/
    Coming to your original questions .. To get the list of AD users and AD groups not Roles two different things, may be you can try
    http://social.technet.microsoft.com/wiki/contents/articles/2195.active-directory-dsquery-commands.aspx or use some LDAP browser .
    SVS

  • Finding nth highest salary

    Hi guys , I am trying to find the nth highest salary
    using the below query , is there any case in which the below query can fail
    select
    * from (
    select
    distinct rownum rn,salary from emp_mgr order by rownum) t where t.rn=3

    chris227 wrote:
    Sory, may be i am blind, dont see it yet.
    Doesnt the Nth high paid employee earns the Nth highest salary?
    No. Multiple employees can earn same salary. Look at EMP table:
    SQL> select ename,sal from emp order by sal desc;
    ENAME             SAL
    KING             5000
    FORD             3000
    SCOTT            3000
    JONES            2975
    BLAKE            2850
    CLARK            2450
    ALLEN            1600
    TURNER           1500
    MILLER           1300
    WARD             1250
    MARTIN           1250
    ENAME             SAL
    ADAMS            1100
    JAMES             950
    SMITH             800
    Highest salary 5000. Second highest salary is 3000. Third highest salary is 2975. Now look what NTH_VALUE returns:
    SQL> select distinct sal
      2    from (select nth_value(sal,&n) over(order by sal desc) sal from emp)
      3  /
    Enter value for n: 1
    old   2:   from (select nth_value(sal,&n) over(order by sal desc) sal from emp)
    new   2:   from (select nth_value(sal,1) over(order by sal desc) sal from emp)
           SAL
          5000
    SQL> /
    Enter value for n: 2
    old   2:   from (select nth_value(sal,&n) over(order by sal desc) sal from emp)
    new   2:   from (select nth_value(sal,2) over(order by sal desc) sal from emp)
           SAL
          3000
    SQL> /
    Enter value for n: 3
    old   2:   from (select nth_value(sal,&n) over(order by sal desc) sal from emp)
    new   2:   from (select nth_value(sal,3) over(order by sal desc) sal from emp)
           SAL
          3000
    SQL> /
    Enter value for n: 4
    old   2:   from (select nth_value(sal,&n) over(order by sal desc) sal from emp)
    new   2:   from (select nth_value(sal,4) over(order by sal desc) sal from emp)
           SAL
          2975
    SQL>
    SY.

Maybe you are looking for