Get min and max for a column from table with 24 million rows.

What is the best way to re-write the following query in a procedure for the table which has around 24 million rows?
SELECT MIN(ft_src_ref_id), MAX(ft_src_ref_id )
INTO gn_Min_ID, gn_Max_ID
from UI_PURGE_FT;
Thanks
Edited by: tcode on Jun 21, 2012 12:31 PM

Which of the following plan is better, can you please breifly explain?
Also I need to gather statics to know recursive calls , db block gets ,consistent gets etc. etc. how can I get that?
Thanks
1.
Execution Plan
Plan hash value: 3702745568
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 6 | 13991 (2)| 00:02:48 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 | INDEX FAST FULL SCAN | UI_PURGE_FT_PK | 23M| 136M| 13991 (2)| 00:02:48 |
2.
Execution Plan
Plan hash value: 1974183109
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | | 2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 | INDEX FULL SCAN (MIN/MAX)| UI_PURGE_FT_PK | 23M| 136M| 2 (0)| 00:00:01 |
| 3 | SORT AGGREGATE | | 1 | 6 | | |
| 4 | INDEX FULL SCAN (MIN/MAX)| UI_PURGE_FT_PK | 23M| 136M| 2 (0)| 00:00:01 |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------

Similar Messages

  • Get min and max

    Thanks in advance for help
    I have a query as below
       SELECT FI.TCOL1 ,FI.TIPO,FI.TCOL2,COUNT(*) NUM,  
       SUM(FI.TCOL3) SUM_IPBFA,SUM(FI.TCOL4), MIN(FI.COL5) DA_NUM,MAX(FI.COL6) A_NUM
              FROM DBTABLE FI
              WHERE TDATA between DATABEG and DATAEND
              GROUP BY FI.TCOL1 ,TIPO_A,TCOL2
              ORDER BY 1,3           How get MIN e MAX grouped only for FI.TCOL1?
    e.g
    SELECT FI.TCOL1, MIN(FI.COL5) DA_NUM,MAX(FI.COL6) A_NUM
              FROM DBTABLE FI
              WHERE TDATA between DATABEG and DATAEND
              GROUP BY FI.TCOL1 ,TIPO_A,TCOL2
              ORDER BY 1,3Thanks

    it will be better if you can post some sample data and output to work on and to get a better understanding of your requirements.
    you might want to try this but not sure if this will give you the result you needed:
    Select f1.tcol1,
           f1.da_num,
           f2.a_num
      From (SELECT FI.TCOL1,
                   MIN(FI.COL5) DA_NUM
              FROM DBTABLE FI
             WHERE FI.TDATA between DATABEG and DATAEND
            GROUP BY FI.TCOL1) F1,
           (SELECT FI.TCOL1,
                   MAX(FI.COL6) A_NUM            
              FROM DBTABLE FI
             WHERE FI.TDATA between DATABEG and DATAEND
            GROUP BY FI.TCOL1) F2
    Where f1.tcol1 = f2.tcol2
    Order by 1,2,3

  • How to find min and max of a field from sorted internal table

    Hi,
    I have sorted Internal Table by field f1.
    How do I find max and min value of f1.
    For min value of f1 I am using,
    READ TABLE IT1 INDEX 1.
    IT1-F1 = MIN.
    Is this correct? And how do I find the max value of f1 from this table.
    Thanks,
    CD

    Yes, that is right, and you can get the max like this.
    data: lv_lines type i.
    * get min
    READ TABLE IT1 INDEX 1.
    MIN  = IT1-F1.
    * get max
    lv_lines = lines( it1 ).
    read table it1 index lv_lines.
    MAX  = IT1-F1.
    Regards,
    Rich Heilman

  • Generate xml using FOR XML PATH from table with hierarchy

    I need to create xml from a table like:
    EL1 EL2 EL3 Attr01 Attr02 Attr03 Attr04
    E10,    ,    ,a,b,c,d
    E10,E1010,    ,a,b,c,d
    E10,E1010,E101010,a,b,c,d
    E10,E1010,E101020,a,b,c,d
    E10,E1010,E101030,a,b,c,d
    E10,E1020,    ,a,b,c,d
    E10,E1020,E102010,a,b,c,d
    E20,    ,    ,a,b,c,d
    E20,E2010,    ,a,b,c,d
    E20,E2010,E201010,a,b,c,d
    E20,E2020,    ,a,b,c,d
    E20,E2020,E202010,a,b,c,d
    E20,E2020,E202020,a,b,c,d
    The hierarchy is EL1--EL2--EL3, and the 3 columns should be elements of xml;
    The other for columns Attr01,Attr02,Attr03,Attr04 should be attributes of xml;
    The actual table could have more than 500 rows(there are many values for El1,EL2,and EL3). 
    The expected xml should like:
    <root>
      <E10 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
        <E1010 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
          <E101010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
          <E101020 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
          <E101030 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
        </E1010>
        <E1020 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
          <E102010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
        </E1020>
      </E10>
      <E20 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
        <E2010 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
          <E201010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
        </E2010>
        <E2020 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
          <E202010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
          <E202020 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
        </E2020>
      </E20>
    </root>
    I create a sample Src table:
    CREATE TABLE Src
    EL1 VARCHAR(10),
    EL2 VARCHAR(10),
    EL3 VARCHAR(10),
    Attr01 VARCHAR(10),
    Attr02 VARCHAR(10),
    Attr03 VARCHAR(10),
    Attr04 VARCHAR(10)
    GO
    INSERT INTO Src
    (EL1,EL2,EL3,Attr01,Attr02,Attr03,Attr04
     SELECT 'E10','','','a','b','c','d'
     UNION SELECT 'E10','E1010','','a','b','c','d'
     UNION SELECT 'E10','E1010','E101010','a','b','c','d'
     UNION SELECT 'E10','E1010','E101020','a','b','c','d'
     UNION SELECT 'E10','E1010','E101030','a','b','c','d'
     UNION SELECT 'E10','E1020','','a','b','c','d'
     UNION SELECT 'E10','E1020','E102010','a','b','c','d'
     UNION SELECT 'E20','','','a','b','c','d'
     UNION SELECT 'E20','E2010','','a','b','c','d'
     UNION SELECT 'E20','E2010','E201010','a','b','c','d'
     UNION SELECT 'E20','E2020','','a','b','c','d'
     UNION SELECT 'E20','E2020','E202010','a','b','c','d'
     UNION SELECT 'E20','E2020','E202020','a','b','c','d'
    GO
    I tried to use FOR XML PATH to generate xml for the sample data. When the records increase to a few hundreds, it's not a good idea.
    Here is my script:
    SELECT
    (SELECT Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    FROM Src
    WHERE EL3 = 'E101010'
    FOR XML PATH('E101010'),TYPE
    ) AS 'node()'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    FROM Src
    WHERE EL3 = 'E101020'
    FOR XML PATH('E101020'),TYPE
    ) AS 'node()'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    FROM Src
    WHERE EL3 = 'E101030'
    FOR XML PATH('E101030'),TYPE
    ) AS 'node()'
    FROM Src
    WHERE EL2 = 'E1010' AND (EL1 <>'' AND EL3 ='')
    FOR XML PATH('E1010'),TYPE
    ) AS 'node()'--1010
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    FROM Src
    WHERE EL3 = 'E102010'
    FOR XML PATH('E102010'),TYPE
    ) AS 'node()'
    FROM Src
    WHERE EL2 = 'E1020' AND (EL1 <>'' AND EL3 ='')
    FOR XML PATH('E1020'),TYPE
    ) AS 'node()'--1020
    FROM Src
    WHERE EL1 = 'E10' AND (EL2 ='' AND EL3 ='')
    FOR XML PATH('E10'),TYPE) 'node()'
    ,(SELECT Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    FROM Src
    WHERE EL3 = 'E201010'
    FOR XML PATH('E201010'),TYPE
    ) AS 'node()'
    FROM Src
    WHERE EL2 = 'E2010' AND (EL1 <>'' AND EL3 ='')
    FOR XML PATH('E2010'),TYPE
    ) AS 'node()'--2010
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    FROM Src
    WHERE EL3 = 'E202010'
    FOR XML PATH('E202010'),TYPE
    ) AS 'node()'
    ,( SELECT
    Attr01 AS '@Attr01'
    ,Attr02 AS '@Attr02'
    ,Attr03 AS '@Attr03'
    ,Attr04 AS '@Attr04'
    FROM Src
    WHERE EL3 = 'E202020'
    FOR XML PATH('E202020'),TYPE
    ) AS 'node()'
    FROM Src
    WHERE EL2 = 'E2020' AND (EL1 <>'' AND EL3 ='')
    FOR XML PATH('E2020'),TYPE
    FROM Src
    WHERE EL1 = 'E20' AND (EL2 ='' AND EL3 ='')
    FOR XML PATH('E20'),TYPE) AS 'node()'
    FOR XML PATH(''),ROOT('root')
    If I get a few hundreds of rows, how huge the script should be. Does anyone have better solution for this? Thanks.
    Tao

    wBob,
    Thanks! And sorry for late feedback.
    The XSD requires the xml structures like the following
    <Schools>
    <School01>Some school</School01>
    <School02>Some other school</School02>
    </Schools>
    I have to use the number in the element name. 
    Right now I just use the nested FOR XML PATH, although I have to write thousand lines code.
    Thanks anyway.
    Tao
    Tao

  • DELETE QUERY FOR A TABLE WITH MILLION ROWS

    Hello,
    I have a requirement where I have to compare 2 tables - both having around million rows, and delete data based on a single column.
    DELETE FROM TABLE_A WHERE COLUMN_A NOT IN
    (SELECT COLUMN_A FROM TABLE_B)
    COLUMN_A had index defined on it in both tables. Still it is taking a long time. What is the best way to achieve this? any work around?
    thanks

    How many rows are you deleting from this table ? If the precentage is large then the better option is
    1) Create a new table where COLUMN_A NOT IN
    (SELECT COLUMN_A FROM TABLE_B)
    2) TRUNCATE table_A
    3)Insert in to table_A (select * from new table)
    4) If you have any constraints then may be it can be diaabled.
    thanks

  • Find more than one min and max in 2D array contain 0 rows

    Hi
    I have a 2D array and I would like to find the max and min elements between series of 0s. As you can see in the picture If I remove all 0s from the array and use the max and min function then I will have just one min and one max but I need to find min and max after every 0 rows so you can see from the picture ( just as an example) I will have 3 min and 3 max numbers. Would you please help me with this code. Do you now any algorithm that can find min and max between 0s?
    I have also attached my code to remove 0s and then search for max and min numbers but as I mentioned I need min and max for every part
    Many thanks
    Attachments:
    2.jpg ‏82 KB
    3.jpg ‏27 KB

    Thanks altenbach
    I have attached the vi to this post. I would really apperciate if you help me with this example. The min values should be 100, 1500 and 4000 and the max values should be 1200,2600,5400 so as u mentioned the output should be this 2D array 
    100,1200
    1500,2600
    4000,5400
    Attachments:
    new.vi ‏6 KB

  • About min and max fonction

    hello,
    i need to know the min and max for my signal but only on parts that i want to define by a trigger. The question is to know how i could(in my while loop) only analyse a aprt of my signal but not the whole one. i can't use a for loop because i need to see my signal all the time.
    thanks

    Guillaume Trager,
    For the triggering part of your application, there are several tutorials and example programs available to you at NI Developer Zone >> Development Library >> Measurement Hardware >> Analog Input/Output >> Analog Input >> Triggering.
    Once you have the proper triggering program, you can use the Waveform Min Max.vi or Waveform Peak detection.vi to analyze your peak data. The Trigger and Gate Express VI may also work as a software trigger.
    Good luck with your application.

  • Formula for MIN and MAX per range required in BW

    Good day
    Please assist with the following? I need to create a formula (CKF) in BW Query which will give me the same result as the following formula in Excel.
    What I have is one Key Figure and want to calculate a Score on that key figure.
    Score =Key figure/(MAX(range of ie. column B1 to B50 which contains data for the same KF)-MIN(range of ie. column B50 which contains data for the same KF).
    In excel it's easy, ie" Score =TD completed/(MAX(B28:B130)-MIN(B28:B130)
    If more information is required to assist, please let me know?
    Always appreciated.
    Cornelius

    Thank U so much for responding so fast.
    I did the MIN and MAX formula, but it is only taking the MIN or MAX from the single cell of the applicable key figure and not from a 'range' of cells. This is a further example of what I want to do:
    Cell: B1 = 10
            B2 = 12
            B3 = 15
            B4 = 0
    I want to display the MIN as '0' and the MAX as '15' and then do the calculation per row.
    We are in 3.2x. I want to stay away from structures as I have not done that before.
    Any other assistance will be highly appreciated.
    Cornelius

  • Read the min and max occurrence from XSD

    Hi,
    I have a scenario where I have an XML, but not its XSD so my question is of two fold
    1. Is it possible to create an XSD from that XML, if possible how?
    2. Assume I get the XSD how do I read the min and max occurrence from that XSD?
    PS: I am coding in java and pretty new to it, so it would be really helpful if I get the code snippets for the same :)
    Edited by: Harsha.Hegde on Sep 2, 2008 5:49 AM

    Harsha.Hegde wrote:
    Hi,
    I have a scenario where I have an XML, but not its XSD so my question is of two fold
    1. Is it possible to create an XSD from that XML, yes
    if possible how?by using a text editor, tools, etc.
    2. Assume I get the XSD how do I read the min and max occurrence from that XSD?sigh
    PS: I am coding in java and pretty new to itthen you should take some time to learn the basics, then work your way into XML after you have a grasp on things conceptually.
    so it would be really helpful if I get the code snippets for the same :)sorry, no handouts here
    do your own work
    come back when you're written some Java and have a technical question

  • Min and Max values from entire table

     Hi,
     i have requirement in which i need to find the min and max values from the entire table.
    See the sample data 
    create table test
    Sal1 int,
    Sal2 int,
    Sal3 int
    insert into test values (100,700,5700)
    insert into test values (200,3300,5300)
    insert into test values (4400,1200,3500)
    insert into test values (5400,5600,3100)
    i want the output as 100 and 5700.. how can i achieve this in a single query. Please through some light on this topic..!
    Thanking you in advance
    Regards,
    Balaji Prasad B
    Balaji - BI Developer

    Below is an example with a subquery for each of the queries Mohammad posted in order to return both min and max in a single result set.
    SELECT ( SELECT MAX(Maxx) AS Maxx
    FROM test UNPIVOT
    ( Maxx FOR E IN ( Sal1, Sal2, Sal3 ) ) AS unpvt
    ) AS Maxx
    , ( SELECT MIN(Minn) Minn
    FROM test UNPIVOT
    ( Minn FOR E IN ( Sal1, Sal2, Sal3 ) ) AS unpvt
    ) AS Minxx;
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • I have a datetime axis stuck on 1970  for both min and max..

    I have a datetime axis stuck on 1970 for both min and max..
    The lineseries dataprovider has an array collection with objects
    with each object having a dateAdded2 attribute of format mm/dd/yyyy
    and the dates are in this year 2008. the objects also have an
    attribute called amount which is a number.
    eg
    object.dateAdded2 = "07/14/2008"
    object.amount =5
    Anyone with any idea what is going wrong? Similar type of
    data works fine in my other charts.

    Pull the CPU cover and look for leaks from the LCS.
    If the gray mat is wet, the LCS has leaked and the machine will soon be dead.
    PowerMac G5 Coolant Leaks/Repairs
    PowerMac G5 Coolant Leak Repair/Overhaul (w/photos)

  • Calculating min and max value from number array

    I have array which is having return type Number.i want to calculate min and max value of this array..try to help asap..
    Thanks
    dhanu

    hi there,
    public class MinMax {
         int arr[]= { 27, 3, 42, 18, 243, -43, 6, -8 };
         int min, max;
         public MinMax() {
    // it's very bad way to do it.
    //          min=99999;
    //          max=-99999;
    // this must be as following
                    min = max = arr[0];
              search();
              System.out.println("The minimum value is: "+min);
              System.out.println("The maximum value is: "+max);
         private void search() {
    // and here we can search from <1> index instead of <0>
              for (int j=1; j<arr.length; j++) {
                   if (arr[j]<min) {
                        min=arr[j];
                   else if (arr[j]>max) {
                        max=arr[j];
         public static void main(String args[]) {
              new MinMax();
    there is a bug in the supplied code. Your homework is
    to figure out what it is without posting another
    message for help with your homework.well, i think it's a tragedy :(

  • Find min and max from a bunch of numbers

    hi,
    i have a bunch of numbers, and i need to find the min and max.
    so i have a arraylist which contains objects....whats the best way to find the min number and max number of all these objects?
    thanks

    You're close, but you can do them all at the same time without temp variables..
    double maximumX = 0;
    double minimumX = 0;
    double maximumY = 0;
    double minimumY = 0;
    for (int i = 0; i < myobjects.size(); i++) {
         mything d2d = (mything) myobjects.get(i);
         maximumX = Math.max(d2d.getBounds().getMaxX(), maximumX);
         minimumX= Math.min(d2d.getBounds().getMinX(), minimumX);
         maximumY = Math.max(d2d.getBounds().getMaxY(), maximumY);
         minimumY = Math.min(d2d.getBounds().getMinY(), minimumY);
    }Since you are dealing with rectangles, you could add them all to an Area and get the bounds of the Area, but that's probably slower.

  • After installing Version 5 I get an error message about incompatibility and min and max versions.

    I shutdown Zone Alarm, and deleted the contents of the file, which contained the "exe" file, then reinstalled Firefox version 5.0. I still get the XUL Runner error message about incompatibility of Version 5.0 with min and max 5.0.1. What next?

    The updater wasn't able to update all the files and some were left as older versions.<br />
    You need to do a clean reinstall.
    Download a fresh Firefox copy and save the file to the desktop.
    * Firefox 5.0.x: http://www.mozilla.com/en-US/firefox/all.html
    * Uninstall your current Firefox version.
    * Do not remove personal data when you uninstall the current version.
    Remove the Firefox program folder before installing that newly downloaded copy of the Firefox installer.
    * It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    Your bookmarks and other profile data are stored elsewhere in the Firefox Profile Folder and won't be affected by a reinstall, but make sure that you do not select to remove personal data if you uninstall Firefox.
    * http://kb.mozillazine.org/Profile_folder_-_Firefox
    * http://kb.mozillazine.org/Profile_backup

  • Can I charge my iPad mini and/or my iPhone 4S from 220 volt outlets using just the correct plug adapter for the country.

    Can I charge my iPad mini and/or my iPhone 4S from 220 volt outlets using just the correct plug adapter for the country, without a power converter?

    Not staff or owner by a long shot.
    I just know that anecdotally I have seen people reporting issues with their mini's charging. Is there a real issue or not? I don't know. Not a day goes by that a person doesn't post here complaining that their iPad won't charge and it turns out that they're trying to do it via USB or with the iPhone block.
    But while there are a lot of user fixes sometimes it's good to have the pros take a look at things,and at the very least document that there has been an issue.
    the four main reasons an iPad won't charge (beyond being plugged into a USB port)
    Bad cable
    bad outlet
    bad brick
    rule those out and it leaves issue with the iPad.

Maybe you are looking for

  • Cannot send email from non .mac server

    I am only able to send/reply emails using my .mac address. My 2 other server addresses keep giving me the following message. "Cannot send mail. One of the recipient addresses was invalid". How can I fix this?

  • Hi support team

    Good day, I'm just change to iPhone 5 few days.. And I was newbie here for iPhone. I wanted to purchase apps in App Store. After I typed in all my data of debit card but keep having the problem of " invalid security code " I'm kinda frustrated about

  • Push notifications & iMessage not working

    Push notifications used to work for but once iMessage came out I haven't seen a single push notification and I've yet to get iMessage working. iMessage activates just fine and verified my phone number without problems but can never send or receive me

  • 24" iMac - use as a monitor for my PC?

    I have a 24" iMac and want to know if I can utilize the monitor for my PC? Dan

  • Class to connect, manage and disconnect a DDBB

    Hi I had posted this Topic in Java Programming forum, buit I have seen here is the correct. I have a doubt about how to do this class: I have a java class witch I use from jps pages to make differents querys throw Data Base. In this class, I have a c