title: Mysql Reset variable after execute every row
body: <p>Here is my current mysql statement:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>Here is sample table</p>
  
  <pre><code>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')
  </code></pre>
  
  <p>and my sample data</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>How I can reset back <code>@rownum</code> to <code>0</code> on every <code>SELECT school_id FROM users</code> executed?</p>
  
  <p>My expected output will be like this</p>
  
  <p><img src="https://i.stack.imgur.com/6KSVf.png" alt="enter image description here"></p>