A表中有3个字段如下图,要求用一条SQL语句,查出最后的总金额是多少?

其中类型0代表收入,1代表支出.

第1个回答  2011-12-29
select sum(money) from A where Atype='0'
minus
select sum(money) from A where Atype='1'
这样写比较好理解吧,上面查出来是收入的总和,下面是支出的总和,minus是减法函数,执行以下就可以了(oracle)
第2个回答  2011-12-29
select sum(money-2*atype*money) amt from a
最简单了吧,算出你一共有多少流水,再减去两个花去的
第3个回答  2011-12-29
select sum(a.Money) -sum(b.Money) from 表名 a,表名 b where a.Atype=0 and b.Atype=1
不知道对不对哈
第4个回答  2011-12-29
select
sum(money)
from
(select
case
when Atype = '0' then sum(Money)
when Atype = '1' then -1 * sum(Money)
end money
from A
group by Atype
) B
第5个回答  2011-12-29
select sum(Money) from (select case when Atype=0 then Money else 0-Money end as Money from table)本回答被提问者采纳