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

SQLize Online / PHPize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

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

Copy Format Clear
create table account ( id int ); insert into account values (333); create table posts ( accountId int, inbound tinyint ); insert into posts values (333, 1), (333, 0), (333, 0); select count(*) as total, (select count(*) from posts where inbound = 0 and accountid = 333) as inbound, (select count(*) from posts where inbound = 1 and accountid = 333) as outbound from account a join posts p on p.accountId = a.id where a.id = 333 group by a.id; with counts as ( select count(*) as total, count(nullif(inbound, 0)) as inbound, count(nullif(inbound, 1)) as outbound from posts where accountid = 333 ) select * , round((outbound / total) * 100) outboundPercentage from counts;

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

Copy Clear