Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id AFB41B5DC0D for ; Wed, 13 Jul 2011 10:58:17 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 07904-01 for ; Wed, 13 Jul 2011 13:58:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh5.mail.rice.edu (mh5.mail.rice.edu [128.42.199.32]) by mail.postgresql.org (Postfix) with ESMTP id 79EE0B5DBBF for ; Wed, 13 Jul 2011 10:58:11 -0300 (ADT) Received: from mh5.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh5.mail.rice.edu (Postfix) with ESMTP id 6E8E52901A5; Wed, 13 Jul 2011 08:58:11 -0500 (CDT) X-Virus-Scanned: by amavis-2.6.4 at mh5.mail.rice.edu Received: from mh5.mail.rice.edu ([127.0.0.1]) by mh5.mail.rice.edu (mh5.mail.rice.edu [127.0.0.1]) (amavis, port 10024) with ESMTP id QTXHTY+XvOC8; Wed, 13 Jul 2011 08:58:11 -0500 (CDT) X-SMTP-Auth: no X-SMTP-Auth: no Received: from staff-mud-56-27.rice.edu (staff-mud-56-27.rice.edu [168.7.56.27]) by mh5.mail.rice.edu (Postfix) with ESMTP id 3A1812901A2; Wed, 13 Jul 2011 08:58:11 -0500 (CDT) Received: by staff-mud-56-27.rice.edu (Postfix, from userid 18612) id 2258E740D44; Wed, 13 Jul 2011 08:58:11 -0500 (CDT) Date: Wed, 13 Jul 2011 08:58:10 -0500 From: "ktm@rice.edu" To: "Jira, Marcel" Cc: "'pgsql-sql@postgresql.org'" Subject: Re: Select random lines of a table using a probability distribution Message-ID: <20110713135810.GA1874@staff-mud-56-27.rice.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-12-10) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_FILL_THIS_FORM_SHORT=0.01, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201107/59 X-Sequence-Number: 35629 On Wed, Jul 13, 2011 at 03:27:10PM +0200, Jira, Marcel wrote: > Hi! > > Let's consider I have a table like this > > id qualification gender age income > > I'd like to select (for example 100) lines of this table by random, but the random mechanism has to follow a certain probability distribution. > > I want to use this procedure to construct a test group for another selection. > > Example: > > I filter all lines having the qualification "plumber". > I get 50 different ids consisting of 40 males, 10 females and a certain age distribution. > > I also get some information concerning the income of the plumbers. > > Now I want to know if the income is more influenced by the gender and age distribution or by the qualification "plumber". > > Therefore I would like to select a test group (of 50 or more) without any plumbers. This test group has to follow the same age and gender distribution. > > Then I would be able to compare this groups income statistics with the plumbers income statistics. > > Is this possible (and doable with reasonable effort) in PostgreSQL? > > Thank you in advance. > > Best regards, > > Marcel Jira > You may want to take a look at pl/R which make the R system available to PostgreSQL as a function language. Regards, Ken