PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE Post ( id int, published enum('true','false') ); INSERT INTO Post (id, published) VALUES (1, 'true'), (2, 'true'), (3, 'false'), (4, 'true'), (5, 'true'), (6, 'false'), (7, 'true'); CREATE TABLE Pages ( id int, published enum('true','false') ); INSERT INTO Pages (id, published) VALUES (1, 'false'), (2, 'true'), (3, 'true'); CREATE TABLE Products ( id int, published enum('true','false') ); SELECT * FROM Post
Copy Clear
Copy Format Clear
<?php var_export( $db->selectRaw( sprintf( '(%s) posts, (%s) pages, (%s) products', $db->table('Post')->whereRaw('published = true')->selectRaw('COUNT(*)')->toSql(), $db->table('Pages')->whereRaw('published = true')->selectRaw('COUNT(*)')->toSql(), $db->table('Products')->whereRaw('published = true')->selectRaw('COUNT(*)')->toSql() ) ) ->get() ->toArray() );
Show:  
Copy Clear