pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
SUM all timeelapse WHERE timetype = 'Break' but only the rows that are after(below) timetype = 'Start'
2+ messages / 2 participants
[nested] [flat]

* SUM all timeelapse WHERE timetype = 'Break' but only the rows that are after(below) timetype = 'Start'
@ 2015-06-28 05:56  litu16 <litumelendez@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: litu16 @ 2015-06-28 05:56 UTC (permalink / raw)
  To: pgsql-admin

))Hi all, This is my table...

<http://postgresql.nabble.com/file/n5855509/screenshot.jpg; 

This is the SQL statement to create the same table...

   * CREATE TABLE tbl_ebscbspa_log05
    (
      pcnum smallint NOT NULL,
      fnserial serial NOT NULL,
      fnname character varying NOT NULL,
      timestmp timestamp without time zone DEFAULT clock_timestamp(),
      timeelapse interval,
      timetype character varying,
      timeindex real,
      CONSTRAINT table_ebscb_spa_log05_pkey PRIMARY KEY (fnserial)
    )
    WITH (
      OIDS=FALSE
    );
    ALTER TABLE tbl_ebscbspa_log05
      OWNER TO postgres;*

How can I SUM all timeelapse WHERE timetype = 'Break' AND that are placed
after(below) the last(descendent) timetype = 'Start'? So in the table above
Ill get both blue square colored rows summed up. So I get 'totalbreak' =
00-00-00 02:00:00.000

How would be the syntax to select all possible 'Breaks' after the
last(descendent) 'Start' and sum them up? (lets say the max possible
'Breaks' are nine).

I have try this, resulting NULL

    *SELECT t.timeelapse FROM tbl_ebscbspa_log05 t WHERE t.timetype =
'Break' AND NOT EXISTS (SELECT 1 FROM tbl_ebscbspa_log05 WHERE timetype =
'Start' AND 'timestmp' > 't.timestmp') INTO v_timeelapse_break;
            IF FOUND THEN
              NEW.timeelapse := v_timeelapse_break;*

Pls I would like to know how to SUM THEM UP, not just SELECT THEM, hope some
good PostgreSQL fellow programmer could give me a hand with it.

Thanks Advanced.



--
View this message in context: http://postgresql.nabble.com/SUM-all-timeelapse-WHERE-timetype-Break-but-only-the-rows-that-are-afte...
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: SUM all timeelapse WHERE timetype = 'Break' but only the rows that are after(below) timetype = 'Start'
@ 2015-06-30 20:17  David G. Johnston <david.g.johnston@gmail.com>
  parent: litu16 <litumelendez@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2015-06-30 20:17 UTC (permalink / raw)
  To: litu16 <litumelendez@gmail.com>; +Cc: pgsql-admin

On Sun, Jun 28, 2015 at 1:56 AM, litu16 <litumelendez@gmail.com> wrote:

>
> Pls I would like to know how to SUM THEM UP, not just SELECT THEM, hope
> some
> good PostgreSQL fellow programmer could give me a hand with it.
>
>
​http://www.postgresql.org/docs/9.4/interactive/functions-aggregate.html

Also see "GROUP BY"

Instead of showing a picture of a table you might get more help if you make
into into a VALUES-based CTE and incorporate it directly into an example
query.

WITH data AS ( VALUES (...),(...),(...) )
SELECT ...
FROM data
...

David J.
​

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2015-06-30 20:17 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-06-28 05:56 SUM all timeelapse WHERE timetype = 'Break' but only the rows that are after(below) timetype = 'Start' litu16 <litumelendez@gmail.com>
2015-06-30 20:17 ` David G. Johnston <david.g.johnston@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