Re: [GENERAL] Complex query

2014-03-31 Thread Leonardo M . Ramé
On 2014-03-31 12:16:53 -0700, David Johnston wrote: > Leonardo M. Ramé-2 wrote > > select lag.id, lag.idtask, lag.code, lag.lg from (select idtask, code, id, > > lag(code, -1) over () as lg from tasks_test) as lag > > First you want to include an ORDER BY in the OVER(...) clause, and probably > a

Re: [GENERAL] Complex query

2014-03-31 Thread David Johnston
Leonardo M. Ramé-2 wrote > select lag.id, lag.idtask, lag.code, lag.lg from (select idtask, code, id, > lag(code, -1) over () as lg from tasks_test) as lag First you want to include an ORDER BY in the OVER(...) clause, and probably a PARTITION BY as well. Then you move that to a sub-query (for e

Re: [GENERAL] Complex query

2014-03-31 Thread Leonardo M . Ramé
On 2014-03-31 11:46:28 -0700, David Johnston wrote: > Leonardo M. Ramé-2 wrote > > Hi, I'm looking for help with this query. > > > > Table Tasks: > > > > IdTask StatusCode StatusName > > -- > > 1 R Registered > > 1 S Started > > 1

[GENERAL] Complex query

2014-03-31 Thread Leonardo M . Ramé
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 --

Re: [GENERAL] Complex query

2014-03-31 Thread Igor Neyman
> -Original Message- > From: Leonardo M. Ramé [mailto:l.r...@griensu.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 +, Igor Neyman wrote: >

Re: [GENERAL] Complex query

2014-03-31 Thread Leonardo M . Ramé
-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 Statu

Re: [GENERAL] Complex query

2014-03-31 Thread David Johnston
Leonardo M. Ramé-2 wrote > 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

Re: [GENERAL] Complex query

2014-03-31 Thread Raymond O'Donnell
On 31/03/2014 19:38, Leonardo M. Ramé wrote: > 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 Fi

Re: [GENERAL] Complex query

2014-03-31 Thread Igor Neyman
> -Original Message- > From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general- > ow...@postgresql.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 loo

Re: [GENERAL] Complex query question

2011-09-07 Thread Mike Orr
This works beautifully. Thanks to you and Osvaldo; I learned something more about querying today. I wasn't so much wanting to learn about subqueries as to how to do these kinds of queries. In this case, I'm testing a search routine, and I needed to extract some possible results to expect. (I actu

Re: [GENERAL] Complex query question

2011-09-07 Thread Albe Laurenz
Mike Orr wrote: > I have a complex query question whose answer I think would help me to > understand subselects and aggregates better. I have a table with four > columns of interest: > > id (int primary key), loc_title (varchar null), loc_value (float > null), loc_unit (varchar null) > > I want t

Re: [GENERAL] Complex query question

2011-09-07 Thread Jayadevan M
Hello, > I have a complex query question whose answer I think would help me to > understand subselects and aggregates better. I have a table with four > columns of interest: > > id (int primary key), loc_title (varchar null), loc_value (float > null), loc_unit (varchar null) > > I want the output

[GENERAL] Complex query question

2011-09-06 Thread Mike Orr
I have a complex query question whose answer I think would help me to understand subselects and aggregates better. I have a table with four columns of interest: id (int primary key), loc_title (varchar null), loc_value (float null), loc_unit (varchar null) I want the output columns to be: (1) eac

Re: [GENERAL] complex query using postgresql

2008-04-30 Thread Alban Hertroys
On Apr 30, 2008, at 11:50 AM, Pau Marc Munoz Torres wrote: Hi everybody I have de following table where i can perform two different queries: select * from precalc where idr(p1, p4, p6, p7, p9, 'HLA-DR7')>2; where idr is a function used to create indicies Are your indices generated by the

[GENERAL] complex query using postgresql

2008-04-30 Thread Pau Marc Munoz Torres
Hi everybody I have de following table where i can perform two different queries: select * from precalc where idr(p1, p4, p6, p7, p9, 'HLA-DR7')>2; where idr is a function used to create indicies and select * from precalc where p1='S'; Now i would like to perform a query as : select * from

[GENERAL] Complex query optimization

2008-02-01 Thread Yuriy Rusinov
Hello, Colleagues ! I have a table with geographical objects, every object has set of semantic values. Thus we have object-semantic relation one-to-many. Tables structure was objects id_object | id_semantic 1 2 1 3 1 4 ... n n1 n

Re: [GENERAL] Complex query need help with OR condition.

2004-10-26 Thread Jaime Casanova
--- Ken Tozier <[EMAIL PROTECTED]> escribió: > I'm working on a query which works as expected when > I leave out one of > the "OR" tests but when the "OR" is included, I get > hundreds of > duplicate hits from a table that only contains 39 > items. Is there a way > to write the following so th

Re: [GENERAL] Complex query need help with OR condition.

2004-10-24 Thread Ken Tozier
On Oct 25, 2004, at 12:35 AM, Tom Lane wrote: Ken Tozier <[EMAIL PROTECTED]> writes: When I add the OR clause things go haywire: SELECT a.paginator, a.doc_name, (b.time - pm_events.time) as elapsed_time FROM pm_events as a, pm_events as b WHERE a.event_code='pmcd' OR a.event_code='

Re: [GENERAL] Complex query need help with OR condition.

2004-10-24 Thread Tom Lane
Ken Tozier <[EMAIL PROTECTED]> writes: > When I add the OR clause things go haywire: > SELECT a.paginator, a.doc_name, (b.time - pm_events.time) as > elapsed_time FROM pm_events as a, pm_events as b > WHERE a.event_code='pmcd' > OR a.event_code='pmop' > AND b.event_code='pmcl' >

[GENERAL] Complex query need help with OR condition.

2004-10-24 Thread Ken Tozier
I'm working on a query which works as expected when I leave out one of the "OR" tests but when the "OR" is included, I get hundreds of duplicate hits from a table that only contains 39 items. Is there a way to write the following so that the "WHERE" clause tests for two possible conditions? Th