title: SQLZOO Q#14 ORDER BY CASE Issues
body: <p>I am trying to solve question number 14 (<a href="https://sqlzoo.net/wiki/AdventureWorks_hard_questions" rel="nofollow noreferrer">https://sqlzoo.net/wiki/AdventureWorks_hard_questions</a>) in a particular way but I am having some issues with entries not appearing in any range. I just wanted to know if someone could point out out any problems with my approach.</p>
  <p>EDIT: So from what what I have read the &quot;BETWEEN&quot; does not seem to capture decimal values and it is better to use &lt;&gt; operators. I will try this and get back here with my results. My issue as well is that there are no answers to these SQLZoo problems and a number of peoples submissions have varying results for this question.</p>
  <pre><code>SELECT 
      CASE 
          WHEN ListPrice*OrderQty BETWEEN 0 AND 99 THEN '0 - 99'
          WHEN ListPrice*OrderQty BETWEEN 100 AND 999 THEN '100 - 999'
          WHEN ListPrice*OrderQty BETWEEN 1000 AND 9999 THEN '100 - 9999'
          WHEN ListPrice*OrderQty &gt;= 10000 THEN '10000+'
          ELSE 'ERROR'
      END Range,
      COUNT(*) AS '# of Orders',
      SUM(ListPrice*SOD.OrderQty) AS 'Total Value'
  FROM Product P
  JOIN SalesOrderDetail SOD
  ON P.ProductID = SOD.ProductID
  GROUP BY            
  CASE 
      WHEN ListPrice*OrderQty BETWEEN 0 AND 99 THEN '0 - 99'
      WHEN ListPrice*OrderQty BETWEEN 100 AND 999 THEN '100 - 999'
      WHEN ListPrice*OrderQty BETWEEN 1000 AND 9999 THEN '100 - 9999'
      WHEN ListPrice*OrderQty &gt;= 10000 THEN '10000+'
      ELSE 'ERROR'
  END
  </code></pre>