Re: [GENERAL] Aggregates and Joins

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: [GENERAL] Aggregates and Joins
Дата
Msg-id 199811242330.XAA01978@linda.lfix.co.uk
обсуждение исходный текст
Ответ на Aggregates and Joins  (Bob Dusek <bobd@palaver.net>)
Ответы Re: [GENERAL] Aggregates and Joins  (Bob Dusek <bobd@palaver.net>)
Список pgsql-general
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.Elphick@lfix.co.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



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

Предыдущее
От: Bob Dusek
Дата:
Сообщение: Aggregates and Joins
Следующее
От: Bob Dusek
Дата:
Сообщение: Re: [GENERAL] Aggregates and Joins