Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

I have a SQL Server table that contains users & their grades. For simplicity's sake, lets just say there are 2 columns - name & grade. So a typical row would be Name: "John Doe", Grade:"A".

I'm looking for one SQL statement that will find the percentages of all possible answers. (A, B, C, etc...) Also, is there a way to do this without defining all possible answers (open text field - users could enter 'pass/fail', 'none', etc...)

The final output I'm looking for is A: 5%, B: 15%, C: 40%, etc...

1 Answer

0 votes
by (40.4k points)

Try using the below code:

Query:

Select Grade, (Count(Grade)* 100 / (Select Count(*) From MyTable)) as Score

From MyTable

Group By Grade

Hope this helps you...:)

You can master these queries and become proficient in SQL queries by enrolling in an industry-recognized SQL certification.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...