title: oracle sql to calculate gpa from grades
body: <p>Hi I am new to Oracle SQL and i want to write an SQL statement that can read the grades from the table and generate gpa for students. Below is a sample code I wrote and its not working:</p>
  
  <pre><code>select id,
  declare gpa = 0;
  BEGIN
      IF grade = 'A+' THEN gpa = gpa + 4.5;
      ELSIF grade = 'A' THEN gpa = gpa + 4;
      ELSIF grade = 'B+' THEN gpa = gpa + 3.5;
      ELSIF grade = 'B' THEN gpa = gpa + 3;
      ELSIF grade = 'C+' THEN gpa = gpa + 2.5;
      ELSIF grade = 'C' THEN gpa = gpa + 2;
      ELSE gpa = gpa + 0;
      END IF
      gpa = gpa/count(grade)
  END
  gpa from table where id in ('s11','s12','s13','s14')
  group by id
  </code></pre>
  
  <p>The example of data in the table is as such:</p>
  
  <pre><code>id                   grade
  --------------------------
  s11                  A
  s11                  B+
  s11                  A+
  s11                  C
  s12                  C+
  s12                  A
  s12                  D
  s12                  B
  s13                  A+
  s13                  C+
  s13                  B
  s13                  A
  s13                  A
  ....
  ....
  ....
  ....
  </code></pre>
  
  <p>Can anyone please help????</p>