[SQL] Displaying first, last, count columns

2006-06-21 Thread Worky Workerson
I'm having a bit of a brain freeze and can't seem to come up with decent SQL for the following problem: I have a table "t" of the form "time_occurred TIMESTAMP, prog_data VARCHAR" and would like to create a query that outputs something of the form "first_seen, last_seen, count, prog_data". I hav

Re: [SQL] Displaying first, last, count columns

2006-06-21 Thread Aaron Bono
I would suggest:selectmax(time_occurred) AS last_seen,min(time_occurred) AS first_seen,count(*),prog_datafrom tgroup by prog_dataI would also suggest you use inner joins rather than put all your tables in the from and join in the where clause.  It is much easier to read and understand what you are

Re: [SQL] Displaying first, last, count columns

2006-06-21 Thread Frank Bax
At 10:55 AM 6/21/06, Worky Workerson wrote: I'm having a bit of a brain freeze and can't seem to come up with decent SQL for the following problem: I have a table "t" of the form "time_occurred TIMESTAMP, prog_data VARCHAR" and would like to create a query that outputs something of the form "fi

[SQL] How to get a result in one row

2006-06-21 Thread virgi
Hi! I'm using PostgreSQL 7.4.7. table_c id | nick +-- 1 | T 2 | S 3 | G 4 | A 5 | D ... table_m id | c --+ 22192 | 4 15041 | 3 21764 | 5 22192 | 1 15041 | 4 15041 | 2 ... where table_m.c is a foreign key on table_c.id SELECT t

Re: [SQL] keeping last 30 entries of a log table

2006-06-21 Thread Jeff Frost
On Wed, 21 Jun 2006, Ben K. wrote: Just for the sake of alternatives - create sequence cy30 maxvalue 30 cycle; insert into log values(select generate_series(1,30), 'dummy'); INSERT 0 30 update log set des='' where account_id=(select nextval('cy30')); UPDATE 1 There are details to consid

Re: [SQL] How to get a result in one row

2006-06-21 Thread Frank Bax
At 11:06 AM 6/21/06, [EMAIL PROTECTED] wrote: returns: id | nick --+-- 22192 | A 22192 | T (2 rows) I'd like to get the result in only one row: id | nick --+-- 22192 | A,T This question is in the archives (probably more than once). The answer is... Read the online docs

Re: [SQL] How to get a result in one row

2006-06-21 Thread Richard Broersma Jr
> >I'd like to get the result in only one row: > >id | nick > >--+-- > >22192 | A,T > This question is in the archives (probably more than once). The answer > is...> > Read the online docs about aggregate functions. There is an example that > does (almost) exactly what you are aski

Re: [SQL] How to get a result in one row

2006-06-21 Thread Frank Bax
At 02:24 PM 6/21/06, Richard Broersma Jr wrote: > >I'd like to get the result in only one row: > >id | nick > >--+-- > >22192 | A,T > This question is in the archives (probably more than once). The answer is...> > Read the online docs about aggregate functions. There is an exampl

[SQL] join on next row

2006-06-21 Thread Sim Zacks
I am having brain freeze right now and was hoping someone could help me with a (fairly) simple query. I need to join on the next row in a similar table with specific criteria. I have a table with events per employee. I need to have a query that gives per employee each event and the event after

[SQL] Date ranges + DOW select question

2006-06-21 Thread joseppi c
Hi, I have a table which contains starttime, endtime and DOW; i.e. a weekly list of times for when a process must be started and ended. TABLE: cronTimes FIELDS: starttime, endtime, dayOfWeek I have another table which contains date ranges. TABLE: dateRanges FIELDS: dateStart, dateEnd I need to

[SQL] Doubt in stored procedure

2006-06-21 Thread satheesh Gnanasekaran
hi,      iam a novice in postgresql. i want to insert a values  to a table using stored procedure. plz mail me  the sample codes and examples. thanks in advance       with regards, Sathaa

Re: [SQL] keeping last 30 entries of a log table

2006-06-21 Thread Ben K.
I need to write a function which inserts a log entry in a log table and only keeps the last 30 records. I was thinking of using a subquery similar to the following: insert into log (account_id, message) values (1, 'this is a test); delete from log where account_id = 1 and id not in ( select id

Re: [SQL] join on next row

2006-06-21 Thread Justin Lintz
what about putting a limit of 1 on your select statement, so you will just get the first event greater then the initial date for the employee?On 6/18/06, Sim Zacks <[EMAIL PROTECTED]> wrote:I am having brain freeze right now and was hoping someone could help me with a (fairly) simple query.I need