March 11, 2004 at 5:13 am
HI!
I want to get positive and negative sums of one product, how can i do that?
My query:
select goods,sum(quantity) table group by goods
order by sum(quantity)
so i want to get gruped and sumed goods but i want to get negative quantities sumed only with negative and positive with positive
March 11, 2004 at 5:42 am
SELECT Goods, SUM(Quantity) Both, SUM(CASE WHEN Quantity > 0 THEN Quantity END) Pos, SUM(CASE WHEN Quantity < 0 THEN Quantity END) Neg
FROM Table
GROUP BY Goods
ORDER BY Goods, Both
--Jonathan
March 11, 2004 at 5:53 am
Amazing what all can happen while typing. Fortunately I hit F5 before answering
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
March 11, 2004 at 5:56 am
many thanks
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply