Calculate percentage of Total marks in SQl




Table shown here shows the separate marks for each subject of each student. We can group these students to find the total marks of each student.

Code Snippet

SELECT NAME ,sum (MARKS) AS MARKS FROM TableName GROUP BY Name

Then we need to multiply the result that we get on dividing MARKS by TOTAL .This gives the percentage of marks obtained by each student.I.e., In case of Pavitra, we need to divide 21 by 30 which is suppose to be the Total marks.So (21/30) gives .77.Multiply .77 by 100 which gives the total percentage 77

Code Snippet

SELECT NAME ,(convert(float,(sum (MARKS)))/convert(float,@total))* 100  as  PERCENTAGE_MARKS FROM #t1 GROUP BY Name


HappyCoding ! 😉

Advertisements

One response to this post.

  1. When I initially commented I clicked the “Notify me when new comments are added”
    checkbox and now each time a comment is added I
    get three e-mails with the same comment. Is there any way you can remove me from that service?
    Thank you!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: