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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Count Query 1

Status
Not open for further replies.

MinnKota

Technical User
Nov 19, 2003
166
US
I have a table with the Following format

[Reason],[Date]
NS, 12/05/2003
OA, 12/07/2003
NS, 1/02/2004
AS, 11/05/2003
SS, 12/02/2003
OA, 12/04/2003
NS, 2/05/2004

I am trying to build a count query that returns a total for the reason codes in a certain year (2003). I would like the final product to look like:

[Reason],[Total]
AS, 1
NS, 1
OA, 2
SS, 1

 
Try this:

SELECT REASON, COUNT(*) AS Total FROM yourtable
GROUP BY REASON, [DATE]

-VJ
 
Does this return only 2003 reason codes?
 
oops theres a sharp sign missing, and an alias for the count corrected:

Code:
SELECT [Reason], COUNT([Reason]) as CntReasons
FROM [yourtbl]
WHERE [Date] >= #01/01/2003# and [Date] <= #12/31/2003#
GROUP BY [Reason];

HTH,
fly

Martin Serra Jr.
 
Try this:

SELECT REASON, COUNT(*) AS Total FROM yourtable
WHERE year([DATE])='2003'
GROUP BY REASON

-VJ
 
Anyway, avoid to name your fields with reserved words like Date. A lot of headaches in perspective.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top