pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Aggregates and joined tables...
3+ messages / 2 participants
[nested] [flat]

* Aggregates and joined tables...
@ 1970-01-01 00:00  omid omoomi <oomoomi@hotmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: omid omoomi @ 1970-01-01 00:00 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; +Cc: pgsql-sql

Hi all,
I have a problem using aggregate function SUM() ...
The platform is PostgreSQL 6.5.2 on i386-unknown-freebsd3.2, compiled by gcc 
2.7.2.1 .
The story is that I need to join two tables with an aggregate function.
Here is a sample model :

Table A consist of ( fa1 , fa2 )
Table B consist of ( fb1 , fb2 )
Table C consist of ( fc1 , fc2 ,fc3 )

I want to write a query which looks like this :

select fa1 - sum(fc3)
from A,B,C
where fa1=fb1 and fb2=fc2
group by fa1 ;

unfortunately I get this in result:
ERROR:  Illegal use of aggregates or non-group column in target list



Any idea ?
How can I have my result with only one SQL statement ?

Thanks in advance
Omid Omoomi
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Aggregates and joined tables...
@ 1970-01-01 00:00  omid omoomi <oomoomi@hotmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: omid omoomi @ 1970-01-01 00:00 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; +Cc: tgl@sss.pgh.pa.us; pgsql-sql

Hello,
I have upgraded my DB to 7.0.3, but there is still the problem. I think that 
it may be a bug.
Joining 3 tables was not possible...
It says "fa1 should be in aggregate too" !

While joining 2 tables gives wrong results ...
ie, if the results should be like this:
fa1           sum
-----       -------
ali           100
omid          200
shaya          50

then I get this:
fa1           sum
-----       -------
ali           350
omid          350
shaya         350

Any more idea ?
Omid Omoomi


>>The platform is PostgreSQL 6.5.2 on i386-unknown-freebsd3.2, compiled by 
>>gcc 2.7.2.1 .

>>The story is that I need to join two tables with an aggregate function.
>>Here is a sample model :

>>Table A consist of ( fa1 , fa2 )
>>Table B consist of ( fb1 , fb2 )
>>Table C consist of ( fc1 , fc2 ,fc3 )

>>I want to write a query which looks like this :
>>select fa1 - sum(fc3)
>>from A,B,C
>>where fa1=fb1 and fb2=fc2
>>group by fa1 ;
>>unfortunately I get this in result:
>>ERROR:  Illegal use of aggregates or non-group column in target list

>Works fine in current sources.  Try upgrading to something newer than
6.5.2 ...




_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Aggregates and joined tables...
@ 2001-02-05 04:06  Tom Lane <tgl@sss.pgh.pa.us>
  parent: omid omoomi <oomoomi@hotmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2001-02-05 04:06 UTC (permalink / raw)
  To: omid omoomi <oomoomi@hotmail.com>; +Cc: pgsql-general@postgresql.org; pgsql-sql

"omid omoomi" <oomoomi@hotmail.com> writes:
> The platform is PostgreSQL 6.5.2 on i386-unknown-freebsd3.2, compiled by gcc 
> 2.7.2.1 .

> I want to write a query which looks like this :
> select fa1 - sum(fc3)
> from A,B,C
> where fa1=fb1 and fb2=fc2
> group by fa1 ;
> unfortunately I get this in result:
> ERROR:  Illegal use of aggregates or non-group column in target list

Works fine in current sources.  Try upgrading to something newer than
6.5.2 ...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-02-05 04:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1970-01-01 00:00 Re: Aggregates and joined tables... omid omoomi <oomoomi@hotmail.com>
1970-01-01 00:00 Aggregates and joined tables... omid omoomi <oomoomi@hotmail.com>
2001-02-05 04:06 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox