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 points (`id` int, `attempt_id` int, `group_id` int, `points` int) ; INSERT INTO points (`id`, `attempt_id`, `group_id`, `points`) VALUES (1, 1, 2, 5), (2, 1, 2, 5), (3, 1, 1, 5), (4, 2, 3, 5), (5, 2, 2, 5), (6, 2, 3, 5), (7, 3, 1, 5), (8, 3, 3, 5) ; CREATE TABLE attempts (`id` int, `status` int) ; INSERT INTO attempts (`id`, `status`) VALUES (1, 1), (2, 1), (3, 0) ; CREATE TABLE `groups` (`id` int, `title` varchar(7)) ; INSERT INTO `groups` (`id`, `title`) VALUES (1, 'Group 1'), (2, 'Group 2'), (3, 'Group 3') ;

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

Copy Clear
Copy Format Clear
<?php if ( $result = mysqli_query( $mysqli, "SELECT MIN(g.title) title,SUM(points) FROM points p INNER JOIN `groups` g ON p.group_id = g.id WHERE `attempt_id`IN (SELECT id FROM attempts WHERE status = 1) GROUP BY `group_id`" ) ) { // Fetch all $gpcrow = mysqli_fetch_all($result, MYSQLI_ASSOC); print_r($gpcrow); // Free result set // Free result set mysqli_free_result($result); }
Copy Clear