2

I have a table of Student which has fields

ID  |   Name        |   Class   |  
---------------------------------
1   |   One         |   Class1  |  
2   |   Two         |   Class2  |  
3   |   Three       |   Class1  |  

I want to get the count of students for each class in a single Query. Like.

Class   |   Count   |
---------------------
Class1  |   2       |
Class2  |   1       |
2
  • It would be great if you could show some kind of effort on your part. Commented Mar 20, 2016 at 6:27
  • This is basic group by statement which you can construct on your own if you know the basics, you can learn more about SQL Group by on W3Schools - Group By Commented Mar 20, 2016 at 6:37

1 Answer 1

4

You can try this

SELECT
 Class,
 COUNT(*) AS Count
FROM
  Student 
GROUP BY
  Class
Sign up to request clarification or add additional context in comments.

2 Comments

What to do if a condition also to be added ?
WHERE your_condition GROUP BY Class;

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.