Here is my current mysql statement:
SET @rownum := 0;
SELECT school_id,
mb_no AS student_id,
xp,
@rownum := @rownum + 1 AS rank_school_position
FROM users
WHERE school_id IN (
SELECT school_id
FROM users)
ORDER BY xp DESC;
Here is sample table
CREATE TABLE `users` (
`school_id` INT(11) NOT NULL DEFAULT '0',
`mb_no` INT(11) NOT NULL DEFAULT '0',
`xp` INT(10) NOT NULL DEFAULT '0')
and my sample data
INSERT INTO `d_copy` (`school_id`, `mb_no`, `xp`) VALUES
(610, 1, 1190),
(610, 2, 195),
(611, 3, 0),
(610, 4, 35),
(610, 5, 160),
(611, 6, 0),
(610, 7, 175),
(611, 8, 0),
(610, 9, 95),
(610, 10, 4770);
How I can reset back @rownum
to 0
on every SELECT school_id FROM users
executed?
My expected output will be like this