Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z91tz-0007Y4-SU for pgsql-admin@arkaria.postgresql.org; Sun, 28 Jun 2015 02:01:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z91tz-0000lV-1c for pgsql-admin@arkaria.postgresql.org; Sun, 28 Jun 2015 02:00:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Z8u8U-00020N-LA for pgsql-admin@postgresql.org; Sat, 27 Jun 2015 17:43:26 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Z8u8Q-00028Q-Oj for pgsql-admin@postgresql.org; Sat, 27 Jun 2015 17:43:25 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id 7A5F4FE46EE for ; Sat, 27 Jun 2015 10:44:03 -0700 (PDT) Date: Sat, 27 Jun 2015 10:43:19 -0700 (MST) From: litu16 To: pgsql-admin@postgresql.org Message-ID: <1435426999355-5855467.post@n5.nabble.com> Subject: SELECT column WHERE time_type = 'Break' but only the rows that are after(below) time_type = 'Start' MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org ))Hi all, currently Im stuck in an issue, hope some good PostgreSQL fellow programmer could give me a hand with it. This is my table... I would like to SELECT all 'time_elapse' WHERE time_type = 'Break' but only the rows that are after(below) the last(descendent) time_type = 'Start' and sum them up. So in the table above I would SELECT... * time_elapse | time_type | time_index ----------------------------+-------------+------------- 00-00-00 01:00:00.00 | Break | 2.1 00-00-00 01:00:00.00 | Break | 2.2* So totalbreak = 00-00-00 02:00:00.000 I know how to convert character varying to timestamp in order to sum them up, But I don't know how would be the syntax to select all possible 'Breaks' and sum them up (lets say the max Breaks between each 'Start' is nine). I can hardly imagine a way to do that, so I would like to ask for suggestions. Thanks Advanced. -- View this message in context: http://postgresql.nabble.com/SELECT-column-WHERE-time-type-Break-but-only-the-rows-that-are-after-below-time-type-Start-tp5855467.html Sent from the PostgreSQL - admin mailing list archive at Nabble.com. -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin