Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 374A9B5DC57 for ; Thu, 9 Jun 2011 10:50:17 -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 39363-04-7 for ; Thu, 9 Jun 2011 13:50:04 +0000 (UTC) X-Greylist: delayed 00:06:39.351793 by SQLgrey-1.7.6 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23]) by mail.postgresql.org (Postfix) with SMTP id B40D3B5DC55 for ; Thu, 9 Jun 2011 10:50:03 -0300 (ADT) Received: (qmail invoked by alias); 09 Jun 2011 13:43:22 -0000 Received: from p57BB6483.dip.t-dialin.net (EHLO [192.168.1.113]) [87.187.100.131] by mail.gmx.net (mp049) with SMTP; 09 Jun 2011 15:43:22 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1+b8G56oWGbLFZG3U5NlHW5ie/9n8G+untlTmsVXg tvM6I996Hd/ZPM Message-ID: <4DF0CDFC.4070802@gmx.net> Date: Thu, 09 Jun 2011 15:43:24 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: need help with some aggregation magic Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201106/23 X-Sequence-Number: 35489 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 ?