X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2477AD76D1 for ; Wed, 24 Aug 2005 10:43:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 59197-04 for ; Wed, 24 Aug 2005 13:43:54 +0000 (GMT) Received: from ibox-server.openwired.net (77.Red-213-97-52.pooles.rima-tde.net [213.97.52.77]) by svr1.postgresql.org (Postfix) with ESMTP id A90EDD76CF for ; Wed, 24 Aug 2005 10:43:52 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by ibox-server.openwired.net (Postfix) with ESMTP id 749E52E00F6 for ; Wed, 24 Aug 2005 15:38:41 +0100 (BST) Received: from ibox-server.openwired.net ([127.0.0.1]) by localhost (ibox-server.openwired.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 20099-01 for ; Wed, 24 Aug 2005 15:38:39 +0100 (BST) Received: from [10.0.0.21] (unknown [10.0.0.21]) by ibox-server.openwired.net (Postfix) with ESMTP id 99D762E00F5 for ; Wed, 24 Aug 2005 15:38:39 +0100 (BST) Message-ID: <430C7A21.9020306@openwired.net> Date: Wed, 24 Aug 2005 15:46:09 +0200 From: =?ISO-8859-1?Q?Josep_Sanmart=ED?= User-Agent: Mozilla Thunderbird 1.0.5 (X11/20050711) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: How to join several selects Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by I-Box de Openwired (www.openwired.com) Antivirus-Antispam at openwired.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200508/224 X-Sequence-Number: 22452 Hello, I have a 'big' problem: I have the following table users(name, start_time, end_time), a new row is set whenever a user logs into a server. I want to know how many users have logged in EVERYDAY between 2 different dates. The only idea that I have is making several select (one for each day): SELECT COUNT(name) FROM users WHERE start_time between "startDate" and "startDate+1" SELECT COUNT(name) FROM users WHERE start_time between "startDate+1" and "startDate+2" ... I would like to know if its possible to make it in 1 sql statement or just which is the best efficient way to solve it. By the way, I use Postgres 7.4. Thanks! -- Josep Sanmarti Analista de Projectes Grup OpenWired, S.L. Caballero, 87 - 08029 - Barcelona (Spain) Tel (+34) 93/410 75 70 - Fax (+34) 93/419 45 91