title: How to use 'Group By' when joining two tables
body: <p>I have two tables StudentMaster and StudentQualificationDetalis and have some data like below.
  <img src="https://i.stack.imgur.com/xXsiA.png" alt="enter image description here"></p>
  
  <p>The MarksPercentage Column is varchar</p>
  
  <pre><code>I need result like-
  details of students who have AdmissionBase = 10+2 and
  Get the number of students in AdmissionBase having percentage 50% - 60% and
  61% - 70% and
  71% - 80% and
  81% - 90% and
  91% - 100%
  </code></pre>
  
  <p>An example of result that I want is-</p>
  
  <pre><code>**AdmissionBase          Percentage          NumberOfStudents**
  10+2                     50% - 60%           3
  10+2                     61% - 70%           2
  </code></pre>
  
  <p>Above is just an example. Records in the table may vary.</p>
  
  <p>Here is what I have tried</p>
  
  <pre><code>SELECT          sm.AdmissionBase,
                  (
                  CASE
                  WHEN sq.MarksPerecent IS NULL OR sq.MarksPerecent = '' THEN 'Not Known'
                  WHEN CONVERT(DECIMAL, sq.MarksPerecent) &gt;= 50 AND CONVERT(DECIMAL, sq.MarksPerecent) &lt;= 60 THEN '50% - 60%'
                  WHEN CONVERT(DECIMAL, sq.MarksPerecent) &gt;= 61 AND CONVERT(DECIMAL, sq.MarksPerecent) &lt;= 70 THEN '61% - 70%'
                  WHEN CONVERT(DECIMAL, sq.MarksPerecent) &gt;= 71 AND CONVERT(DECIMAL, sq.MarksPerecent) &lt;= 80 THEN '71% - 80%'
                  WHEN CONVERT(DECIMAL, sq.MarksPerecent) &gt;= 81 AND CONVERT(DECIMAL, sq.MarksPerecent) &lt;= 90 THEN '81% - 90%'
                  WHEN CONVERT(DECIMAL, sq.MarksPerecent) &gt;= 91 AND CONVERT(DECIMAL, sq.MarksPerecent) &lt;= 100 THEN '91% - 100%'
                  ELSE 'Below 50%'
                  END
                  )Percentage,
                  COUNT(*)
  FROM            StudentMaster sm, StudentQualificationDetails sq
  where           sm.registerationnumber = sq.registerationnumber
  and             sm.AdmissionBase = sq.ExamDescription
  and             sm.admissionbase = '10+2'
  group by percentage
  </code></pre>
  
  <p>But it gives me error- Invalid column name 'percentage'.</p>
  
  <p>Thanks</p>