| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Bob Kruger <bkruger(at)mindspring(dot)com> |
| Cc: | pgsql-sql(at)postgreSQL(dot)org |
| Subject: | Re: [SQL] Query Question |
| Date: | 1999-06-16 15:12:16 |
| Message-ID: | 25093.929545936@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Bob Kruger <bkruger(at)mindspring(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Herouth Maoz | 1999-06-16 15:19:54 | Re: [SQL] Query Question |
| Previous Message | Bob Kruger | 1999-06-16 15:01:00 | Query Question |