Re: [SQL] SQL problem...

2007-06-28 Thread Rodrigo De León
On Jun 28, 1:43 pm, "Bauhaus" <[EMAIL PROTECTED]> wrote: > I have the following table Price: > > FuelID PriceDate Price > LPG1/05/2007 0,2 > LPG13/05/2007 0,21 > SPS 2/05/2007 1,1 > SPS 15/05/2007 1,08 > > And I have to make the following query: > > FuelID PriceDate_from Price

Re: [SQL] sql problem with join

2006-11-17 Thread Aaron Bono
On 11/15/06, Luca Ferrari <[EMAIL PROTECTED]> wrote: On Wednesday 15 November 2006 16:20 your cat, walking on the keyboard, wrote: > May be you could show the results you are getting and then make up some > results that you would really like to get. I am not entirely clear what > you are trying

Re: [SQL] sql problem with join

2006-11-15 Thread Luca Ferrari
On Wednesday 15 November 2006 16:20 your cat, walking on the keyboard, wrote: > May be you could show the results you are getting and then make up some > results that you would really like to get. I am not entirely clear what > you are trying to achieve. Lastly I found the solution, for the mome

Re: [SQL] sql problem with join

2006-11-15 Thread Richard Broersma Jr
> Hi all, > I've got a problem tryng to define a view with a few joins, I'll appreciate > if > someone could drive me in the definition of such query. > I've got a table roleSkill that contains a row for each skill belonging to a > defined role and with the desired competence level for such ski

[SQL] sql problem with join

2006-11-15 Thread Luca Ferrari
Hi all, I've got a problem tryng to define a view with a few joins, I'll appreciate if someone could drive me in the definition of such query. I've got a table roleSkill that contains a row for each skill belonging to a defined role and with the desired competence level for such skill in such r

Re: [SQL] sql problem

2004-11-05 Thread Achilleus Mantzios
O Flavio Fonseca έγραψε στις Nov 5, 2004 : > Hi, > > I am having a problem with a system I developed using php with postgres. > > Take a look at this: > > Welcome to psql 7.3.2, the PostgreSQL interactive terminal. > NetAdmin=# delete from operador where oplogin = 'ff'; > ERROR: fk_historico

[SQL] sql problem

2004-11-05 Thread Flavio Fonseca
Hi, I am having a problem with a system I developed using php with postgres. Take a look at this: Welcome to psql 7.3.2, the PostgreSQL interactive terminal. NetAdmin=# delete from operador where oplogin = 'ff'; ERROR: fk_historicosessao_operador referential integrity violation - key in oper

Re: [SQL] SQL problem: bank account

2003-06-03 Thread Erik G. Burrows
This is the solution I was looking for! 20 seconds to compile the whole list. Thanks everyone for your help, I very much appreciate it. Even though this is kind of 'hackey' being that it's non-standard SQL, it keeps the database from having to to 40,000 selects, as would have to do with any corre

Re: [SQL] SQL problem: bank account

2003-06-03 Thread Jonathan Gardner
On Monday 02 June 2003 00:49, listrec wrote: > How about: > > select max(transaction_id) from bank_account group by customer_id > And if you want the rest of the data in the rows: SELECT b.* FROM bank_account b JOIN ( SELECT max(transaction_id) AS transaction_id FROM bank_account

Re: [SQL] SQL problem: bank account

2003-06-03 Thread Jonathan Gardner
On Monday 02 June 2003 00:49, listrec wrote: > How about: > > select max(transaction_id) from bank_account group by customer_id > And if you want the rest of the data in the rows: SELECT b.* FROM bank_account b JOIN ( SELECT max(transaction_id) AS transaction_id FROM bank_account

Re: [SQL] SQL problem: bank account

2003-06-03 Thread Dmitry Tkach
I am afraid, this looks even uglier then your second solution, but should work, and be quicker... -- You need this to avoid having to rescan the whole table for each customerid every time and resort the results create index customer_txstamp_idx on bank_account (customer_id, ts); select ba.* fro

Re: [SQL] SQL problem: bank account

2003-06-03 Thread Tom Lane
"Erik G. Burrows" <[EMAIL PROTECTED]> writes: > I need to get the most recent transaction for each customer. I need only > the transaction ID, but the entire row would be best. If you don't mind a not-standard-SQL solution, the SELECT DISTINCT ON construct is designed for this sort of thing. See

Re: [SQL] SQL problem: bank account

2003-06-02 Thread listrec
How about: select max(transaction_id) from bank_account group by customer_id Should work... Detlef -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Auftrag von Erik G. Burrows Gesendet: Montag, 2. Juni 2003 07:30 An: [EMAIL PROTECTED] Betreff: [SQL] SQL

Re: [SQL] SQL problem: bank account

2003-06-02 Thread Sean Chittenden
> It seems to me this is a simple problem, but the solution eludes me. > > I have a table: > > bank_account ( > transaction_id int not null serial, > customer_id int not null references customer(id), > ts timestamp not null default now(), > amount float not null, > balance float not null

Re: [SQL] SQL problem: bank account

2003-06-02 Thread Andrew J. Kopciuch
> I need to get the most recent transaction for each customer. I need only > the transaction ID, but the entire row would be best. > Why don't you alter the customer table to hold the transaction ID of the most recent transaction? Some questions though: Do you vacuum the database regularly?

[SQL] SQL problem: bank account

2003-06-02 Thread Erik G. Burrows
It seems to me this is a simple problem, but the solution eludes me. I have a table: bank_account ( transaction_id int not null serial, customer_id int not null references customer(id), ts timestamp not null default now(), amount float not null, balance float not null, primary key(tra

Re: [SQL] SQL problem with aggregate functions.

2002-07-22 Thread Hubert depesz Lubaczewski
On Tue, Jul 09, 2002 at 10:36:17AM +0200, David BOURIAUD wrote: > Field group | count of D | count of R | count of X. if you want this that way, i suggest using subselects. like: select distinct field_group, (select count(*) from table t2 where t2.field_group = t1.field_group and

Re: [SQL] SQL problem with aggregate functions.

2002-07-12 Thread Jean-Luc Lachance
What is wrong with: select field_group, sum( case when f1 = 'D' then cnt else 0 end) as D_COUNT, sum( case when f1 = 'R' then cnt else 0 end) as R_COUNT, sum( case when f1 = 'X' then cnt else 0 end) as X_COUNT from (select field_group, f1, count (*) as cnt from tab group by field_group, f1) a

Re: [SQL] SQL problem with aggregate functions.

2002-07-11 Thread Loyd Goodbar
I would suggest something like select sum(case when f1 = 'D' then 1 else 0 end) as D_COUNT, sum(case when f1 = 'R' then 1 else 0 end) as R_COUNT, sum(case when f1 = 'X' then 1 else 0 end) as X_COUNT from tab where f1 in ('D','R','X') Not sure what the "field group" represents. HTH, Loyd On Thu

Re: [SQL] SQL problem with aggregate functions.

2002-07-11 Thread Christoph Haller
> > I've got a table in which there is a field that can have one amongst 3 > possible values : D, R, X. Is it possible to get in one query the count of > this different values.Please, note that I don't want to have a querry like > this : > "select count (*) from tab group by f1;", cause i want

[SQL] SQL problem with aggregate functions.

2002-07-09 Thread David BOURIAUD
Hi the list ! I've got a table in which there is a field that can have one amongst 3 possible values : D, R, X. Is it possible to get in one query the count of this different values.Please, note that I don't want to have a querry like this : "select count (*) from tab group by f1;", cause i wan

[SQL] SQL problem

2001-03-12 Thread Salvador Mainé
Hello: I have a table with pluviometrical data meteo (rain float, day date) I want to select the the day of maximum value for each year.It should be something like : select max(rain),day from meteo group by date_part('year', day); but it obiously doesn't work. I thought of doing it with agg