Re: simple query question

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "John K(dot) Herreshoff" <jkherr(at)power-net(dot)net>
Cc: Akbar <tuxer(at)myrealbox(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: simple query question
Date: 2005-02-07 16:26:32
Message-ID: 20050207162632.GA34287@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Colin McGuigan 2005-02-07 18:45:12 Re: Percent of update completed
Previous Message Tom Lane 2005-02-07 16:00:00 Re: Percent of update completed