I have a table with 2 fields, "fubar" and "date", in an Access database. "date" stores the dates in the full date format, i.e. date and time, e.g. 2/20/2004 1:34:53PM.
"fubar" contains values that may or may not be unique, e.g. the values could be:
12345
67890
12345
74653
00987
12345
...
What I need to do is to get a count of unique fubar values grouped by dates. However, I need to group only by the dates, not the time.
So given the following table:
fubar date
12345 2/20/2004 1:34:53PM
67890 2/20/2004 5:37:23PM
12345 2/20/2004 10:19:47PM
74653 2/19/2004 12:38:30AM
00987 2/19/2004 7:58:29AM
12345 2/18/2004 3:14:35PM
the SQL statement should return
date count of distinct fubar's
2/20/2004 2
2/19/2004 2
2/18/2004 1
Currently, I use multiple SQL statements, one for each date. Each SQL statement is:
(I specify someday, somemonth and someyear in my VBScript code.)
But I'd like to be able to group everything into one SQL statement so that I only have to deal with one list of records. Is this possible?
"fubar" contains values that may or may not be unique, e.g. the values could be:
12345
67890
12345
74653
00987
12345
...
What I need to do is to get a count of unique fubar values grouped by dates. However, I need to group only by the dates, not the time.
So given the following table:
fubar date
12345 2/20/2004 1:34:53PM
67890 2/20/2004 5:37:23PM
12345 2/20/2004 10:19:47PM
74653 2/19/2004 12:38:30AM
00987 2/19/2004 7:58:29AM
12345 2/18/2004 3:14:35PM
the SQL statement should return
date count of distinct fubar's
2/20/2004 2
2/19/2004 2
2/18/2004 1
Currently, I use multiple SQL statements, one for each date. Each SQL statement is:
Code:
"SELECT COUNT(fubar) FROM (SELECT DISTINCT fubar FROM table WHERE DATEPART('yyyy', date) = " & someyear & " AND DATEPART('m', date) = " & somemonth & " AND DATEPART('d', date) = " & someday & ")"
(I specify someday, somemonth and someyear in my VBScript code.)
But I'd like to be able to group everything into one SQL statement so that I only have to deal with one list of records. Is this possible?