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

Similar Messages

  • How to find the structure fields data in database tables?

    how to find the structure fields data in database tables?

    Your question doesn't appear to be Web Dynpro ABAP related. Please only post questions in this forum if they are directly Web Dynpro ABAP related.  There are several other more general ABAP related forums.

  • Query to find the no of columns in a table

    Is there a query to find the total number of columns in a table?

    Dou you know read?
    -- the number of rows in a table named yourtable:
    select count(1) from yourtable;
    -- the number of columns in a table
    -- If is a user's table:
    select count(1)
    from user_tab_columns
    where table_name='YOURTABLE'
    --If it is´t
    select count(1)
    from DBA_tab_columns
    where owner = 'USEROWNER'
    and table_name='YOURTABLE'

  • Query to find the partitioned column(s) of a table.

    Guys,
    I've a partitioned table.I need to know the column(s) of the table which has been selected for partitioning.
    But none of the below tables below provide me the info:
    DBA_TABLES
    DBA_TAB_PARTITIONS
    DBA_TAB_SUBPARTITIONS
    Thoughts plz??
    Regards,
    Bhagat

    Guys,
    I've an index which is partitioned.
    From the resultset below,Would someone help me understand the range of values which each of the partition would hold?
    SQL> SELECT INDEX_NAME,PARTITION_NAME,HIGH_VALUE FROM DBA_IND_PARTITIONS WHERE INDEX_NAME='FACT_605';
    INDEX_NAME                     PARTITION_NAME                 HIGH_VALUE
    FACT_605                       P_A8_2114                      'A8', 2114, MAXVALUE
    FACT_605                       P_G8_2114                      'G8', '2114', MAXVALUE
    FACT_605                       Z_LAST_PARTITION               MAXVALUE, MAXVALUE, MAXVALUE
    Thanks,
    Bhagat                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Find the sequence name for a particular table

    Hi,
    Please give query to find the sequence name for a particular table in oracle.
    Thanks

    I mean getting List of Sequence names defined in DB.
    I got the answers
    select *from user_sequences                                                                                                                                                                                                               

  • Query to find the class name that has the maximum number of students ?

    I need the query to find the [class Name] which has the most number of students. please look below at the tables
    Students Table                                                                     
    StudentId     StudentName  ClassID                                    
    1                  xxx                   1                                           
    2                  yyy                   1                                           
    3                  zzz                   1  
    4                  fff                    2
    5                   ttt                  2
     Classes Table
     ClassID          ClassNane
     1                    CSHARP
     2                    JSHARP
    The result should be : CSHARP
    since there are 3 students in CSHARP and 2 students in JSHARP class
    Appreciate your help
    Thanks

    Try:
    DECLARE @Classes TABLE (
    ClassID INT identity(1, 1) PRIMARY KEY
    ,ClassName VARCHAR(50)
    INSERT INTO @Classes (ClassName)
    VALUES ('CSharp')
    ,('JSharp')
    DECLARE @Students TABLE (
    StudentID INT identity(1, 1) PRIMARY KEY
    ,StudentName VARCHAR(10)
    ,ClassID INT
    INSERT INTO @Students (
    StudentName
    ,ClassID
    VALUES (
    'xxx'
    ,1
    'yyy'
    ,1
    'zzz'
    ,1
    'fff'
    ,2
    'ttt'
    ,2
    SELECT TOP (1)
    WITH TIES C.ClassName
    FROM @Classes C
    INNER JOIN @Students S ON C.ClassID = S.ClassID
    GROUP BY C.ClassID
    ,C.ClassName
    ORDER BY COUNT(S.StudentID) DESC
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Query to find the memory of database in oracle,sql

    Hi All,
    Please let me know the query to find the memory of database in oracle,sql.
    Thanks,
    sajith

    How do I find the overall database size?
    The biggest portion of a database's size comes from the datafiles. To find out how many megabytes are allocated to ALL datafiles:
    select sum(bytes)/1024/1024 "Meg" from dba_data_files;
    To get the size of all TEMP files:
    select nvl(sum(bytes),0)/1024/1024 "Meg" from dba_temp_files;
    To get the size of the on-line redo-logs:
    select sum(bytes)/1024/1024 "Meg" from sys.v_$log;
    Putting it all together into a single query:
    select a.data_size+b.temp_size+c.redo_size "total_size"
    from ( select sum(bytes) data_size
    from dba_data_files ) a,
    ( select nvl(sum(bytes),0) temp_size
    from dba_temp_files ) b,
    ( select sum(bytes) redo_size
    from sys.v_$log ) c;
    Another query ("Free space" reports data files free space):
    col "Database Size" format a20
    col "Free space" format a20
    select round(sum(used.bytes) / 1024 / 1024 ) || ' MB' "Database Size"
    , round(free.p / 1024 / 1024) || ' MB' "Free space"
    from (select bytes from v$datafile
    union all
    select bytes from v$tempfile
    union all
    select bytes from v$log) used
    , (select sum(bytes) as p from dba_free_space) free
    group by free.p
    This is what I use :P From http://www.orafaq.com/wiki/Oracle_database_FAQ#How_do_I_find_the_overall_database_size.3F

  • Query to find the latest record with respect to the current status

    Dear gurus
    I have the following data in a table
    Customernum
    bkcode
    reqtdate
    Prevstat
    currstat
    The data will be like this
    CustomerNum bkcode reqdate prevstat currstat
    5900 1 03-Aug-12 0 1
    5900 1 06-Aug-12 1 0
    5900 5 22-Jun-12 0 1
    If a customer has an issue to solved, a record is added with bkcode , register date and currstat will be 1
    If the issue is resolved for the bookingcode,a new record is added, the currentstatus will become 0. and prev stat will show 1. Row no 1 and 2 reflects this case
    If this table is queried for finding the unresolved issues. the output should be only the Last row of the above example. since issue with bookingcode 1 has been resolved
    I have trying hard to get this thing confused what to use Lead or Max
    Kindly guide me

    Hi,
    one way here:
    WITH mytable(CustomerNum, bkcode, reqdate, prevstat, currstat)
    AS
       SELECT 5900, 1, TO_DATE('03-Aug-12', 'DD-Mon-YY'), 0, 1 FROM DUAL UNION ALL
       SELECT 5900, 1, TO_DATE('06-Aug-12', 'DD-Mon-YY'), 1, 0 FROM DUAL UNION ALL
       SELECT 5900, 5, TO_DATE('22-Jun-12', 'DD-Mon-YY'), 0, 1 FROM DUAL
    SELECT CustomerNum, bkcode, reqdate, prevstat, currstat
      FROM (SELECT a.*
                 , ROW_NUMBER() OVER (PARTITION BY CustomerNum, bkcode
                                           ORDER BY reqdate DESC) AS rn
              FROM mytable a
    WHERE rn=1
       AND currstat=1;
    CUSTOMERNUM     BKCODE REQDATE     PREVSTAT   CURRSTAT
           5900          5 22-JUN-12          0          1Regards.
    Al
    Edited by: Alberto Faenza on Dec 18, 2012 5:23 PM
    Changed again!! Previous logic was wrong

  • Query to find the Salary table details  HRMS 11i

    I am looking  query to find the persons salary details in Oralce EBS 11i.
    I tried the below query bu it didn'ty work.
    SELECT papf.employee_number
    ,papf.full_name
    ,pj.NAME job
    ,haou.NAME ORGANIZATION
    ,ppp.proposed_salary_n salary
    FROM per_all_people_f papf
    ,per_all_assignments_f paaf
    ,per_jobs pj
    ,hr_all_organization_units haou
    ,per_position_definitions ppd
    ,per_all_positions pap
    ,per_pay_proposals ppp
    WHERE 1 = 1
    AND SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date
    AND papf.current_employee_flag = 'Y'
    AND papf.employee_number IS NOT NULL
    AND paaf.person_id = papf.person_id
    AND SYSDATE BETWEEN paaf.effective_start_date AND paaf.effective_end_date
    AND paaf.job_id = pj.job_id
    AND paaf.organization_id = haou.organization_id
    AND paaf.position_id = pap.position_id
    AND pap.position_definition_id = ppd.position_definition_id
    AND ppp.pay_proposal_id = (SELECT MAX (pay_proposal_id)
    FROM per_pay_proposals
    WHERE assignment_id = paaf.assignment_id)
    In our case all the below tables have 0 records..
    select count(*) from PER_PAY_PROPOSALS ;
      COUNT(*)
             0
    select count(*) from pay_element_entry_values_f;
      COUNT(*)
             0
    select count(*) from PAY_ELEMENT_ENTRY_VALUES_F;
      COUNT(*)
             0
    select count(*) from PAY_ELEMENT_ENTRIES_F;
      COUNT(*)
             0

    Hi,
    Your results clearly states that there is no salary data which is been captured as well as there are no element entries which are assigned to any assignment.
    Please do the below which will insert records in salary as well as element entries table:
    1. Add a salary proposal to any active employee (People Enter and Maination --> Search for any employee --> Assignment --> Salary) - This will insert a record in PER_PAY_PROPOSALS table
    2. Add an element entry to any active assignment (People Enter and Maination --> Search for any employee --> Assignment --> Entries) - This will insert a record in PAY_ELEMENT_ENTRIES_F and PAY_ELEMENT_ENTRY_VALUES_F table
    Hope this clarifies.
    Thanks,
    Sanjay

  • Sql query to find the space in between the sentense

    hi,
    can anybody tell me the query to find the space in between the data
    chandan

    Not sure what you mean, but you might want to take a look at INSTR, like in
    instr (txt, ' ')

  • How to find the last update date time and user of record field peoplecode

    how to find the last update date time record field peoplecode?
    Thank you.

    One can check the last update date time using the following query
    SELECT LASTUPDDTTM FROM PSPCMPROG WHERE OBJECTVALUE1 LIKE 'RECNAME' AND OBJECTVALUE2 LIKE 'FIELDNAME'

  • Query to find the list of BP without having Particular GL transactions.

    Hi Experts,
    I want the query to find the List of Business partner who is not having Journal entry for Certain General ledger.
    Scenario: we are creating JE for TDS posting.
    so, i want to know the list of BP , who and all not having particular TDS GL for the particular period.
    Thanks in advance,
    Dwarak

    Hi Dwarak,
    Sure, no problem
    DECLARE @AcctCode AS NVARCHAR(100)
    SELECT @AcctCode=T0.AcctCode FROM OACT T0 WHERE T0.AcctCode='[%0]'
    DECLARE @DateFrom AS DATETIME
    SELECT @DateFrom=T1.RefDate FROM JDT1 T1 WHERE T1.RefDate=[%1]
    DECLARE @DateTo AS DATETIME
    SELECT @DateTo=T2.RefDate FROM JDT1 T2 WHERE T2.RefDate=[%2]
    SELECT CardCode FROM OCRD WHERE CardType='S'
    AND CardCode NOT IN(
    SELECT DISTINCT ContraAct FROM JDT1
    WHERE Account=@AcctCode AND RefDate BETWEEN @DateFrom AND @DateTo)
    Ok, now, here's the problem that I just encountered. This query will work, but, no matter how we fill the parameter, it will show you the very same result. To be honest, I don't know what's wrong with this query.
    If you change all the variables ( @AcctCode and @DateFrom and @DateTo ) directly, it will give you the accurate result. Take this as an example:
    SELECT CardCode FROM OCRD WHERE CardType='S'
    AND CardCode NOT IN(
    SELECT DISTINCT ContraAct FROM JDT1
    WHERE Account='10030201' AND RefDate BETWEEN '2011-09-01' AND '2011-09-20')
    I hard-code the account code, date from and date to for selection. System will show you the accurate result, but using parameter as in first query, system show same result no matter how we fill the parameter.
    Sorry, it seems that I could only partially solved your problem here. I already tried to create a stored procedure and executing the stored procedure with parameter, but still, somehow SBO show very same result no matter if we change the parameter.
    So, my solution need user to manually change the parameter in query. I know, this is a stupid solution, I'm afraid I can't help you to achieve perfect solution here. Maybe anyone here in the forum could guide me to fix my mistake in first query and how to rectify it?
    Best Regards,
    Hendry Wijaya

  • Query to find the Views and synonyms that are accessing through db_link

    HI all,
    Oracle 10g
    I need a Query to find the Views and synonyms that are accessing through db_link.
    ie.
    database A have the db_link to database B through a schema A
    now i need to find what are the Synonyms and views that are accessing through db_link either directly or indirectly..
    regards,
    Deepak
    Edited by: Deepak_DBA on Dec 10, 2010 5:38 PM

    On the second database (B) use this query to find the SQL which used by the schema A (DB LINK USER). Check the SQL_FULLTEXT column.
    select sql_fulltext,sql_id,module,parsing_schema_name,parsing_user_id,first_load_time,loads,users_executing,rows_processed,plsql_exec_time,sorts,fetches,invalidations,parse_calls,cpu_time,elapsed_time,disk_reads,buffer_gets
    from V$sqlarea
    where parsing_schema_name = 'A' --and to_char(first_load_time,'dd/mm/yyyy') like  '%11/08/2007'
    order by first_load_time desc;
    Regards
    Asif Kabir

  • Query to find the long running concurrent requests morethan 2 hours

    Can any one please provide the " Query to find the long running concurrent requests which are running more than 2 hours"

    You need to find the different between the current time/date and FND_CONCURRENT_REQUESTS.ACTUAL_START_DATE for the running requests.
    More details can be found in the following notes:
    Note: 187504.1 - bde_request.sql - Process and Session info for one Concurrent Request (11.5)
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=187504.1
    Note: 134035.1 - ANALYZEREQ.SQL - Detailed Analysis of One Concurrent Request (Release 11 and up)
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=134035.1
    Note: 751438.1 - How To Check List , Start And End Dates Of A Parent Concurrent Request And All Childs
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=751438.1

  • How to get second maximum salary from employee table(sql query)

    how to get second maximum salary from employee table(sql query)

    dude there is no matter of structure .........that user already said its from employee table ...............its basic table in sql and there is no need to specify the table structure
    .........i think u got my point I think you are the one who didn't understand Sarma's point.
    Give a man a fish and you feed him once. Teach a man how to fish and you feed him a life long.
    >
    and the query is
    select max(sal) from emp where sal<(select max(sal)
    from emp);
    this will give the 2nd max salary from the emp tableBtw: You solution is bad, because it needs to scan and sort the table emp twice. And a better solution has been given already.
    Message was edited by:
    Sven W. - reordered statements

Maybe you are looking for

  • Desktop background only displaying white!

    So I have the g5 iMac. I had the background set to change through patterns every minute. Now the background is just white. I put the menu bar on translucent and can see the patterns changing on the menu bar, but not the background. It remains white.

  • Testing for division by zero

    This program consists of 2 classes. The getRating method performs actual calculations based on the below values. The program runs OK, until you test it when dividing by zero. I am trying to return 0 if there is division by zero. I don't think I am ap

  • Install Recommended Path Cluster Fails

    When I try to install the patch cluster on a new install I get two kinds of failures depending on what I am trying to do. I am installing on a 2900 and the Solaris 2.10 (3/05) If I use the nosave option then I get a failure code of 45 If I don't use

  • Want to know about inter company billing or stock transfer

    Dear All, I want detail about intercomany billing. Currently we are not suing this std. flow. I want to study and implent. Pl. help  me in this process. Points will be added. Nik

  • Purchasing Premiere Pro as a single application

    Hello, I'm trying to convince my client (I do motion graphics for his videos) to switch to Premiere from FCP 7. I subscribe to full CC suite and cannot find any information on whether Media Encoder or Encore comes with it. Also, in order to use the L