HowTo Sample a Certain amount of records

Ok, I have created a table that has the top customers from 10 stores, so there is a Store Number column like 1, 2, 3.... and there is also a aggregated sum() Store Spend column that shows how much the customer spent in the last_12_months.
I now would like to sample the best/top 500 records from each of the stores, using Descending order and the spend column last_12_months column......
How would I do something like that ?
Thanks!

Hi,
That's an example of a "Top-N" query. You want to pick N items (N=500) from the top of a sorted list (or, in this case, 10 sorted lists - a separate list for each store).
In a sub-query, get all the columns you need, applying whatever WHERE-clause is appropriate (such as "WHERE sales_dt >= ADD_MONTHS (SYSDATE, -12)").
Also select a column that numbers each row according to how it compares to other rows in its class.
For example, if each store_number is a different class, and the ranking is determined by SUM (spend) in descending order, the new column might be
,       RANK () OVER
            ( PARTITION BY  store_number
              ORDER BY      SUM (spend)    DESC
            )  AS rnkThen, in your main query, choose only the rows "WHERE rnk <= 500".
The sub-query is necessary because analytic functions (like RANK) are evaluated after the WHERE-clause, but you want the opposite. You need to compute rnk and then use it in a WHERE-clause.
If you need more help, post some sample data and the results you want from that data.
You'll probably want to change your requirements to accomodate a small data set, such as picking the top 3 per store, rather than the top 500.

Similar Messages

  • Have a certain amount of records print per page

    Cr 2008
    In my main report I have header information, then a sub report in my last group header.  What is happening is my sub report is growing larger for some students and pushes my data onto the top of the next page splitting the data up.  I am trying to just print  3 students per page and keep everything printing together.
    If my sub report grows to large then some of that data shows at the top of the next page causing issues, how do I tell the entire group to print to the next page if there is not enough room on the current page and not break the way the rest of the report is printing?
    Hopefully this makes sense.
    Thanks,
    GJ

    Hello Glenn,
    You should be able to get the entire group to start a new page if the subreport won't fit on the page if you set the top level group to Keep Together. Go to Report menu > Group Expert > highlight the top group and select options > options tab and then enable Keep Together.

  • Limiting the amount of records or pages that gets generated by a report

    Post Author: jjurroz
    CA Forum: General
    Hey guys,I'm using CR 8.5.3I have a quick question that hopefully one of your can help me out with. I have a report that works perfectly and uses a couple different parameters for sorting etc.. I'm using an SQL database and for a particular report, after inputting the correct parameter values the report would generate for example 12,000 records on 2000 pages. What I'm trying to do is create a new parameter that would limit either the amount of pages that gets generated or the amount of records. I think I'd rather limit the amount of records to start off with and I would like it to be from a list of predefined amounts. I.E. "ALL", "First 10", "First 50". Essentially I'm trying to create a report that gives me a subset or sample of the main report so that it could get printed to pdf and sent to customer for review. Any help would be greatly appreciated! Regards,Jose

    Post Author: jjurroz
    CA Forum: General
    I can only go to 'TopN/Sort Group Expert' menu option if I add a summary field, otherwise the option is greyed out. If I do add a summary field and go to 'TopN/Sort Group Expert' I have no formula button. I can select TopN from a drop down but then I have to hard code the N value. I'm start to wonder whether its even possible to do it dynamically in CR 8.5.   V361:Sorry JJurroz, Here again I have CR XI, so not sure if 8 will do this.  Create a number parameter {? Top_N} then go to Group Sort Expert, you should be able to click on the formula button for Top N and put your parameter {? Top_N} in the formula.
    That should work.

  • Restrict a supplier upto certain amount limit for purchasing ?

    Hi,
    How can we restrict a supplier upto certain amount limit for purchasing (PO)?
    regards,
    Abdul Hafeez

    Can you add a when-validate-record personalization at the po_headers level?
    OR you can modify the PO approval workflow to add the check.
    Sandeep Gandhi

  • Amount of records loaded to dso is not same as in psa

    i performed a loading from psa to dso. i have 2 datasource under this dso, the amount of records loaded from psa for this 2 datasources to dso is not consistent. the psa for the 1st datasource having 3k records and the 2nd datasource having 5k records, when i perform the loading for both of this datasource to dso, the records is less. do anyone here know why is this so?

    hi,
    DSO have overwrite option and hence you have lesser records.
    chk if you have enough key fields in DSO, so that you can reduce the number of records getting overwritten.
    Ramesh

  • How to insert large amount of records at a time into oracle

    Hi, im Dilip. I'm newbie to Oracle. For practicing purpose i got some SQL code which has huge amounts of records in text format which i need to copy+paste in my SQL Plus in Oracle 9i. But when i try to paste in SQL Plus I'm unable to paste more them 50 lines of code at a time. In one of the text file there is 80 thousand lines of record's code i need to paste. Please help me. Here is the link for the text file I'm using : http://www.mediafire.com/view/?4o9eo1qjd15kyib . Any kind of help will be much appreciated.

    982089 wrote:
    Hi, im Dilip. I'm newbie to Oracle. For practicing purpose i got some SQL code which has huge amounts of records in text format which i need to copy+paste in my SQL Plus in Oracle 9i. But when i try to paste in SQL Plus I'm unable to paste more them 50 lines of code at a time. In one of the text file there is 80 thousand lines of record's code i need to paste. Please help me. Here is the link for the text file I'm using : http://www.mediafire.com/view/?4o9eo1qjd15kyib . Any kind of help will be much appreciated.
    sqlplus user1/pass1
    @sql_text_file.sql
    doing above will execute all the SQL statements in the text file

  • What is the best practice of deleting large amount of records?

    hi,
    I need your suggestions on best practice of deleting large amount of records of SQL Azure regularly.
    Scenario:
    I have a SQL Azure database (P1) to which I insert data every day, to prevent the database size grow too fast, I need a way to  remove all the records which is older than 3 days every day.
    For on-premise SQL server, I can use SQL Server Agent/job, but, since SQL Azure does not support SQL Job yet, I have to use a Web job which scheduled to run every day to delete all old records.
    To prevent the table locking when deleting too large amount of records, in my automation or web job code, I limit the amount of deleted records to
    5000 and batch delete count to 1000 each time when calling the deleting records stored procedure:
    1. Get total amount of old records (older then 3 days)
    2. Get the total iterations: iteration = (total count/5000)
    3. Call SP in a loop:
    for(int i=0;i<iterations;i++)
       Exec PurgeRecords @BatchCount=1000, @MaxCount=5000
    And the stored procedure is something like this:
     BEGIN
      INSERT INTO @table
      SELECT TOP (@MaxCount) [RecordId] FROM [MyTable] WHERE [CreateTime] < DATEADD(DAY, -3, GETDATE())
     END
     DECLARE @RowsDeleted INTEGER
     SET @RowsDeleted = 1
     WHILE(@RowsDeleted > 0)
     BEGIN
      WAITFOR DELAY '00:00:01'
      DELETE TOP (@BatchCount) FROM [MyTable] WHERE [RecordId] IN (SELECT [RecordId] FROM @table)
      SET @RowsDeleted = @@ROWCOUNT
     END
    It basically works, but the performance is not good. One example is, it took around 11 hours to delete around 1.7 million records, really too long time...
    Following is the web job log for deleting around 1.7 million records:
    [01/12/2015 16:06:19 > 2f578e: INFO] Start getting the total counts which is older than 3 days
    [01/12/2015 16:06:25 > 2f578e: INFO] End getting the total counts to be deleted, total count:
    1721586
    [01/12/2015 16:06:25 > 2f578e: INFO] Max delete count per iteration: 5000, Batch delete count
    1000, Total iterations: 345
    [01/12/2015 16:06:25 > 2f578e: INFO] Start deleting in iteration 1
    [01/12/2015 16:09:50 > 2f578e: INFO] Successfully finished deleting in iteration 1. Elapsed time:
    00:03:25.2410404
    [01/12/2015 16:09:50 > 2f578e: INFO] Start deleting in iteration 2
    [01/12/2015 16:13:07 > 2f578e: INFO] Successfully finished deleting in iteration 2. Elapsed time:
    00:03:16.5033831
    [01/12/2015 16:13:07 > 2f578e: INFO] Start deleting in iteration 3
    [01/12/2015 16:16:41 > 2f578e: INFO] Successfully finished deleting in iteration 3. Elapsed time:
    00:03:336439434
    Per the log, SQL azure takes more than 3 mins to delete 5000 records in each iteration, and the total time is around
    11 hours.
    Any suggestion to improve the deleting records performance?

    This is one approach:
    Assume:
    1. There is an index on 'createtime'
    2. Peak time insert (avgN) is N times more than average (avg). e.g. supposed if average per hour is 10,000 and peak time per hour is 5 times more, that gives 50,000. This doesn't have to be precise.
    3. Desirable maximum record to be deleted per batch is 5,000, don't have to be exact.
    Steps:
    1. Find count of records more than 3 days old (TotalN), say 1,000,000.
    2. Divide TotalN (1,000,000) with 5,000 gives the number of deleted batches (200) if insert is very even. But since it is not even and maximum inserts can be 5 times more per period, set number of deleted batches should be 200 * 5 = 1,000.
    3. Divide 3 days (4,320 minutes) with 1,000 gives 4.32 minutes.
    4. Create a delete statement and a loop that deletes record with creation day < today - (3 days ago - 3.32 * I minutes). (I is the number of iterations from 1 to 1,000)
    In this way the number of records deleted in each batch is not even and not known but should mostly within 5,000 and even you run a lot more batches but each batch will be very fast.
    Frank

  • How do I create a certain amount of instances at runtime?

    If i want a certain amount of instances at runtime, how can i do it?
    say, if i write a program that read an input from a keyboard and create a certain amount of instances. or read an input from a keyboard to be an instance variable. Can i do it? How? Please help!

    If i want a certain amount of instances at runtime,
    how can i do it?
    say, if i write a program that read an input from a
    keyboard and create a certain amount of instances.
    or read an input from a keyboard to be an instance
    variable. Can i do it? How? Please help!How much instance do you want? 1 gm? 10 gms? 1 pound? a kilo?

  • Insert into table a large amount of records

    I was trying to find a fast way to optimize a script that insert a large amount of records into a table. The initial script was like
    insert into table_xxxx
    select a.camp1, a.camp2, a.camp3 a.camp4, b.camp1, b.camp2, b.camp3
    from table_a a, table_b b
    where a.camp0 = b.camp0
    The commit sentence was at the end of the insert script; so i came up with this solution
    Declare
    TYPE cur_CURSOR IS REF CURSOR ;
    TYPE Tab_Hist IS TABLE OF table_xxxx%ROWTYPE INDEX BY BINARY_INTEGER;
    g_tHist Tab_Hist;
    CURSOR c_Base IS
    select a.camp1, a.camp2, a.camp3 a.camp4, b.camp1, b.camp2, b.camp3
    from table_a a, table_b b
    where a.camp0 = b.camp0;
    BEGIN
    OPEN c_base;
    LOOP
    FETCH c_base BULK COLLECT INTO g_tHist LIMIT 1000;
    EXIT WHEN g_tHist.COUNT = 0;
    BEGIN
    FORALL i IN g_tHist.FIRST .. g_tHist.COUNT SAVE EXCEPTIONS
    INSERT INTO prov_cobr_dud VALUES g_tHist(i);
    COMMIT;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    END;
    g_tHist.DELETE;
    EXIT WHEN c_base%NOTFOUND;
    END LOOP;
    CLOSE c_base;
    commit;
    END;
    If anyone could tell me another way to do the same thing i'll apreciate it a lot; i'm keen on learn more efficient ways to optimize scripts.
    PD: The initial insert was inserting the table with 120,000 records (more or less)

    Hello,
    Wrong forum. This is the Oracle Forms forum. You should post in the SQL-PL/SQL forum.
    Francois

  • How do I get the page to refresh after a certain amount of time so it jumps back to beginning of one page site? Its for an exhibition

    Hi,
    I am in an exhibition space where I need to display my Muse website offline and locally on the desktop. I am looking for a way for the website to refresh after a certain amount of time so it can go back to the beginning of the page. Can someone help? Please!

    You can try the steps mentioned here :
    http://stackoverflow.com/questions/2787679/how-to-reload-page-every-5-second
    http://stackoverflow.com/questions/17886578/refresh-part-of-page-div
    http://crunchify.com/how-to-refresh-div-content-without-reloading-page-using-jquery-and-aj ax/
    Thanks,
    Sanjit

  • 1.     Retainage of certain amount of Total payment to be made to vendor

    Hi gurus
    can someone help me to configure the below scenario please
    1.     Retainage of certain amount of Total payment to be made to vendor
    Thanks

    Dear Lakshmi,
    Retention money is that part of the invoice of a vendor, which is not paid to the vendor until some pre agreed conditions are satisfied.
    For example, a vendor may suppy a machinery and as per the terms, 90% of the amount would be paid and the remaining 10% would be paid say after 6 months after satisfactory commissioning of the machinery.
    The retention money concept is used in Accounts Payable and can be configured with the help of "terms of payment"
    You can use the Terms of payment to acheive this requirement.
    Go to Transaction code OBB8. Create a new terms of payment say Z001, which has the "Installment Payment" ticked.
    Now create two more terms of payment Z002 and Z003. Here mark the "Payment Block" (A or B) for the terms of payment Z003.
    Now go to OBB9, fill as below
    Z001----- 170-----Z002
    Z001--230-----Z003.
    Now at the PO stage, make sure that the terms of payment is Z001.
    At the stage of the invoice verification, the entry would be
    Expense A/c Dr 1000
    To Vendor A/c 700
    To Vendor A/c 300 ( This would be with a payment block)
    At the time of automatic payment, this Rs.300/- will not be selected unless we remove the payment block.
    Regards
    Venkatesh
    PS: Assign points if useful

  • Retainage of certain amount of Total payment to be made to vendor

    Hi MM gurus
    I need to configure with the below requirement, can someone through light on it please
    1.     Retainage of certain amount of Total payment to be made to vendor
    2.      Separate Tax ID for Vendor

    Dear Lakshmi,
    Retention money is that part of the invoice of a vendor, which is not paid to the vendor until some pre agreed conditions are satisfied.
    For example, a vendor may suppy a machinery and as per the terms, 90% of the amount would be paid and the remaining 10% would be paid say after 6 months after satisfactory commissioning of the machinery.
    The retention money concept is used in Accounts Payable and can be configured with the help of "terms of payment"
    You can use the Terms of payment to acheive this requirement.
    Go to Transaction code OBB8. Create a new terms of payment say Z001, which has the "Installment Payment" ticked.
    Now create two more terms of payment Z002 and Z003. Here mark the "Payment Block" (A or B) for the terms of payment Z003.
    Now go to OBB9, fill as below
    Z001----- 170-----Z002
    Z001--230-----Z003.
    Now at the PO stage, make sure that the terms of payment is Z001.
    At the stage of the invoice verification, the entry would be
    Expense A/c Dr 1000
    To Vendor A/c 700
    To Vendor A/c 300 ( This would be with a payment block)
    At the time of automatic payment, this Rs.300/- will not be selected unless we remove the payment block.
    Regards
    Venkatesh
    PS: Assign points if useful

  • AnyStandard functionality in F110 to filter the invoices for certain amount

    Hi All,
    I have a requirement like  - We need to process the batch payment based on the Value of the Invoices accounted in system.
    Any single/consolidation of  invoices for value exceeding Rs 50000/- needs to be processed through separate batches under T Code F110
    Vis-à-vis any single invoices whose value is less than Rs 50000/- also needs to be processed through a separate batch. The system should list out all the transaction based on the Value of the Invoices covering Rs 50000/- under T Code F 110
    Do we have any standard functionality where in we can restrict the invoices till certain amount.
    Kindly help
    Regards,
    Mercy

    Dear,
    You can only chose 'free selection' tab in F110 for a single value by 'field name'. To do that you must change yours invoices in FBL1N or FBL5N. Run one of these reports for your open items dispalay and sort by amount. Block in mass all open items with amount exceded and go to F110. This is a tip to have your desired result. I hope it helps.
    Regards

  • Can a sprite become visible after a certain amount of user inactivity?

    Can a sprite become visible after a certain amount of user inactivity? like a timer triggering an event?

    Hi Kevin,
    You can look at the on timeOut event. (This is not to be confused with timeOut objects)
    There are a number of related properties, which date back from the early days of Director, and which seem to have been omitted from recent versions of the documentation, even though they still function. I give them here with their original names (prior to Director 10):
    the timeOutKeyDown
    the timeOutLapsed
    the timeOutLength
    the timeOutMouse
    the timeOutPlay
    the timeOutScript
    the lastClick
    the lastEvent
    the lastKey
    the lastRoll
    (You can also use the more recent DOM style for these last four properties: _player.lastXXX)
    Here's a very simple script which will make sprite 1 disappear when the movie starts, and reappear if the user does nothing for 5 seconds:
    on startMovie()
      sprite(1).visible = FALSE
      the timeOutLength = 300 -- = 5 seconds * 60 ticks / second
    end startMovie
    on timeOut()
      sprite(1).visible = TRUE
    end timeOut
    If you click the mouse at intervals of less than 5 seconds after starting the movie, then the sprite will remain invisible.
    NOTE: Using sprite(x).visible = FALSE will make the entire sprite channel invisible everywhere in the Score. It's better to use sprite(x).blend = 0, unless the sprite must not react to the mouse while it is invisble, in which case it is better to move it off-stage.
    Is this what you are looking for?
    James

  • Video content freezes for a certain amount of time on Lion

    After upgrading to Lion, I have noticed that video content freezes (though the voice is heard, but the picture is frozen for some seconds) for a certain amount of
    time when its starts playing (eg youtube videos) on Lion.
    I have observed this on my friends macbook pro also.
    I have a macbook (mid 2010 model)

    Stats Before playing a video
    Stats while playing a video in youtube

Maybe you are looking for