Select the last 50 closed records

The research of a statement select simple sql which selects the latest 50 records closed in the database.

I found some help out there who have an example like:

SELECT RecordID, closed_date
(SELECT RecordID, closed_date, RANK() over (ORDER BY closed_Date DESC) date_rank
FROM table1)
WHERE the date_rank < = 50;

Only problem is, this is to select something like 4000 recordings, and many of them are not yet closed.

I think that you need to retrieve the records that are only closed in the first place.

Try this,

SELECT RecordID, closed_date
  FROM (SELECT RecordID,
               closed_date,
               ROW_NUMBER () OVER (ORDER BY closed_Date DESC) rn
          FROM table1
         WHERE closed_date < SYSDATE)  --Notice this.
 WHERE rn <= 50;

G.

Tags: Database

Similar Questions

  • How to select the last 3 records in a table?

    I have a table named HRM_ATTENDANCE
    as follows
    Name         Type         Nullable Default Comments 
    ------------ ------------ -------- ------- -------- 
    LEAVEDATE    DATE                                   
    EMPLOYEECODE VARCHAR2(8)                            
    LEAVETYPE    VARCHAR2(4)                            
    APPROVEDBY   VARCHAR2(8)  Y                         
    FEEDBY       VARCHAR2(8)  Y                         
    FEEDTIME     DATE         Y                         
    REMARKS      VARCHAR2(50) Y 
    the table contains the record of leave of employees as follows
    LEAVEDATE   EMPLOYEECODE LEAVETYPE APPROVEDBY FEEDBY   FEEDTIME    REMARKS
    ----------- ------------ --------- ---------- -------- ----------- --------------------------------------------------
    6/1/2013    00001        CL  
    6/3/2013    00001        EL                                         
    6/5/2013    00001        CPL    
    6/7/2013    00001        SL 
    6/9/2013    00001        CL                                        
    I want to select the last 3 leaves (records) to employeecode "00001" so I don't know the what are the dates of the leave. in easy words I want to choose the folder where leavedate > = 5 June 2013 ", but I don't know any dates."

    Select * from HRM_ATTENDANCE where rownum<=3 order="" by="" leavedate="">

  • Select the last record of each month

    Hello

    to select the last docnumber and qty of every month

    Structure

    Name Null?    Type

    ------------------------------- -------- ----

    PRODUCTCODE NUMBER

    NUMBER NUMBER

    DATE OF PLANFORMONTH

    NUMBER OF CLEXPECTEDQTY

    NUMBER OF CLCONFIRMQTY

    NUMBER OF CLFGBUFFERQTY

    NUMBER OF CLTOTPRINTBUFFER

    in this select query if I take the sum he required all records where, as I want the last record of each month

    SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.

    SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)

    GROUP BY productcode, (planformonth)

    Sandy

    Hello

    Thanks its working now the code is written as below:

    SELECT * FROM

    (SELECT

    e.*,

    ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r

    Of

    E FGSALESPLAN)

    WHERE r = 1 AND

    entryvalid = 'Y '.

    order by Number

    Sandy

  • Select the last 10 records in a table

    Oracle9i. I am trying to select the last 10 numbers in a table with this command series
    select serial from tab_42 where employeecode='00001'  and rownum<=10 order by serial desc;
    but it's not not selecting the most recent serial number 10. How to do?

    The rownum clause is applied before the order by clause, one must use a subquery...

    select * from (select serial from tab_42 where employeecode='00001' order by serial desc) where rownum<=10;
    
  • Select the last disk in the history table

    How to select the last record in a history table? the example data is
    < p >
    Product EffectiveDate

    prod1 01/01/1980

    prod1 01/01/1990

    prod1 01/01/2000

    prod2 02/02/1980

    prod2 02/02/2000
    < /p >
    < p >


    The expected result is



    Product EffectiveDate

    prod1 01/01/2000

    prod2 02/02/2000
    < /p >

    Assuming that there is a single line with max (effectivedate) for a given product

    SELECT product, attrib1, attrib2, ... , max_effective_date
      FROM (SELECT product,
                   attrib1,
                   attrib2,
                   ... ,
                   effectivedate,
                   max( effectivedate ) over (partition by product) max_effective_date
              FROM history_table)
     WHERE effectivedate = max_effectivedate
    

    should work.

    Justin

    Published by: Justin cave on October 30, 2008 18:32

    Formatting changes

  • By selecting the last row of the table

    I'm trying to select the last row in a table. The tables will have a different number of lines, so I can't select based on a line number. I tried to use the location options, but get an error that "the object is not a function". Not sure what the problem is.

    table = app.selection[0];
    if (table.hasOwnProperty("baseline")) table = table.parent;
    if (table instanceof Cell) table = table.parent;
    if (table instanceof Column) table = table.parent;
    if (table instanceof Row) table = table.parent;
    if (table instanceof Table)
    
    {
                table.rows(LocationOptions.AT_END).cells.texts.everyItem().fontStyle = "regular";
     }
    

    You can use the placement options for this?

    Hello

    table. Rows being a collection of object using the index-[1] is a proper way

    but cells.texts generates an error. Change it to:

    table.rows[-1].cells.everyItem().texts.everyItem().appliedCharacterStyle = "myriad regular";
    

    Jarek

  • How to select the last 20 transactions in a table

    Hi guys,.
    I have a table named INOUT with following columns

    EMPLOYEECODE VARCHAR2
    DATE OF THE RESPONDENT


    each day employees now their me 'in '. then entered came and came in this table. If we want to select the last 20 EMPLOYEECODE in this table that make their selves 'in '. How to choose that? just 20 last employees who traded. Help, please

    Hello

    This is called a Query Top - N , you want to choose elements of N (N = 20, in this case) from the top of a sorted list.
    Here's a way to do it:

    WITH     got_r_num     AS
    (
         SELECT       emloyeecode
         ,       MAX (intime)     AS latest_intime     -- If wanted
         ,       RANK () OVER (ORDER BY  MAX (intime)  DESC)
                        AS r_num
         FROM       inout
         GROUP BY  employeecode
    )
    SELECT     employeecode
    ,     latest_intime          -- If wanted
    ,     r_num               -- If wanted
    FROM     got_r_num
    WHERE     r_num     <= 20
    ;
    

    That actaully could take more than 20 people: If there be a tie, it includes any person who is entitled to be in the top 20. If you want exactly 20 people, then add the columns of tiebreaker to analytical or use ROW_NUMBER instead of RANK ORDER BY clause.

  • Cannot select the last picture

    Hello

    I have 75 frames in an animation. I have about 6 layers.

    I'm putting a stop on the last image statement.

    Whenever I open the Actions window it says even if image 1

    the playhead is positioned on the last image.

    How to place a stop comand on the last image and which layer

    should I select?

    Thank you

    Jim

    After having selected the last image, right-click on it and select Insert image.  You should now be able to add your stop() command in the last picture.

  • Select the last character of a string

    Hello
    I want to select the last character of a string address. "For example, as a result of select ' 165 John Ave W '-'W '. I tried to use the RIGHT but it does not work. I am using sqlplus.

    SELECT RIGHT(ADDRESS,1) FROM addresses;
    ORA-00904: "RIGHT": invalid identifier

    I can't find that any select statement to get the result I want. Ideas?

    Thank you!

    You want: SUBSTR (, - 1).

  • Select the last 7 days

    How to select the last 7 days of my table, I use the query, but it is the calculation according to sysdate
    It is the data of my talble
    DP_DATE
    ---------
    03-APR-10
    21-APR-10
    22-APR-10
    23-APR-10
    26-APR-10
    27-APR-10
    28-APR-10
    29-APR-10
    30-APR-10
    03-MAY-10
    04-MAY-10
    
    11 rows selected.
      select distinct dp_date
      from dailyprice
      where trunc(dp_date) between trunc(sysdate-7) and trunc(sysdate)
    
    this query is returning 
    DP_DATE
    ---------
    29-APR-10
    30-APR-10
    03-MAY-10
    04-MAY-10
    I want to choose last 7 days
    APRIL 26, 10
    APRIL 27, 10
    28 APRIL 10
    APRIL 29, 10
    30 APRIL 10
    MAY 3, 10
    4 MAY 10

    kindly Guide

    concerning

    Hello

    Use DENSE_RANK() rather than ROW_NUMBER().

    with mytable
    as
    (
    select 'abcFund' FND , to_date('09-MAY-10','dd-mon-rr') dp_date, 10 price from dual union all
    select 'dddFund', to_date('09-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('09-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('09-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('09-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('07-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('07-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('07-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('05-MAY-10','dd-mon-rr'), 11 from dual union all
    select 'dddFund', to_date('05-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('05-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('04-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('04-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('03-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('03-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('03-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('03-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('01-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('01-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('30-APR-10','dd-mon-rr'), 11 from dual
    )
    select dp_date
          from ( select dp_date
                      , dense_rank() over (order by dp_date desc) rn
                   from mytable
               )
         where rn <= 7;
    

    Courtesy: Rob SQL
    * 009 *.

    Published by: 009 on May 6, 2010 05:01

  • If the record not found this particular date, then select the last recordings date.

    I have three columns
    Number DP_FND_CODE;
    Date of DP_DATE;
    Number DPPRICE;

    I want that if dp_uprice not found this particular date (: dd1) then
    Select maximum Dp_uprice that the date would be less then: dd1

    Example: -.
    I run query and :DD1 parameter = 18/10/2010
    
    SELECT dp_fnd_code, dp_date , dp_uprice dpprice 
    FROM dailyprice where dp_date = :dd1
    
    DP_FND_CODE DP_DATE                      DPPRICE
    ----------- ----------------------- ------------
              1 18/10/2010                  109.0344
              2 18/10/2010                   10.1045
              3 18/10/2010                  100.4010
              4 18/10/2010                  102.3276
              6 18/10/2010                   14.6958
              7 18/10/2010                   98.8300
              8 18/10/2010                  102.0900
    It will show that all the Archives: dd1 = 18/10/2010, you can see above the result of the query DP_FND 5 is missing.
    I want to if there is no DPRICE of that particular date (: DD1) then it shows the date of the last DPPRICE.
    Like this
    DP_FND_CODE DP_DATE                      DPPRICE
    ----------- ----------------------- ------------
              1 18/10/2010                  109.0344
              2 18/10/2010                   10.1045
              3 18/10/2010                  100.4010
              4 18/10/2010                  102.3276
              5 16/10/2010                  122.3276          
              6 18/10/2010                   14.6958
              7 18/10/2010                   98.8300
              8 18/10/2010                  102.0900
    so I used this query, but correct nicely.
    SELECT dp_fnd_code, dp_date, 
                 case when dp_uprice is null then(
               select max(dp_uprice) dpprice from dailyprice where dp_date < :dd1 group by dp_fnd_code,dp_date
               ) else dp_uprice  end dpprice 
      FROM dailyprice 
      where dp_date = :dd1
      order by dp_fnd_code
      
    Thanks in advance.
    SELECT dp_fnd_code,
           max(dp_date) keep (dense_rank last order by dp_date),
           max(dpprice) keep (dense_rank last order by dp_date)
      FROM dailyprice
      where dp_date <= :dd1
      group by dp_fnd_code
      order by dp_fnd_code;
    
  • Line Segment tool does not select the last line! Why? CC 2015

    I regularly draw several segments on the right with the line Segment tool, then convert them to a live paint. This often requires that lines are tangent or overlapping. In CC 2015 the last segment of the line remains active and the line segment tool switches to a tool "to rotate/move", by drawing a line tangent or closely placed impossible without '' if. '' How can I disable this 'new' and return to the line Segment tool I like in CS 5? Yes, I am trying to embrace the new, he does not cease of themselves in the way of productivity.

    You can not turn it off. Ask us for an option you can disable 'Keep selected', as you can for a brush.

    Feature requests are CC 2015 in the Help menu.

  • Hide/no equla to the last row of records

    Hello

    I mentioned below records in Mount so each time I have select any mount it should now show the last line of this mount i.e. test No-3
    all records of Assembly that will not display the last rank of the number of test

    Mount day test_No and org2 to org3 org4 org1
    299,00 1 0 1 1 0 7186
    299,00 1 0 2 1 0 7186
    299,00 0 3 3 0 7186
    298,00 0 4 1 0 7186
    298,00 1 0 2 1 0 7186
    298,00 1 1 3 1 0 7186

    You want to show or hide the last row?

    If you want to display only last row, use the following query...

    select mount, day, org1, test_no, org2, org3, org4
    from
    (
      select mount, day, org1, test_no, org2, org3, org4,
               row_number()
                    over (partition by mount order by test_no desc) rn
      from your_table t
      --"Use the below filter if you need"
      --where mount = &your_value
    )
    where rn = 1;
    

    If you want to hide only last row, use the following query...

    select mount, day, org1, test_no, org2, org3, org4
    from
    (
      select mount, day, org1, test_no, org2, org3, org4,
               row_number()
                    over (partition by mount order by test_no desc) rn
      from your_table t
      --"Use the below filter if you need"
      --where mount = &your_value
    )
    where rn != 1;
    

    Published by: JAC on 7 February 2013 15:58

  • Select the last Date of multicolumn and its value adjustent cust_id

    I have a Table with 5 customer_id and 5 Dates with each belonging to its cust_id.

    I need to take the last, in my example would be CUSTID_5.  I know

    this with the GREATEST who select the CHANGE_DATE_5 (in my example), but

    How to choose the CUSTID_x? that goes along with the winning Date?

    create table test_tbl)

    number of custid_1

    date of change_date_1,

    number of custid_2

    date of change_date_2,

    number of custid_3

    date of change_date_3,

    number of custid_4

    date of change_date_4,

    number of custid_5

    date of change_date_5

    );

    INSERT INTO test_tbl

    (CUSTID_1, CHANGE_DATE_1, CUSTID_2, CHANGE_DATE_2, CUSTID_3, CHANGE_DATE_3, CUSTID_4, CHANGE_DATE_4, CUSTID_5, CHANGE_DATE_5)

    VALUES

    (111, sysdate, 222, sysdate + 1, 333, sysdate + 2, 444, sysdate + 3, 555, sysdate + 4);

    commit;

    Hello

    Here's one way:

    WITH unpivoted_data AS

    (

    SELECT custid, change_date

    , EVALUATE () OVER (ORDER BY change_date DESC) AS r_num

    OF test_tbl

    UNPIVOT ((custid, change_date)

    Label ((custid_1, change_date_1) AS 1)

    , (custid_2, change_date_2) AS 2

    , (custid_3, change_date_3) AS 3

    , (custid_4, change_date_4) AS 4

    , (custid_5, change_date_5) AS 5

    )

    )

    )

    SELECT custid, change_date

    Of unpivoted_data

    WHERE r_num = 1

    ;

    Having several columns for several occurrences of basically the same thing is a bad table.  This problem would be much simpler, but also more effective if each pair custid/change_date has been strored on a separate line.  In addition, you would not be limited to 5 pairs.

  • Select the last instruction time need.

    Hi all

    I have my db on aix 5 and oracle 9.2. My requirement is to remove all the objects that are not in use for the last 2 years. Auditing is not enabled because of the constraint of space. I looked in dba_objects and last_ddl_time column there, but it will show last modification of object DDL. I want to list all the objects against which even SELECT statement is not triggered for last 2 years.

    Kind regards
    Amit.

    you will check with production database?

    Note: Please do not do this with production database... It's just a workaround and a lot of time...

    Take the backup db production and restore in the separate test environment...

    Just map your application to the new environment of test and activate the trace...

    Go to each option on your application and check the trace files, this will help you what are all the tables are used in the application.

    This will degrade your performance if the application has a lot of menus and options of this method will be a lot of your time...

    If you have not enabled the audit, this is one way you can find the solution...

    Kind regards...
    Delphine K

Maybe you are looking for

  • 2009 iMac has none showing after restore and hard disk crash

    My 2009 iMac running 10.9.5 Mavericks locked up and I had to restore it from backup. After I restored it, it made 2 backups and then crashed. When I tried to restore it again there is no hard drive available. I got when starting was a folder flashing

  • Satellite 2430-101: WLan - Yes or no?

    HelloI am German.I have my toshiba w - lan?Toshiba S2430-101Model no PS243E-06P4S-GRP4 2, 53 G/2 x 256 / 40 G 42, 15XT, CDW, LM Can someone help me?

  • Satelltie P100-387: Question about preinstaled on HARD drive software

    I want to know what software preinstalled on new P100-387 on the HARD drive.There are 3 files which I don't know exactly what's in it and if it is important to be on C:\ CMPNENTS I386 VALUEADD (I want to know if I can remove it or put it on DVD). And

  • Equium L20: memory of 192 MB instead of 256 MB and slow

    I have an Equium L20, which is less than a year and began to run very slowly. It registers only 192 MB of memory, wherever it is physically a 256 MB chip in the machine. Is it because of the graphics card or is the problem why the laptop going really

  • XY graphics funktions

    There're eine eine funktion XY possibility in einem chart abzubilden. Float X-Achse und Y-Achse float. Danke fur Eure Antwort!