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)?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Retrive the second-highest value from the table using query.

    Hi,
    I am using Oracle 8i...
    I have to retrieve the second-highest salary from the table...for this I need to write a SQL..Can anybody please help me to figure out this problem..Thanks in advance..
    smitha

    Using analytic functions
    SELECT *
    FROM (SELECT other_columns,DENSE_RANK() OVER(ORDER BY salary DESC) sal_rank
          FROM table)
    WHERE sal_rank = 2
    Using Order by and rownum
    SELECT *
    FROM (SELECT other_columns,rownum sal_rank
          FROM (SELECT other_columns,salary
                FROM table
                ORDER BY salary DESC))
    WHERE sal_rank = 2TTFN
    John

  • Query to retrieve the number of transactions done in every 1 hour for last

    Hi,
    Could anyone help in writing a query to retrieve the number of transactions done in every 1 hour for last month.
    Case:
    I/P
    Cases Timestamp1
    case1 01-01-2008 00:00:01
    case2 01-01-2008 00:01:01
    case3 01-01-2008 01:00:01
    case1 01-01-2008 01:02:01
    case4 01-01-2008 01:10:01
    case5 02-01-2008 02:00:01
    case6 02-01-2008 02:10:01
    case7 02-01-2008 23:00:01
    case.. 31-01-2008 24:00:00
    O/P
    from time to_time cases
    01-01-2008 00:00:00 01-01-2008 01:00:00 2
    01-01-2008 01:00:01 01-01-2008 02:00:00 3
    etc
    Any help really appreciated

    We can do this using analytical functions
    Following is what I did:
    create table timestamp1 (ts date)
    select *from timestamp1
    30/10/2008 15:41:13
    30/10/2008 15:41:05
    30/10/2008 15:40:03
    30/10/2008 14:58:26
    30/10/2008 14:29:45
    30/10/2008 13:17:48
    30/10/2008 08:29:50
    30/10/2008 06:05:51
    30/10/2008 03:41:52
    30/10/2008 02:29:54
    select distinct to_char(ts,'hh24') frmhrs,
    to_char(ts,'hh24')+1 tohrs, count(ts) OVER (order by to_number(to_char(ts,'hh24')) RANGE (1/24) PRECEDING )
    from timestamp1
    where trunc(ts)=trunc(sysdate) -- I added this just to make sure I get for today's data
    order by frmhrs
    FRMHRS     TOHRS     CNT
    02     3     1
    03     4     1
    06     7     1
    08     9     1
    13     14     1
    14     15     2
    15     16     3
    You can customizeas per ur need.

  • Query to find the  second maximum date in a table

    please give me the query to find the second maximum date in a table

    You can try with this
    SELECT empno
          ,hiredate
      FROM emp        a
    WHERE 2          = (SELECT COUNT(DISTINCT hiredate)
                           FROM emp        b
                          WHERE b.hiredate      >= a.hiredate
    OR
    SELECT empno
          ,hiredate
      FROM (SELECT ROWNUM      row_num
                  ,empno
                  ,hiredate
              FROM emp        a
          ORDER BY hiredate   ASC
    WHERE row_num             = 2;Regards
    Arun

  • 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

  • SQL Query to retrieve the All records based on the Max Dates.

    Hello all,
    I am trying to retrieve the newest record based on the date field (  nextDate  ).
    Currently there are only 4 records in the MC_Maintenance table and two in the Machine table.
    Machine table
    MC_id             EquipID          
    1                      0227
    MC_id             EquipID
    2                     0228
    MC_Maintenance table
    Maint_id           MC_id             Next_maint                  
    1                      2                      08/25/2010     
    2                      2                      07/01/2010
    3                      1                      06/11/2010
    4                      1                      07/11/2010
    What I  am trying to accomplish is,
    list the two machines from the Machine table with the MAX(Next_maint) controlling the MC_Maintenance output list
    These are the records that I would like to Display.
    Maint_id           MC_id             Next_maint                  
    1                      2                      08/25/2010
    4                      1                      07/11/2010                 
    Below is the SQL Query
    SELECT
           MC.MC_ID as ID,
            MC.complete_Date as completed,
            MC.next_maint as nextDate,
            MC.maint_notes as Notes,
            MC.facility as Facility,
            M.EquipId,
            M.name as name,
            M.SerialNumber as SN,
            M.dept as dept,
            M.Freq as freq
            From  MC_Maintenance MC, Machine M
            where  MC.MC_ID =  M.MC_ID
    '           USING MAX(nextDate )
    Any ideas would help.
    TJ

    I would have thought that was a simple group by problem?
    SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
    FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
    GROUP BY M.EquipID, MC.MC_ID

  • Query - Cannot Retrieve the Data / Result Set

    Hello,
    I'm trying to query a cube through the OLAP connection using Java and every time I try to execute a query an exception is thrown stating "Cannot retrieve the data set" or "Cannot retrieve the result set" depending on how I'm doing the query.  I've tried to execute the query both through the use of an IBIQuery and IBICommandProcessor object as well as directly through the IBIOlap connection via an MDX statement and both methods produce the same exception.  If anyone can shed some light on why exception is being thrown it would be greatly appreciated.

    please help me ... The question has nothing to do with 'getting' data from excel and certainly not with putting it into MySQL.
    The stack trace specifically tells you that your connection string is wrong.
    It also tells you which connection string is wrong.
    Which you can use to determine specifically which one is wrong. And which you did not provide that info to us.

  • Query to retrieve the records which have more than one assignment_id

    Hello,
    I am trying to write a query to retrieve all the records from the table per_all_assignments_f which has more than one different assignment_id for each person_id. Below is the query i have written but this retrieves the records even if a person_id has duplicate assignment_id's but i need records which have more than one assignement_id with no duplicates for each person_id
    select assignment_id ,person_id, assignment_id
    From per_all_assignments_f
    having count(assignment_id) >1
    group by person_id, assignment_id
    Thank You.
    PK

    Maybe something like this?
    select *
    From   per_all_assignments_f f1
    where  exists (select 1
                   from   per_all_assignments_f f2
                   where  f2.person_id = f1.person_id
                   and    f2.assignment_id != f1.assignment_id
                  );Edited by: SomeoneElse on May 7, 2010 2:23 PM
    (you can add a DISTINCT to the outer query if you need to)

  • SQL Query to retrieve the records

    Hi All,
    I have one table. It contains millions of records.I gave the query as follows.
    select * from emp where empnob in (1,1000)
    it displays empnob
    1 A 300000 Manager
    6 B 120000 Analyst
    87 C 32980 salsman
    Now I want to retrieve remaining records. Pelase let me know the query which are not available in emp table between the given limit.
    Thank you.

    Hi ,
    For example there are 10 records only.
    I gave
    select * from emp where empno in (1,10)
    t displays the records having the empnos 1,3,4,6,8
    Now I want to display the records 2,5,7,9,10 also...
    Please let me know the query.Are use using an oracle database? My Oracle database would never return such a result for your query.
    Please post some output from an sqlplus session where you show us exactly what you do.
    Message was edited by:
    Sven W.

  • Query to retrieve Currency Code for Employee Salary

    Hi,
    I'm stumped by this issue.  Does anyone know what table(s) contain the employee's salary currency code?
    Thanks!
    Bruce Marcoux

    Did you check the business components for the salary page ?
    Check the VO query -
    select fct.name as currency ,fct.currency_code as currency_code from per_pay_bases ppb ,pay_input_values_f piv ,pay_element_types_f pet ,per_all_assignments_f paa ,fnd_currencies_tl fct where paa.pay_basis_id = ppb.pay_basis_id and ppb.input_value_id = piv.input_value_id and piv.element_type_id = pet.element_type_id and fct.currency_code = pet.input_currency_code and fct.language = USERENV('LANG') and paa.assignment_id = :1 and :2 between nvl(paa.effective_start_date,hr_general.start_of_time) and nvl(paa.effective_end_date,hr_general.end_of_time) and :3 between nvl(pet.effective_start_date,hr_general.start_of_time) and nvl(pet.effective_end_date,hr_general.end_of_time) and :4 between nvl(piv.effective_start_date,hr_general.start_of_time) and nvl(piv.effective_end_date,hr_general.end_of_time) 

  • Query to retrieve the 'My Favorites' sub folder names from InfoView

    Please help me with the query which can get all the folder names present in 'My Favorites' in the InfoView, and also query to get all the folder names in 'Public Folders' for the current user?
    Thanks

    To get all the folders under Public Folders accessible by current user:
    1. Logon as that user.
    2. Run the query: select * from ci_infoobjects where si_kind='folder' and si_parentid=0; This only returns the top level folders. To get the subfolders within these folders, you need to make a recursive call changing si_parentid. Si_parentid=0 stands for root, change it with SI_ID of folder for which you are trying to find subfolders. To run the query and get results the user may need some access at the root level ( not granted for a general user by default, granted only for administrator)
    The folders or objects listed under My Favorites are contents of a user's favorite or personal folder and a user should have full access to it by default. To retrieve contents of that:
    select si_id from ci_infoobjects where si_kind='favoritesfolder' and si_name='<user name>' which will give a User's favorite folder and SI_ID of it.
    then call:
    Select * from ci_infoobjects where si_parentid=<SI_ID obtained from previous query>
    will list all the top level objects, folders in a user's favorite folder.

  • SQL Query to retrieve the Workflow Status in MSPS 2010 PWA

    I need to determine the status of stages within a workflow for "incomplete". What DB/Table or Views are required to get this information by project?

    Hi Tom
    You can get all data from Reporting Database, from MSP_EpmWorkflowStatusInformation table, 
    If you want to get what is the actual Stage, you can use some query like this
      SELECT     D.ProjectName, B.PhaseName, A.StageName, 
     D.ProjectUID
    FROM         MSP_EpmWorkflowStage A INNER JOIN
                          MSP_EpmWorkflowPhase B ON A.PhaseUID = B.PhaseUID INNER JOIN
                          MSP_EpmWorkflowStatusInformation C ON A.StageUID = C.StageUID INNER JOIN
                          MSP_EpmProject_UserView D ON C.ProjectUID = D.ProjectUID
                          where C.StageStatus=1
     For each state you have to replace in the query  value for StageStatus  field, take a look to this table MSP_EpmWorkflowStatusType
    All values are there for any status
    StageStatusID LCID
    StageStateDescription
    0 1033
    Not Started
    1 1033
    In Progress (Waiting for Input)
    2 1033
    In Progress (Waiting for Approval)
    3 1033
    In Progress (Workflow Processing)
    4 1033
    Completed
    5 1033
    Completed with errors
    6 1033
    Workflow completed
    Hope this help you.
    Ray Chapa

  • 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

  • What does the "second highest"mean on the macbook pro web page mean? If you have to think too hard then does it need changing as a landing page title ?

    An
    y comments ?

    thanks
    just seemed a strange turn of phrase.
    obviously worked though as I was puzzled enough to  ask :-)

  • The query just run the first time, the second doesnt run

    The query just run the first time, the second doesnt run, i checked it in the SM50 and appear this msg:
    CL_RSR_CACHE_BO_FF============CP
    its not a problem of indexes, i repaired it but its really weird cause the first time the query run ok, the second doesnt, it seems that the cache is confused or i dont know, help guys, i'll really appreciate it

    I was watching the notes, its really weird when i load the cube and execute the query for the first time, its ok, to the second stay in cache, but i was watching that the cube doesnt allow me activat the BD statistics, i dont know if this is necesary to improve the performance of the query, what i know is this:
    1- before i create a Hierarchy for an infoobject thta is in the cube ,  the query used to run ok. Now when i load the first time and execute its ok, but the second stay in cache.
    2- now i can activate the statistics for the cube, the indexes are ok, i checked for the RSRV and all is ok less the statistics.
    what can i do help friends...

Maybe you are looking for