Re: SUM the result of a subquery. - Mailing list pgsql-sql

From Jayadevan M
Subject Re: SUM the result of a subquery.
Date
Msg-id OF39AE7609.CC04F696-ON65257792.00446E7D-65257792.00448A26@ibsplc.com
Whole thread Raw
In response to SUM the result of a subquery.  (negora <negora@negora.com>)
Responses Re: SUM the result of a subquery.  (negora <negora@negora.com>)
List pgsql-sql
> SELECT SUM (
> (SELECT i.id_item, i.price, SUM (o.quantity), ROUND (SUM 
> (o.quantity) * i.price, 2) AS cost
> FROM orders o
> JOIN items i ON i.id_item = o.id_item
> WHERE o.date_order BETWEEN '2010-01-01' AND '2010-01-31'
> GROUP BY i.id_item, i.price)
> ); 
> 
> No luck. Obviously SUM expects an expression, not a set of rows. Is 
> there a way to perform a sum of the resulting rows?
> 
I don't have a PostgreSQL server to try this right now. But you are 
looking for something like 
SELECT SUM (cost) from (
(SELECT i.id_item, i.price, SUM (o.quantity), ROUND (SUM (o.quantity) * 
i.price, 2) AS cost
FROM orders o
JOIN items i ON i.id_item = o.id_item
WHERE o.date_order BETWEEN '2010-01-01' AND '2010-01-31'
GROUP BY i.id_item, i.price)
) as x

Regards,
Jayadevan





DISCLAIMER: 

"The information in this e-mail and any attachment is intended only for 
the person to whom it is addressed and may contain confidential and/or 
privileged material. If you have received this e-mail in error, kindly 
contact the sender and destroy all copies of the original communication. 
IBS makes no warranty, express or implied, nor guarantees the accuracy, 
adequacy or completeness of the information contained in this email or any 
attachment and is not liable for any errors, defects, omissions, viruses 
or for resultant loss or damage, if any, direct or indirect."







pgsql-sql by date:

Previous
From: negora
Date:
Subject: SUM the result of a subquery.
Next
From: negora
Date:
Subject: Re: SUM the result of a subquery.