title: Sub-Query with group by and Case Statement
body: <p>I have two tables , one is <strong>Country</strong> table and another one is <strong>Threshold</strong> Table.</p>
  <p><strong>Country</strong> table has columns and data like this :<p>
  <kbd><strong><code>ID        </code></strong></kbd><kbd><strong><code>Country   </code></strong></kbd><kbd><strong><code>Count     </code></strong></kbd><kbd><strong><code>Year      </code></strong></kbd><br/>
  <kbd><code>00001     </code></kbd><kbd><code>India     </code></kbd><kbd><code>200       </code></kbd><kbd><code>2011      </code></kbd><br>
  <kbd><code>00001     </code></kbd><kbd><code>India     </code></kbd><kbd><code>400       </code></kbd><kbd><code>2013      </code></kbd><br>
  <kbd><code>00001     </code></kbd><kbd><code>Japan     </code></kbd><kbd><code>1000      </code></kbd><kbd><code>2011      </code></kbd><br>
  <kbd><code>00001     </code></kbd><kbd><code>Japan     </code></kbd><kbd><code>550       </code></kbd><kbd><code>2013      </code></kbd><br>
  <kbd><code>00001     </code></kbd><kbd><code>China     </code></kbd><kbd><code>400       </code></kbd><kbd><code>2011      </code></kbd><br></p>
  <p>And the <strong>Threshold</strong> table has data like this :<p>
  <kbd><strong><code>ID            </code></strong></kbd><kbd><strong><code>Low Value     </code></strong></kbd><kbd><strong><code>High Value     </code></strong></kbd><br/>
  <kbd><code>00001         </code></kbd><kbd><code>500           </code></kbd><kbd><code>1000           </code></kbd><br/></p>
  <p>That means if the <code>Count &gt;= 500</code> then <strong>Low</strong> , if the <code>Count &gt; 500 and &lt; 1000</code> the <strong>Medium</strong> and if <code>Count &gt;= 1000</code> then <strong>High</strong>.</p>
  <p>I want a result like this :<p>
  <kbd><strong><code>Country   </code></strong></kbd><kbd><strong><code>Count     </code></strong></kbd><kbd><strong><code>Threshold      </code></strong></kbd><kbd><strong><code>Low Value  </code></strong></kbd><kbd><strong><code>High Value   </code></strong></kbd><br/>
  <kbd><code>India     </code></kbd><kbd><code>600       </code></kbd><kbd><code>Medium         </code></kbd><kbd><code>500        </code></kbd><kbd><code>1000         </code></kbd><br>
  <kbd><code>Japan     </code></kbd><kbd><code>1550      </code></kbd><kbd><code>High           </code></kbd><kbd><code>500        </code></kbd><kbd><code>1000         </code></kbd><br>
  <kbd><code>China     </code></kbd><kbd><code>400       </code></kbd><kbd><code>Low            </code></kbd><kbd><code>500        </code></kbd><kbd><code>1000         </code></kbd><br></p>
  <p>So I want to write a <code>SQL query</code> .</p>
  <p>I am already using this query :<p></p>
  <pre><code>SELECT C.Country,C.Count
  ,CASE WHEN C.Count &lt;= T.Low_Value THEN 'Low' WHEN C.Count BETWEEN T.High_Value AND T.Low_Value THEN 'Medium' ELSE 'High' END AS Threshold,
  T.Low_Value, T.High_Value FROM 
  (SELECT ID,Country,Sum(Count) AS Count 
  FROM Country 
  WHERE ID=00001 
  GROUP BY ID,Country) C 
  JOIN Threshold T 
  ON C.ID = T.ID
  </code></pre>
  <p>But this query is giving error.</p>
  <p>Can anyone one please suggest me how to implement this ?</p>
  <blockquote>
  <p>I am using <strong>Oracle</strong><p></p>
  <p>The error is <strong>ORA-00979 : not a GROUP BY expression</strong></p>
  </blockquote>
  <p><code>**This query is just for representation**</code></p>