Re: [GENERAL] I need help creating a query

2006-07-14 Thread Sergio Duran
e -From: "Sergio Duran" <[EMAIL PROTECTED]>To: <pgsql-general@postgresql.org >Sent: Thursday, July 13, 2006 9:20 PMSubject: [GENERAL] I need help creating a query> Hello,>> I need a little help creating a query, I have two tables, worker and> position, for simplicity

Re: [GENERAL] I need help creating a query

2006-07-14 Thread Marcin Mank
- Original Message - From: "Sergio Duran" <[EMAIL PROTECTED]> To: Sent: Thursday, July 13, 2006 9:20 PM Subject: [GENERAL] I need help creating a query > Hello, > > I need a little help creating a query, I have two tables, worker and > position, for simplic

Re: [GENERAL] I need help creating a query

2006-07-14 Thread Sergio Duran
This is what I did, I used plpgsql,create or replace function first_accum(anyelement, anyelement) returns anyelement as $$BEGIN   IF $1 IS NOT NULL THEN return $1;   ELSE return $2;   END IF; END' language plpgsql; then I created the aggregateCREATE AGGREGATE first(sfunc = first_accum, basetype = a

Re: [GENERAL] I need help creating a query

2006-07-14 Thread Richard Broersma Jr
> create table worker( > name varchar(50), > position varchar(50), > startdate date, > salary numeric(9,2)); > insert into worker values ('Jon', 'boss', '2001-01-1', 1000.00); > insert into worker values ('Peter', 'cleaning', '2002-01-01', 100.00); > insert into worker values ('Pet

Re: [GENERAL] I need help creating a query

2006-07-14 Thread Q
On 15/07/2006, at 2:07 AM, Sergio Duran wrote:How about if we make it simpler, only 1 tablecreate table worker(    name varchar(50),    position varchar(50),    startdate date,    salary numeric(9,2));insert into worker values ('Jon', 'boss', '2001-01-1', 1000.00);insert into worker values ('Peter'

Re: [GENERAL] I need help creating a query

2006-07-14 Thread Sergio Duran
How about if we make it simpler, only 1 tablecreate table worker(    name varchar(50),    position varchar(50),    startdate date,    salary numeric(9,2));insert into worker values ('Jon', 'boss', '2001-01-1', 1000.00);insert into worker values ('Peter', 'cleaning', '2002-01-01', 100.00);insert in

Re: [GENERAL] I need help creating a query

2006-07-14 Thread Sergio Duran
Nice, Richard, but you use max(startdate), how about the salary? i cant use max(salary) how about if he got a pay cut?My current solution is to write the nested query on the field list, like SELECT worker.*,   (select salary FROM position where worker_id=worker.worker_id and fecha<='2006

Re: [GENERAL] I need help creating a query

2006-07-13 Thread Richard Broersma Jr
> > worker: worker_id, name > position: position_id, worker_id, position, startdate, salary > > If I perfom a query joining both tables, I can obtain all the workers and > the positions the've had. > > SELECT name, startdate, position, salary FROM worker JOIN position > USING(worker_id); > wo

Re: [GENERAL] I need help creating a query

2006-07-13 Thread Dann Corbit
] I need help creating a query   Hello, I need a little help creating a query, I have two tables, worker and position, for simplicity sake worker only has its ID and its name, position has the ID of the worker, the name of his position, a date, and his salary/ worker:   worker_id, name

[GENERAL] I need help creating a query

2006-07-13 Thread Sergio Duran
Hello,I need a little help creating a query, I have two tables, worker and position, for simplicity sake worker only has its ID and its name, position has the ID of the worker, the name of his position, a date, and his salary/ worker:   worker_id, nameposition: position_id, worker_id, position, sta