PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE office_layout ( floor INT, office INT ); INSERT INTO office_layout (floor, office) VALUES (1, 4), (2, 4), (3, 3), (4, 3), (1, 5), (2, 5), (3, 4), (4, 4), (1, 6), (2, 6), (3, 5), (4, 5), (2, 7), (3, 6), (4, 6), (3, 7), (4, 7);
Copy Clear
Copy Format Clear
<?php $sql = <<<SQL SELECT floor, office, ROW_NUMBER() OVER (PARTITION BY floor ORDER BY office) AS sort_count FROM office_layout ORDER BY floor, office; SQL; $result = $mysqli->query($sql)->fetch_all(MYSQLI_ASSOC); var_export($result);
Show:  
Copy Clear