Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 8B41F9F9FA7 for ; Mon, 8 Oct 2007 07:49:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 26951-10 for ; Mon, 8 Oct 2007 07:49:11 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by postgresql.org (Postfix) with ESMTP id 159EA9F9CAE for ; Mon, 8 Oct 2007 07:49:10 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id j3so810863ugf for ; Mon, 08 Oct 2007 03:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; bh=dA5Q8/cpX19bgi8xwhPZ2Wm3NlP43SldXGNwFwoEF3I=; b=omUsUZyYFQey6Z/NM5JnwRgG4m3rptzRps5A7Kxi5Zh5Vi1SHd1dbs+uN6r79BglgifdFSzdMUZwC1sBZBMI9Ycu3V2E2JU0KO6JqvWT/NwXT/JErs+/QSo7SxC3ntL5DLKgLnTm0gCXwaOT/G4SFxiIqjG3pa0aRjR2bfst3tU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=o6w41RwrOlGqzaHwAvubDHyRRoCFMrN4YV9Gi7ikNaM379L6FSfuVHORgo8+eDAQ7ssvBqPh8EYbhIdo0m0ZczJM34Nf6FfHykPrtN0j3je13AEhS5QXa32DWLrWuDI4f1XRoWkqLY5jkDXNMULrlLYt4FrWkKcKDX5L7QZpmRE= Received: by 10.67.28.3 with SMTP id f3mr6703355ugj.1191840548227; Mon, 08 Oct 2007 03:49:08 -0700 (PDT) Received: from ?192.168.10.68? ( [193.238.52.47]) by mx.google.com with ESMTPS id e33sm14741723ugd.2007.10.08.03.49.05 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 08 Oct 2007 03:49:06 -0700 (PDT) Message-ID: <470A0B20.40203@gmail.com> Date: Mon, 08 Oct 2007 12:49:04 +0200 From: =?ISO-8859-1?Q?Dani_Casta=F1os?= User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Get different sums from the same table in one query Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/37 X-Sequence-Number: 29409 Hi all! I want to put this three queries in only one... Take a look that the only thing that changes is the message_type_id. Any suggestions?? SELECT TO_CHAR( statistics_date, 'DD/MM/YYYY') AS date_in, sum(total_num_messages) FROM statistics_daily WHERE message_type_id IN (4,5) AND statistics_date = CURRENT_DATE AND telecom_operator_id <> 0 AND telephone_number IN ( $numbers ) GROUP BY date_in SELECT TO_CHAR( statistics_date, 'DD/MM/YYYY') AS date_in, sum(total_num_messages) FROM statistics_daily WHERE message_type_id IN (6) AND statistics_date = CURRENT_DATE AND telecom_operator_id <> 0 AND telephone_number IN ( $numbers ) GROUP BY date_in SELECT TO_CHAR( statistics_date, 'DD/MM/YYYY') AS date_in, sum(total_num_messages) FROM statistics_daily WHERE message_type_id IN (21) AND statistics_date = CURRENT_DATE AND telecom_operator_id <> 0 AND telephone_number IN ( $numbers ) GROUP BY date_in Thank you in advance!