title: mySQL - User's total points count in different ranges with Dynamic Ranges
body: <p>When i am trying to execute following query it gives me proper result but i want to show range dynamically</p>
  
  <pre><code> SELECT
   CASE
   WHEN points &lt;= 25 THEN '0-25'
   WHEN points BETWEEN 25 AND 50 THEN '25-50'
   WHEN points BETWEEN 50 AND 75 THEN '50-75'
   WHEN points BETWEEN 75 AND 100 THEN '75-100'
   ELSE '&gt; 100'
   END AS `Range`
   ,COUNT(*) AS `Count`
   ,CASE
   WHEN points &lt;= 25 THEN 1
   WHEN points BETWEEN 25 AND 50 THEN 2
   WHEN points BETWEEN 50 AND 75 THEN 3
   WHEN points BETWEEN 75 AND 100 THEN 4
   ELSE 5
   END AS `Sort`
   FROM (
   SELECT user_id, SUM(points) as points
   FROM tbl
   GROUP BY user_id
   ) AS summary
   GROUP BY `Range`, `Sort`
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>+--------+-------+
  | Range  | Count |
  +--------+-------+
  | 0-20   | 01    |
  | 25-50  | 02    |
  | 50-75  | 01    |
  | 75-100 | 04    |
  | &gt; 100  | 00    |
  +--------+-------+
  </code></pre>
  
  <p>I am getting 100 value from following value from another table </p>
  
  <p>SELECT MIN(points) FROM tbl1 where 1 LIMIT 0,1</p>
  
  <p>If min value will be 100 then output will be:</p>
  
  <p><strong>Output</strong></p>
  
  <pre><code>+--------+-------+
  | Range  | Count |
  +--------+-------+
  | 0-20   | 01    |
  | 25-50  | 02    |
  | 50-75  | 01    |
  | 75-100 | 04    |
  | &gt; 100  | 00    |
  +--------+-------+
  </code></pre>
  
  <p>If min value will be 500 then output will be:</p>
  
  <p><strong>Output</strong></p>
  
  <pre><code>+---------+-------+
  | Range   | Count |
  +---------+-------+
  | 0-100   | 01    |
  | 100-200 | 02    |
  | 300-400 | 01    |
  | 400-500 | 04    |
  | &gt; 500   | 00    |
  +---------+-------+
  </code></pre>
  
  <p>Thanks in advance</p>