Reputation: 95
I have a table with the following layout :
+----+-----------+-------------+ | id | name | department | +----+-----------+-------------+ | 1| John | Finance | +----+-----------+-------------+ | 2| Bob | Optics | +----+-----------+-------------+ | 3| Jill | Finance | +----+-----------+-------------+ | 4| Jake | Finance | +----+-----------+-------------+ | 5| Mike | Support | +----+-----------+-------------+
I want to get the sum of all the people in each department :
+-----------+-------------+ | people | department | +-----------+-------------+ | 3| Finance | +-----------+-------------+ | 1| Optics | +-----------+-------------+ | 1| Support | +-----------+-------------+
I am having trouble constructing a right query
Upvotes: 1
Views: 756
Reputation: 6563
Try this :-
SELECT COUNT(name) AS people,department FROM table GROUP BY department
Upvotes: 1
Reputation: 2843
Use COUNT
SELECT COUNT(name),department FROM table GROUP BY department
Upvotes: 2
Reputation: 7973
SELECT departmetn, Count(*) as people FROM table Group by departmetn
Upvotes: 1