Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] Aggregates and Joins

From: Bob Dusek <bobd(at)palaver(dot)net>
To: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
Cc: PostgreSQL General <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] Aggregates and Joins
Date: 1998-11-25 00:14:30
Message-ID: Pine.LNX.3.96.981124190942.24677E-100000@toots.palaver.net (view raw or flat)
Thread:
Lists: pgsql-general
Hey!!!

Thanks a lot.  That is just what I needed.  

here's the query I used:

select sum(price), trans_id from second_table group by trans_id;

I had to include the "trans_id" in the target list to use it for grouping.
I've never been able to mix single fields and aggregates before (of
course, I've never used the "group" syntax before either).  

Thanks a lot. 

Bob


On Tue, 24 Nov 1998, Oliver Elphick wrote:

> Date: Tue, 24 Nov 1998 23:30:19 +0000
> From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
> To: Bob Dusek <bobd(at)palaver(dot)net>
> Cc: PostgreSQL General <pgsql-general(at)postgreSQL(dot)org>
> Subject: Re: [GENERAL] Aggregates and Joins 
> 
> Bob Dusek wrote:
> ...
>   >table second_table (
>   >
>   >   this_id int,
>   >   price money,
>   >   ...
>   >   ..
>   >   trans_id int, -- my primary key association
>   >
>   >);
> ...
>   >What I need to do is to obtain the sum of the field 'price' from
>   >second_table for every distinct 'trans_id' (all of which can be found in
>   >first_table). ... Is there a quicker way to do this?  Is it possible to
>   >use the aggregate functions and have more than one row returned?  
> 
> select sum(price) from second_table group by trans_id;
> 
> -- 
> Oliver Elphick                                Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
> Isle of Wight                              http://www.lfix.co.uk/oliver
>                PGP key from public servers; key ID 32B8FAA1
>                  ========================================
>      "Jesus saith unto him, I am the way, the truth, and the
>       life; no man cometh unto the Father, but by me."      
>                                          John 14:6 
> 
> 
> 


In response to

pgsql-general by date

Next:From: PAX!Date: 1998-11-25 00:44:54
Subject: Re: [GENERAL] Aggregates and Joins
Previous:From: Oliver ElphickDate: 1998-11-24 23:30:19
Subject: Re: [GENERAL] Aggregates and Joins

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group