Geting negative and positive value

  • 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

  • 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

  • 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]

  • many thanks

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply