PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE tickets ( id int, agent_id int, status int ); INSERT INTO tickets (id, agent_id, status) VALUES (1, 19, 2), (2, 31, 5), (3, NULL, 1), (4, 37, 2), (5, 61, 3), (6, 40, 4), (7, NULL, 2), (8, 55, 1)
Copy Clear
Copy Format Clear
<?php var_export( $db::table('tickets') ->selectRaw("SUM(status = 1) open") ->selectRaw("SUM(status = 2) pending") ->selectRaw("SUM(agent_id IS NULL) unassigned") ->selectRaw("SUM(status NOT IN (3,4)) unresolved") ->first() );
Show:  
Copy Clear