Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id EC5BCB5D832 for ; Thu, 9 Jun 2011 11:32:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 79590-02 for ; Thu, 9 Jun 2011 14:32:05 +0000 (UTC) X-Greylist: delayed 00:15:06.20219 by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id 24132B5D80A for ; Thu, 9 Jun 2011 11:32:04 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id M36PVGJK; Thu, 9 Jun 2011 15:16:57 +0100 Message-ID: From: "Oliveiros d'Azevedo Cristina" To: "Andreas" , References: <4DF0CDFC.4070802@gmx.net> Subject: Re: need help with some aggregation magic Date: Thu, 9 Jun 2011 15:16:57 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/24 X-Sequence-Number: 35490 The ts means the time the user started on a project ? Or the time he finished? Or can mean both? If so, how do you can tell one from the other? Different event_type s ? Is it correct to assume from your words that an user cannot be in more than one project at the time? If so, can't be overlapping, right? Best, Oliveiros ----- Original Message ----- From: "Andreas" To: Sent: Thursday, June 09, 2011 2:43 PM Subject: [SQL] need help with some aggregation magic > hi, > I have a log-table that stores events of users and projects like this > ( user_id integer, project_id integer, ts timestamp, event_type integer ) > > I need an aggregated list of worktime per user, per project, per day. > > The users can switch projects during the day so I can't work this out with > min(ts) and max(ts). > > Is there a clever way to get this with SQL ? > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql