Re: [SQL] Query Question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] Query Question
Дата
Msg-id 25093.929545936@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Query Question  (Bob Kruger <bkruger@mindspring.com>)
Список pgsql-sql
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


В списке pgsql-sql по дате отправления:

Предыдущее
От: Bob Kruger
Дата:
Сообщение: Query Question
Следующее
От: Herouth Maoz
Дата:
Сообщение: Re: [SQL] Query Question