Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 61DC09FB2CE for ; Fri, 27 Jul 2007 16:30:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 02532-01 for ; Fri, 27 Jul 2007 16:28:55 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.246]) by postgresql.org (Postfix) with ESMTP id E61A99FB2B3 for ; Fri, 27 Jul 2007 16:28:58 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c36so178848ana for ; Fri, 27 Jul 2007 12:28:57 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=JRuoSr+85/QqVU5WA1bJbXNJPyWD+1x36vONQIwmEaEjWGQFy2G88uiVyWEyHDFccd2doicbE2SDCNHfrZBV+wZtncYkQdzRyupp2hx7nGS0IbdRL5A3BCI9WugFeCZBt5JszV4firty9dklwFl5qcaBJuwX5odBfUD1K3Qhx4I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=XNuswgAEXxl5mlY6rWmhmr+ORhe0SwJbbpiRdfNOBvP7AgXLm8UN0FkAZlYF+Y4gGBmO4+1Gj2ByeuP+7FNEBQliGw719Aos6rZQ91XqNj3oXB69dAI7csYpeHqwfO2GN13XJq7/eABrTY7cKyhF/pk/8a5/RVzn4pVQOiEx8lA= Received: by 10.100.127.1 with SMTP id z1mr3217861anc.1185564536642; Fri, 27 Jul 2007 12:28:56 -0700 (PDT) Received: by 10.100.33.20 with HTTP; Fri, 27 Jul 2007 12:28:56 -0700 (PDT) Message-ID: Date: Fri, 27 Jul 2007 14:28:56 -0500 From: "=?UTF-8?Q?Rodrigo_De_Le=C3=B3n?=" To: "Carol Cheung" Subject: Re: group by range of values Cc: pgsql-sql@postgresql.org In-Reply-To: <46AA41EC.8050101@consumercontact.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46AA41EC.8050101@consumercontact.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/173 X-Sequence-Number: 28908 On 7/27/07, Carol Cheung wrote: > Something like: > > decade | average(salary) > -------+----------------- > 1940 | 69500 > 1950 | 53333.33 > 1960 | 53000 > 1970 | 40333.33 CREATE TABLE tester ( birth_year integer, salary numeric(10,2) ); SELECT SUBSTRING(TO_CHAR(BIRTH_YEAR,'FM9999') FROM 1 FOR 3)||'0' AS DECADE , AVG(SALARY) AS AVG_SALARY FROM TESTER GROUP BY SUBSTRING(TO_CHAR(BIRTH_YEAR,'FM9999') FROM 1 FOR 3)||'0' ORDER BY DECADE;