Re: simple query question

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: simple query question
Дата
Msg-id 20050207162632.GA34287@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: simple query question  ("John K. Herreshoff" <jkherr@power-net.net>)
Список pgsql-novice
On Mon, Feb 07, 2005 at 06:17:47AM -0500, John K. Herreshoff wrote:
>
> Try SELECT name, sum(sum) as total_sum, buying_price, sale_price
> FROM view_stok_table_total
> GROUP BY name, buying_price, sale_price
> ORDER BY buying_price, sale_price;

To calculate the total sum for each name, you need to use "GROUP BY name",
not "GROUP BY name, buying_price, sale_price".  For the sample data the
above query gives the following result, which is not what was requested:

  name  | total_sum | buying_price | sale_price
--------+-----------+--------------+------------
 mentos |         5 |          100 |        120
 mentos |         8 |          110 |        140
 durex  |         9 |          200 |        210
 queen  |        10 |          400 |        450
(4 rows)

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Percent of update completed
Следующее
От: Colin McGuigan
Дата:
Сообщение: Re: Percent of update completed