Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table-student having fields id,name,grade.

id name grade

1 a1 A
2 a2 B
3 a3 C
4 a4 B
5 a5 A
6 a6 A


now i want to get a result as the following table


grade count

A 3
B 2
C 1
Posted
Comments
Arunprasath Natarajan 28-Jun-12 12:44pm    
Dear Friend, Both Abhinav's and Prasad's answers are fine. I think you are new to SQL.
Kindly go through about SQL in W3School or msdn. I will help you a lot.

Try select grade, count(*) from stduent group by grade.
Ideally, this is a very simple query and if you read a good book on sql, you should be able to right such a query on your own.
 
Share this answer
 
Comments
Mohamed Mitwalli 27-Jun-12 1:46am    
5+
Abhinav S 27-Jun-12 2:50am    
Thank you.
Espen Harlinn 27-Jun-12 19:04pm    
5'ed!
Abhinav S 27-Jun-12 23:25pm    
Thanks Espen.
Try this:
SQL
SELECT DISTINCT grade, COUNT(grade) from stduent GROUP BY grade.


Understand how count works, this is really very simple as Abhinav answered.

Refer:http://msdn.microsoft.com/en-us/library/ms175997.aspx[^]
 
Share this answer
 
Comments
Mohamed Mitwalli 27-Jun-12 1:46am    
5+
Prasad_Kulkarni 27-Jun-12 1:49am    
Thank you Mohamed!
Espen Harlinn 27-Jun-12 19:04pm    
5'ed!
Prasad_Kulkarni 28-Jun-12 11:49am    
Thank you Espen!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900