counting record fields and totals

C

cporter

I have a query where I need to count the number of times a record field
(ontime) is 1 and the total number of records in the query. What is the
best way to do this?

SELECT tblPMTemp.MACHID, tblPMTemp.PROCNO, tblPMTemp.FREQ,
tblPMTemp.DLP, IIf([DLP]+[FREQ]+14<=Date(),1,0) AS Ontime
FROM tblPMTemp
WHERE (("KLA"=Left([machid],3)));
 
J

Jerry Whittle

SELECT tblPMTemp.MACHID,
tblPMTemp.PROCNO,
tblPMTemp.FREQ,
tblPMTemp.DLP,
Sum(IIf([DLP]+[FREQ]+14<=Date(), 1, 0)) AS SumOntime,
Count(tblPMTemp.DLP) AS CountOntime
FROM tblPMTemp
Group By tblPMTemp.MACHID,
tblPMTemp.PROCNO,
tblPMTemp.FREQ,
tblPMTemp.DLP
HAVING (("KLA"=Left([tblPMTemp..machid], 3)));
 
J

John Spencer

SELECT MACHID
, Count(*) as RecordsReturnedForMachID
, SUM( IIf([DLP]+[FREQ]+14<=Date(),1,0)) AS Ontime
FROM tblPMTemp
WHERE MachID Like "KLA*"
GROUP BY MachID

That give you totals by MachId. If you want, totals for all then remove
MachId from the Select clause and delete the Group by clause.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top