Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 9B8ED2E0050 for ; Thu, 1 May 2008 00:12:21 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 93112-09 for ; Thu, 1 May 2008 00:12:15 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from web54307.mail.re2.yahoo.com (web54307.mail.re2.yahoo.com [206.190.49.117]) by developer.postgresql.org (Postfix) with SMTP id B52132E004C for ; Thu, 1 May 2008 00:12:13 -0300 (ADT) Received: (qmail 2552 invoked by uid 60001); 30 Apr 2008 23:12:12 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=mnoiAkHRcPb9tcLJ9xsgHvSELd2JF0JgjjxQnLZKZz1PP5wUWpjZEMnmBIac0wg+UWrCg1FnOLFrTjQd28M6qR8A4tNesBYlm68Cv6Qwzk8edmFG6u/wpPNi7i6aD7iYAA0soGc7tmHumbII9gSGqSm667jrOrPPoEpXBuP5BzQ=; X-YMail-OSG: dfEhcbgVM1kEIEuIUZYXwLSPw1ILh_LOjRvVvtOp0_z5JWr9zdkl1DnYKwz.CHn0lw-- Received: from [69.227.19.53] by web54307.mail.re2.yahoo.com via HTTP; Wed, 30 Apr 2008 16:12:12 PDT Date: Wed, 30 Apr 2008 16:12:12 -0700 (PDT) From: chester c young Subject: Re: columns for count histograms of values To: Alexy Khrabrov Cc: sql pgsql In-Reply-To: <824FF9F9-9997-4AD9-9955-3CA658E150D4@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <357171.1486.qm@web54307.mail.re2.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200805/1 X-Sequence-Number: 30767 --- Alexy Khrabrov wrote: > Greetings -- I have a table of the kind > > Ratings: > id integer > rating smallint > > -- where value can take any value in the range 1 to 5. Now I want to > > have a statistical table Stats of the form > > id integer > min smallint > max smallint > avg real > r1 integer > r2 integer > r3 integer > r4 integer > r5 integer > > -- how can I create it in one pass over Ratings? select id, min(rating), max(rating), avg(rating), sum( case rating = 1 then 1 else 0 end ), ... ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ