Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
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;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear