SUM all timeelapse WHERE timetype = 'Break' but only the rows that are after(below) timetype = 'Start'

Поиск
Список
Период
Сортировка
От litu16
Тема SUM all timeelapse WHERE timetype = 'Break' but only the rows that are after(below) timetype = 'Start'
Дата
Msg-id 1435470976136-5855509.post@n5.nabble.com
обсуждение исходный текст
Ответы Re: SUM all timeelapse WHERE timetype = 'Break' but only the rows that are after(below) timetype = 'Start'
Список 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-after-below-timetype-Start-tp5855509.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.


В списке pgsql-admin по дате отправления:

Предыдущее
От: xujian
Дата:
Сообщение: Postgresql gss user map doesn't work
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: SUM all timeelapse WHERE timetype = 'Break' but only the rows that are after(below) timetype = 'Start'