tags:

views:

2069

answers:

3

I have data stored as below in an MS Access database:

Date         User
20090101     1001
20090101     1002
20090102     1001
20090103     1001
20090103     1003

I'm attempting to create a query which shows the daily running count of unique users. For example:

Date        Daily Count   Unique User Running Count
20090101    2             2
20090102    1             2
20090103    2             3

What's the best way to achieve this?

A: 

Your query will look something like this...can't test it without the data though:

SELECT Date, Count(Date) As [Daily Count], Count(User) As [Unique User Running Count]
FROM TableName
GROUP BY Date
Justin Niessner
Unfortunately, Access Count() counts all values, not just distinct.
mavnn
When there is a GROUP BY clause, the Count() should only count the elements in the group...in this case, it would be how many for each distinct Date.
Justin Niessner
Indeed. Unfortunately, that doesn't give the OPs desired result for the running count field.
mavnn
A: 

It's not exactly the same scenario, but this questions answers should give you a starting point.

mavnn
+2  A: 

In most SQL implementations you could select using the aggregate function count(distinct user). But Access doesn't support that construct. I think the best you could do is to select the distinct values in a subquery and count them.

I was going to write a query but this link seems to do a good job.

HTH Tom

Tom