CREATE TABLE IF NOT EXISTS tablename (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`type` int(11) NOT NULL,
`sum` varchar(50) NOT NULL default '0',
PRIMARY KEY ( `id` )
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
INSERT INTO tablename (`type`, `sum`) VALUES
(0, 50), (1, 10), (1, 30), (1, 120), (0, 75), (0, 150);
select
sum(if(`type` = 0, `sum`, 0)) `income`,
sum(if(`type` = 1, `sum`, 0)) `outcome`,
sum(if(`type` = 0, `sum`, -`sum`)) `balance`
from tablename;