Thread: count qry
View Single Post
  #2  
Old May 20th, 2010, 02:01 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default count qry

I've assigned an alias to the table to make this query easier to type. Also
moved the filtering conditions into a Where clause for efficiency and used the
DateValue function to strip off the time instead of using the DateSerial
function with three other functions calls.

SELECT DateValue([Date/Time*]) AS [Date]
, [A].[Event Type]
, [A].Parameter
, [A].Desc2
, Count(*) AS MyCount
, [A].Module
FROM [AlarmData Table Filtered by Date] AS A
WHERE[A].[Event Type]="CHANGE" AND
[A].Parameter Like "*OPSUP" AND
[A].Desc2="NEW VALUE = 1"
GROUP BY DateValue([Date/Time*]),
[A].[Event Type], [A].Parameter, [A].Desc2, [A].Module

If you want a count by date you need to change the query to eliminate the
other fields that you don't want to group by. Perhaps the following -
although you may want to eliminate Module also.

SELECT DateValue([Date/Time*]) AS [Date]
, Count(*) AS MyCount
, [A].Module
FROM [AlarmData Table Filtered by Date] AS A
WHERE[A].[Event Type]="CHANGE" AND
[A].Parameter Like "*OPSUP" AND
[A].Desc2="NEW VALUE = 1"
GROUP BY DateValue([Date/Time*])
, [A].Module

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

StuJol wrote:
using access 2003 i have the following qry

SELECT DateSerial(Year([Date/Time*]),Month([Date/Time*]),Day([Date/Time*]))
AS [Date], [AlarmData Table Filtered by Date].[Event Type], [AlarmData Table
Filtered by Date].Parameter, [AlarmData Table Filtered by Date].Desc2,
Count(*) AS MyCount, [AlarmData Table Filtered by Date].Module
FROM [AlarmData Table Filtered by Date]
GROUP BY
DateSerial(Year([Date/Time*]),Month([Date/Time*]),Day([Date/Time*])),
[AlarmData Table Filtered by Date].[Event Type], [AlarmData Table Filtered by
Date].Parameter, [AlarmData Table Filtered by Date].Desc2, [AlarmData Table
Filtered by Date].Module
HAVING ((([AlarmData Table Filtered by Date].[Event Type])="CHANGE") AND
(([AlarmData Table Filtered by Date].Parameter) Like "*OPSUP") AND
(([AlarmData Table Filtered by Date].Desc2)="NEW VALUE = 1"));

im trying to count number of entries per date but keeps returning 1 and
several instances of same date.