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

PHPize Online / SQLize 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 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);

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

Copy Clear
Copy Format Clear
<?php $sql = <<<SQL SELECT floor, office, ROW_NUMBER() OVER (PARTITION BY floor ORDER BY office) rank FROM office_layout ORDER BY rank, floor, office; SQL; $result = $mysqli->query($sql)->fetch_all(MYSQLI_ASSOC); var_export($result);
Copy Clear