Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8914189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:39:31+00:00 2026-06-15T04:39:31+00:00

Hi I am new to Oracle SQL and i want to write an SQL

  • 0

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:

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

The example of data in the table is as such:

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
....
....
....
....

Can anyone please help????

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:39:32+00:00Added an answer on June 15, 2026 at 4:39 am

    Try something like this :

    select id, sum(case name 
                        when 'A+' then 4.5 
                        when 'A' then 4
                        when 'B+' then 3.5
                        when 'B' then 3
                        when 'C+' then 2.5
                        when 'C' then 2
                        else 0
                   end
                   )/count(*) gpa
    from table 
    where id in ('s11','s12','s13','s14')
    group by id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to PL/SQL, and am using Oracle SQL Developer to write a
Im new to cursors in Oracle. I have a piece of SQL that is
I am a new user in Oracle. In Oracle SQL Developer, whenever I want
New to Oracle SQL and I assume that this is a very straight forward
This is the situation: I have a table in an Oracle SQL DB. That
I am new to Oracle. I have been using SQL-Server for the past 3
Oracle's PL/SQL is fairly new to me, so I need some help understanding if
SQL Server 2012 introduced Sequence as a new feature, same as in Oracle and
I'm Working with a new Oracle DB, with one table having the following indexes:
I have an Excel file that I need to import into a (new) Oracle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.