Re: Complex query

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

> -----Original Message-----
> From: Leonardo M. Ramé [mailto:l(dot)rame(at)griensu(dot)com]
> Sent: Monday, March 31, 2014 2:56 PM
> To: Igor Neyman
> Cc: PostgreSql-general
> Subject: Re: [GENERAL] Complex query
>
> On 2014-03-31 18:48:58 +0000, Igor Neyman wrote:
> > > -----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.
> > >
> >
> > 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
> >
> >
>
> You are right, let's add the Id column. This is just an example, the real table (a
> view) contains both, the Id and a timestamp:
>
> Id IdTask StatusCode StatusName
> ----------------------------------
> 1 1 R Registered
> 2 1 S Started
> 3 1 D Dictated
> 4 1 F Finished
> 5 1 T Transcribed
> ----------------------------------
> 6 2 R Registered
> 7 2 S Started
> 8 2 T Transcribed
> 9 2 F Finished
>
> After adding the Id column, can I use a window function to get what I need?.
>
> 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

D.Johnston showed how to use windows function in this case.

Regards,
Igor Neyman

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Igor Neyman 2014-03-31 19:07:37 Re: getting the current query from pg_stat_activity
Previous Message Si Chen 2014-03-31 18:57:06 getting the current query from pg_stat_activity