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/