Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA27223 for ; Wed, 16 Jun 1999 11:13:01 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id LAA25095; Wed, 16 Jun 1999 11:12:16 -0400 (EDT) To: Bob Kruger cc: pgsql-sql@postgreSQL.org Subject: Re: [SQL] Query Question In-reply-to: Your message of Wed, 16 Jun 1999 10:01:00 -0500 <3.0.5.32.19990616100100.007ac9a0@mindspring.com> Date: Wed, 16 Jun 1999 11:12:16 -0400 Message-ID: <25093.929545936@sss.pgh.pa.us> From: Tom Lane Bob Kruger 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