title: Using SUM and CASE Functions to get a row of sums
body: <p>I want to create a output adding up all the integers associated with each variable that fits with a certain range. So one column is the ranges (0-99,100-199,etc.), second column has the total number of variables, and the third column will be the summation. </p>
  
  <p>I've created the format for creating the first two columns, and for understanding purposes my goal is just to recreate the same table with the second and third column.</p>
  
  <p>The Ttable contains a list of items each assigned a value. </p>
  
  <pre><code>SELECT Ttable.SUM AS TotalTime,
          COUNT(*) AS Number
  
  FROM 
      (SELECT 
      SUM(CASE WHEN count BETWEEN 0 AND 99 THEN [Value] ELSE 0 END) AS SUM FROM Ttable)
      (SELECT
      SUM(CASE WHEN count BETWEEN 100 AND 199 THEN [Value] ELSE 0 END) AS SUM FROM Ttable)
      (SELECT
      SUM(CASE WHEN count BETWEEN 200 AND 300 THEN [Value] ELSE 0 END) AS SUM FROM Ttable)
      Ttable
  GROUP BY Ttable.SUM
  ORDER BY Ttable.SUM;
  </code></pre>
  
  <p>Code returns columns one and two</p>
  
  <pre><code>SELECT  Ttable.RANGE AS FileRange,
          COUNT(*) AS Number
  FROM (
      SELECT 
      CASE
          WHEN count BETWEEN 0 AND 99 THEN '0 - 99'
          WHEN count BETWEEN 100 AND 199 THEN '100 - 199'
          WHEN count BETWEEN 200 AND 300 THEN '200 - 299'
          ELSE '300-399' END AS RANGE FROM table)
      Ttable
  GROUP BY Ttable.RANGE
  ORDER BY Ttable.RANGE;
  </code></pre>
  
  <p>I expect the code to return columns two and three of</p>
  
  <pre><code>FileRange         Number        SumValues
   0 - 99            600            8000
  100 - 199          400            5600
  200 - 300          200            3000
  </code></pre>
  
  <p>but I'm getting a "SQL command not properly ended"</p>