PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
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') ;
Copy Clear
Copy Format Clear
<?php $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`"); $gpcrow = mysqli_fetch_assoc($query); // Fetch all $gpcrow = mysqli_fetch_all($result, MYSQLI_ASSOC); print_r($gpcrow); // Free result set mysqli_free_result($result); mysqli_close($con);mysqli_query($con, $sql); // Fetch all mysqli_fetch_all($result, MYSQLI_ASSOC); // Free result set mysqli_free_result($result);
Show:  
Copy Clear