pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedSELECT column WHERE time_type = 'Break' but only the rows that are after(below) time_type = 'Start'
2+ messages / 2 participants
[nested] [flat]
* SELECT column WHERE time_type = 'Break' but only the rows that are after(below) time_type = 'Start'
@ 2015-06-27 17:43 litu16 <litumelendez@gmail.com>
2015-06-28 04:04 ` Re: SELECT column WHERE time_type = 'Break' but only the rows that are after(below) time_type = 'Start' Cliff Pratt <enkiduonthenet@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: litu16 @ 2015-06-27 17:43 UTC (permalink / raw)
To: pgsql-admin
))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...
<http://postgresql.nabble.com/file/n5855467/screenshot.jpg;
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-be...
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: SELECT column WHERE time_type = 'Break' but only the rows that are after(below) time_type = 'Start'
2015-06-27 17:43 SELECT column WHERE time_type = 'Break' but only the rows that are after(below) time_type = 'Start' litu16 <litumelendez@gmail.com>
@ 2015-06-28 04:04 ` Cliff Pratt <enkiduonthenet@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Cliff Pratt @ 2015-06-28 04:04 UTC (permalink / raw)
To: pgsql-admin
One way would be to use a SELECT in a WHERE clause:
SELECT SUM(<column_that_you_want_to_sum>) FROM <your_table> WHERE (SELECT
<column_that_you_want_to_select_on> >
MAX(<field_that_you_want_to_compare_against>);
Something along those lines should work.
Cheers,
Cliff
On Sun, Jun 28, 2015 at 5:43 AM, litu16 <litumelendez@gmail.com> wrote:
> ))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...
>
> <http://postgresql.nabble.com/file/n5855467/screenshot.jpg;
>
> 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-be...
> 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
>
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2015-06-28 04:04 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-06-27 17:43 SELECT column WHERE time_type = 'Break' but only the rows that are after(below) time_type = 'Start' litu16 <litumelendez@gmail.com>
2015-06-28 04:04 ` Cliff Pratt <enkiduonthenet@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox