Re: Complex query

From: Igor Neyman <ineyman(at)perceptron(dot)com>
To: Leonardo M(dot) Ramé <l(dot)rame(at)griensu(dot)com>, PostgreSql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Complex query
Date: 2014-03-31 18:48:58
Message-ID: A76B25F2823E954C9E45E32FA49D70EC7A9C351C@mail.corp.perceptron.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-
> owner(at)postgresql(dot)org] On Behalf Of Leonardo M. Ramé
> Sent: Monday, March 31, 2014 2:38 PM
> To: PostgreSql-general
> Subject: [GENERAL] Complex query
>
> Hi, I'm looking for help with this query.
>
> Table Tasks:
>
> IdTask StatusCode StatusName
> ----------------------------------
> 1 R Registered
> 1 S Started
> 1 D Dictated
> 1 F Finished
> 1 T Transcribed
> ----------------------------------
> 2 R Registered
> 2 S Started
> 2 T Transcribed
> 2 F Finished
>
> As you can see, I have a table containing tasks and statuses. What I would like
> to get is the list of tasks, including all of its steps, for only those tasks where
> the StatusCode sequence was S followed by T.
>
> In this example, the query should only return task Nº 2:
>
> 2 R Registered
> 2 S Started
> 2 T Transcribed
> 2 F Finished
>
> Can anybody help me with this?.
>
> Regards,
> --
> Leonardo M. Ramé
> Medical IT - Griensu S.A.
> Av. Colón 636 - Piso 8 Of. A
> X5000EPT -- Córdoba
> Tel.: +54(351)4246924 +54(351)4247788 +54(351)4247979 int. 19
> Cel.: +54 9 (011) 40871877
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

Leonardo,

Unless you add one more column to your Tasks table, specifically: StatusTimestamp as in:

IdTask StatusCode StatusName StatusTimestamp

You cannot find which record in the table follows which, because order in which records returned from the database is not guaranteed until you add "ORDER BY" clause to your SELECT statement.

Regards,
Igor Neyman

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Moshe Jacobson 2014-03-31 18:49:46 Wanted: ALTER TRIGGER ... OWNED BY EXTENSION
Previous Message David Johnston 2014-03-31 18:46:28 Re: Complex query