1
set @total_balance=0;
select total_balance=if(a.transaction_type='+c') then total_balance=total_balance+a.tran_amount
else if(a.transaction_type='-p'or '-r') then total_balance=total_balance-a.tran_amount
END
from lib_user_account a
where employee_Id='1004';
4

2 に答える 2

2
SUM(IF(a.transaction_type='+c', a.tran_amount, -a.tran_amount))
于 2013-04-03T04:22:08.543 に答える