agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Tom Lane <tgl@sss.pgh.pa.us>
To: Bob Kruger <bkruger@mindspring.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Query Question
Date: Wed, 16 Jun 1999 11:12:16 -0400
Message-ID: <25093.929545936@sss.pgh.pa.us> (raw)
In-Reply-To: <3.0.5.32.19990616100100.007ac9a0@mindspring.com>
Bob Kruger <bkruger@mindspring.com> writes:
> I would like to be able to do a query in which I can list all of the
> vehicles and a totalization of the costs, e.g. list one vehicle number, and
> the sum of costs for that vehicle.
I think you want GROUP BY, eg
select veh_no, sum(cost) from table group by veh_no;
sum() and other aggregates apply across a group, not across the whole
table, when you use GROUP BY. Notice you do NOT use DISTINCT ...
GROUP BY takes care of that for you.
regards, tom lane
view thread (15+ messages) latest in thread
Message-ID: <25093.929545936@sss.pgh.pa.us>
Permalink: ../25093.929545936@sss.pgh.pa.us/
Also on: postgresql.org/message-id/25093.929545936@sss.pgh.pa.us
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, bkruger@mindspring.com
Subject: Re: [SQL] Query Question
In-Reply-To: <25093.929545936@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox