Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 899DD9F9854 for ; Mon, 8 Oct 2007 08:37:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 23645-06 for ; Mon, 8 Oct 2007 08:37:15 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by postgresql.org (Postfix) with ESMTP id E741C9F9798 for ; Mon, 8 Oct 2007 08:37:15 -0300 (ADT) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay05.plus.net with esmtp (Exim) id 1Ieqv8-0006mW-HU; Mon, 08 Oct 2007 12:37:12 +0100 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id C48F7274054; Mon, 8 Oct 2007 12:37:09 +0100 (BST) Message-ID: <470A1665.6030500@archonet.com> Date: Mon, 08 Oct 2007 12:37:09 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.6 (X11/20070728) MIME-Version: 1.0 To: =?ISO-8859-1?Q?Dani_Casta=F1os?= CC: pgsql-sql@postgresql.org Subject: Re: Get different sums from the same table in one query References: <470A0B20.40203@gmail.com> In-Reply-To: <470A0B20.40203@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/40 X-Sequence-Number: 29412 Dani Casta=F1os wrote: > Hi all! >=20 > I want to put this three queries in only one... Take a look that the=20 > only thing that changes is the message_type_id. Any suggestions?? >=20 > SELECT TO_CHAR( statistics_date, 'DD/MM/YYYY') AS date_in,=20 > sum(total_num_messages) > FROM statistics_daily > WHERE message_type_id IN (4,5) > AND statistics_date =3D CURRENT_DATE > AND telecom_operator_id <> 0 > AND telephone_number IN ( $numbers ) > GROUP BY date_in Is this what you mean? SELECT message_type_id, to_char... ... WHERE message_type_id IN (4,5,6,21) ... GROUP BY message_type_id, date_id --=20 Richard Huxton Archonet Ltd