求sql语句
id inCome outCome endCome changeDate
1 2 2 0 2002-12-03
1 10 1 0 2002-02-03
1 30 2 0 2002-01-03
2 40 10 0 2002-03-04
2 30 20 0 2002-03-03
----------------------------------------------
要求:
根据id:
结果:
id inCome outCome endCome
1 2 2 0
1 10 1 9 -----为9+0 endCome
1 30 20 19 ===30-20+9 endcome
2 40 10 30
2 30 20 40
-------------------------------------
endcome=isnull(sum(cast(inCome as money)-sum(cast(outcome as money)),0)