Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting multiple values in a field 1

Status
Not open for further replies.

Yukonbanzai

Technical User
Mar 18, 2004
36
CA
Trying to count specific values in a field.
Table has field named "rank" with 8 possible text values, (Military Ranks).
How can I count how many of each value.
I need to be able to create a report that states how many Sgt's, Cpl's, etc.
 
Something like this should do it.

Code:
SELECT Rank,  COUNT(Rank) AS NumberInRank FROM MyTable GROUP BY Rank ORDER BY Rank
 
Is there a way to expand this to take in ranks from two tables?
I have a table with the NCO ranks and a different table that has the officer ranks.
Tables are "Cadet" and "Adult". Both have a field named "Rank".
The end result will be a parade state for the unit which needs to list how many of each rank there are.
 
Ok try this

Code:
SELECT Rank,  COUNT(Rank) AS NumberInRank FROM Cadet GROUP BY Rank
UNION ALL
SELECT Rank,  COUNT(Rank) AS NumberInRank FROM Adult GROUP BY Rank 
ORDER BY Rank
[code/]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top