user1100756
user1100756

Reputation: 66

Advice with MySql Formula

select v1.Value1 - v2.Value2 
from (Select Amt as Value1 
      from lineitem 
      WHERE item ='test1' and type='receiving') 
      as v1 CROSS JOIN (Select Amt as Value2 
                        from lineitem 
                        WHERE item ='test1' and type='shipping') 
                        as v2;

This script isn't returning anything. What I'm trying to do is subtract the Amts on the same table from receiving and shipping. Any advice?

Upvotes: 2

Views: 61

Answers (1)

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143229

SELECT sum(case when type='receiving' then amt else -amt end)
    FROM lineitem WHERE item='test1' AND type IN ('receiving','shipping')

Upvotes: 1

Related Questions