PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE stores ( id int, store_id int, country varchar(100) ); INSERT INTO stores (id, store_id, country) VALUES (1, 1, 'Netherlands'), (2, 2, 'Netherlands'), (3, 1, 'Canada'), (4, 2, 'Canada'), (5, 3, 'Netherlands'), (6, 1, 'Sweden'), (7, 2, 'Sweden'), (8, 1, 'Australia');
Copy Clear
Copy Format Clear
<?php var_export( $db::table('stores') ->selectRaw('SUM(store_id = 1) one') ->selectRaw('SUM(store_id = 2) two') ->selectRaw('SUM(store_id = 3) three') ->selectRaw('COUNT(1) total') ->selectRaw("SUM(country = 'Netherlands') dutch") ->selectRaw("SUM(country = 'Sweden') swedish") ->first() );
Show:  
Copy Clear