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;
此脚本未返回任何内容。我要做的是从收货和运输中减去同一张桌子上的Amts。有什么建议吗?
答案 0 :(得分:1)
SELECT sum(case when type='receiving' then amt else -amt end)
FROM lineitem WHERE item='test1' AND type IN ('receiving','shipping')