<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to retrieve a statistic sample from a database table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897744#M1596434</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say I have a 100.000 rows table and I want to take a representative statistical sample from that table.&lt;/P&gt;&lt;P&gt;Say, it should be 5% (or 5000 rows).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question is: How to ensure that the sample is representative? &lt;/P&gt;&lt;P&gt;This is not guaranteed by UP TO N ROWS because the database selects without having an order by  or WHERE starting reading the first db blocks until it reaches  the limit of 5000 rows. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * UP TO 5000 rows into table .... from ZSAMPLE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This means I miss mostly of the records in the table, hence the sample is not representative.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you ever encounter such a problem?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Apr 2011 09:09:06 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-04-21T09:09:06Z</dc:date>
    <item>
      <title>How to retrieve a statistic sample from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897744#M1596434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say I have a 100.000 rows table and I want to take a representative statistical sample from that table.&lt;/P&gt;&lt;P&gt;Say, it should be 5% (or 5000 rows).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question is: How to ensure that the sample is representative? &lt;/P&gt;&lt;P&gt;This is not guaranteed by UP TO N ROWS because the database selects without having an order by  or WHERE starting reading the first db blocks until it reaches  the limit of 5000 rows. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * UP TO 5000 rows into table .... from ZSAMPLE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This means I miss mostly of the records in the table, hence the sample is not representative.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you ever encounter such a problem?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 09:09:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897744#M1596434</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-21T09:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve a statistic sample from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897745#M1596435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;never encountered such a requirement. And i really wonder for what this may be good.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Computers are so fast nowadays that i do not have any idea why you dont go for all the data instead of viewing just that "representative" ones.&lt;/P&gt;&lt;P&gt;Sorry i couldnt help you out here, but still i´m quite interested what this is about.&lt;/P&gt;&lt;P&gt;Maybe we can get you into other ideas once we know for what exactly you are doing this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 09:15:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897745#M1596435</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-21T09:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve a statistic sample from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897746#M1596436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;yes it's not representative.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should insert more statistical conditions, such as the date (maybe the year), the type of record, the status, the amount...&lt;/P&gt;&lt;P&gt;but it depends of the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Surely you have to make a list of these fields and make a select balanced on their values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;example considering only the year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at year. "range build on 5 years&lt;/P&gt;&lt;P&gt;   select fields up to 1000 rows&lt;/P&gt;&lt;P&gt;     from table &lt;/P&gt;&lt;P&gt;     appending table i_tab&lt;/P&gt;&lt;P&gt;     where year...&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 09:18:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897746#M1596436</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-21T09:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve a statistic sample from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897747#M1596437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could SELECT (with package size if desired) into an internal table.  Then:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Select * from table into internal table........&lt;/P&gt;&lt;P&gt;  package size 10000.  "not really necessary for 100000 row table &lt;/P&gt;&lt;P&gt;*Initialize a counter of type i.&lt;/P&gt;&lt;P&gt;  lv_counter = 0.&lt;/P&gt;&lt;P&gt;loop at the internal table.&lt;/P&gt;&lt;P&gt;  lv_counter = lv_counter + 1. &lt;/P&gt;&lt;P&gt;   if lv_counter lt 20. "1 in 20 = 5%&lt;/P&gt;&lt;P&gt;     delete internal table. "drop this row.&lt;/P&gt;&lt;P&gt;   elseif lv_counter eq 20.&lt;/P&gt;&lt;P&gt;     lv_counter = 0.  &lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;endselect.  "if you used package size.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;at the end you would have kept every 1 out of every 20 records from your original table select.  Be sure to use a package size (if needed ) that is an exact multiple of 20.  To futher randomize the table, you could sort on some field that has random values, etc. before doing the every 20th record retention.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 11:56:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897747#M1596437</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-21T11:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to retrieve a statistic sample from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897748#M1596438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It depends on what you mean by "representative". if you mean any 5,000 rows, then it doesn't matter how you pick them. If you want a truly random selection, then Breakpoint's solution (while looking good otherwise, won't do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Apr 2011 13:12:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-retrieve-a-statistic-sample-from-a-database-table/m-p/7897748#M1596438</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-21T13:12:38Z</dc:date>
    </item>
  </channel>
</rss>

