Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / August 2006

Tip: Looking for answers? Try searching our database.

Summing a count field please help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
allie357 - 14 Aug 2006 18:27 GMT
Currently I have a query that counts a text field called Policy

I need a query that sums this count field and evaluates it.

Say if the person has 3 violations they would be included in the query.
Any help is appreciated.

Here is the original query with the count:

PARAMETERS [Enter Start Date (mm/dd/yyyy)] DateTime, [Enter End Date
(mm/dd/yyyy)] DateTime;
SELECT tbl_Violations![Violator's Last Name] & ", " &
tbl_Violations![Violator's First Name] AS [Violator's Name],
tbl_Violations.[Policy Violated], Count(tbl_Violations.[Policy
Violated]) AS [CountOfPolicy Violated]
FROM tbl_Violations LEFT JOIN tblDepartments ON
tbl_Violations.[Violator's Department Number] = tblDepartments.[Dept
Number]
WHERE (((tbl_Violations.[Date Entered]) Between [Enter Start Date
(mm/dd/yyyy)] And [Enter End Date (mm/dd/yyyy)]))
GROUP BY tbl_Violations![Violator's Last Name] & ", " &
tbl_Violations![Violator's First Name], tbl_Violations.[Policy
Violated], tbl_Violations.[Violator's Last Name],
tbl_Violations.[Violator's First Name];
John Spencer - 14 Aug 2006 19:57 GMT
I'm unclear as to what you want.
Do you want anyone that has violated any one policy 3 or more times,
Or do you want any one that has three or more violations of policies
(multiples of one policy count against the total) ,
Or do you want anyone that has violated three or more policies (one
violation per policy can be counted)?

If you want to get persons that have violated any one policy three or more
times you just need to add a having clause to your query.

PARAMETERS [Enter Start Date (mm/dd/yyyy)] DateTime
, [Enter End Date (mm/dd/yyyy)] DateTime;
SELECT tbl_Violations![Violator's Last Name] & ", " &
tbl_Violations![Violator's First Name] AS [Violator's Name],
tbl_Violations.[Policy Violated]
, Count(tbl_Violations.[Policy Violated]) AS [CountOfPolicy Violated]
FROM tbl_Violations LEFT JOIN tblDepartments ON
tbl_Violations.[Violator's Department Number] =
tblDepartments.[Dept Number]
WHERE (((tbl_Violations.[Date Entered])
Between [Enter Start Date (mm/dd/yyyy)] And [Enter End Date (mm/dd/yyyy)]))
GROUP BY tbl_Violations![Violator's Last Name] & ", " &
tbl_Violations![Violator's First Name]
, tbl_Violations.[Policy Violated]
, tbl_Violations.[Violator's Last Name]
, tbl_Violations.[Violator's First Name]
HAVING Count(tbl_Violations.[Policy Violated) >= 3

The remaining two can be done, but are more complex.

> Currently I have a query that counts a text field called Policy
>
[quoted text clipped - 20 lines]
> Violated], tbl_Violations.[Violator's Last Name],
> tbl_Violations.[Violator's First Name];
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.