Re: can you solve this?

From: TurkBear <johng_at_mm.com>
Date: Mon, 21 Aug 2000 14:23:59 GMT
Message-ID: <39a138f4.3305773_at_news>


Try this ( maybe scientifically a little sloppy, but, unless you are doing high-precision random sampling work ( in which case use SAS ) , it should be sufficient)...

Note: Oracle ( absent indexes, partitions, etc) stores rows randomly(in the non-precise sense of the word) so:

( for your example 2)  

First determine relative weight:
add column called age_group and set it to the range you want ...

then in Sql Plus:
compute sum of howmany on report
break on age_group on report

select age_group,count(*) howmany from table_name group by age_group;

( use a calculator to figure count/sum for each age_group and use this to determine # or records needed for each age_group)

then:
select * from table_name where age_group = 'desired_value1' and rownum < (# computed above for this desiered_value) union all
select * from table_name where age_group = 'desired_value2' and rownum < (# computed above for this desired_value)
union all
select * from table_name where age_group = 'desired_value3' and rownum < (# computed above for this desiered_value)

and so on until you have selected from al age_groups and totaled 500 ( about) records...

hth,

"Hagai Katz" <katzh_at_bgumail.bgu.ac.il> wrote:

>Here's a tough one... Oracle support failed to solve it.
>
>1. let's start simple: How can you derive a sample of a predefined number of
>rows from a table, when the lines are picked RANDOMLY?
>2. Now let's make it tougher:
>how can you do a layered sample, in which you take a RANDOMLY selected
>number of lines from different groups of rows in a table, which are defined
>by a column in the table, and the number of rows sampled from each group
>must be determined according to the relative size of that group in the
>table.
>For example: I have a table with clients, distinguished by a column called
>AGE into age groups, and I want to take a random sample of 500 clients, in
>which every age group will be represented according to it's relative weight
>in my clients group. how do I do that?
>
>any ideas?
>Best solutions will be circulated around...
>
>PS - Oracle 8i please...
>
  Received on Mon Aug 21 2000 - 16:23:59 CEST

Original text of this message