Skip to main content
Participant
October 10, 2006
Question

need another way to summarize data

  • October 10, 2006
  • 1 reply
  • 357 views
I have an asp page that displays various statistics about data in the underlying database (Access 2003). The data manipulation is handled on the database side, so all I have to do is grab the numbers and slap them on the asp page, really.

Now, however, I was asked to allow the user to see the same statistics based on a date range they select on the page. At first I thought this was a simple task, but can't figure out how to do it.

Now I need the ability to FIRST filter out the data based on the date range specified by the user, and THEN run all my database calculations. ...but how do you first grab a subset of data from a table, and then in the same database run more queries on it?

Is there a way to do this? If yes, how? If no... is there another way I've not yet learned or thought of?

The only other thought I have is to write code that will loop through my recordsets and come up with the numbers to do the calculations on the page, but that seems like ... well, like there should be a better way!

Any help greatly appreciated.
This topic has been closed for replies.

1 reply

Inspiring
October 11, 2006
The thing about this kind of question is that the specifics about your data
are actually rather important to the answer.
In most cases, I think adding a date range would be a trivial exercise. I
can think of cases where it might be a little bit of an adventure, though.

Can you share your calculations and let us know where the date range would
come into play (on which table(s))?


"RMFI" <webforumsuser@macromedia.com> wrote in message
news:egh6dc$8du$1@forums.macromedia.com...
> Now, however, I was asked to allow the user to see the same statistics
> based
> on a date range they select on the page. At first I thought this was a
> simple
> task, but can't figure out how to do it.


Inspiring
October 11, 2006
This one is really very simple. Whatever query you have now, keep it, just
add tblData.DateTimeStamp BETWEEN @StartDate AND @EndDate to your query.

Any aggregation you do will be done after the result set is filtered, so
you'll be fine. If there's a problem, then please post the actual query so
we can tell why that may be.


"RMFI" <webforumsuser@macromedia.com> wrote in message
news:egj1d0$e9u$1@forums.macromedia.com...
> I need to determine the following facts for any selected time period:
>
> * how many unique users answered questions
> * how many total questions were answered
> * how many were "yes" / how many were "no"
> * which percent were "yes" / "no"
> * which topics had the most "no" answers (and yes/no percent breakdown)


RMFIAuthor
Participant
October 11, 2006
That's what I thought, at first, too. Here is a scenario showing why that doesn't work:

SQL that works on whole table:
SELECT DISTINCTROW Count(tblData.fldUserID) AS CountOffldUserID, tblData.fldUserID
FROM tblData
GROUP BY tblData.fldUserID;

Adding fldDateTimeStamp to the query causes the grouping to be incorrect. Using the same data, just bringing in the date/time causes the Unique User count to be incorrect.

SELECT DISTINCTROW Count(tblData.fldUserID) AS CountOffldUserID, tblData.fldUserID, DateValue([fldTimeStamp]) AS DateStamp
FROM tblData
GROUP BY tblData.fldUserID, DateValue([fldTimeStamp]);

If I don't show the fldDateTimeStamp in the query results, I can't filter based on date in my recordset. Right?

Am I still missing something?

There are other, trickier complications when it comes to the other values I need to calculate.


Data sample:
fldRecordID fldUserID fldQuestionID fldAnswerArray fldTimeStamp
643 61 33 0 8/22/2006 3:10:53 PM
644 61 34 0 8/22/2006 3:10:53 PM
645 61 35 0 8/22/2006 3:10:53 PM
646 61 36 0 8/22/2006 3:10:53 PM
787 61 38 0 8/23/2006 12:32:43 PM
788 61 37 0 8/23/2006 12:32:43 PM
789 61 39 1 8/23/2006 12:32:43 PM
1479 100 13 0 8/25/2006 9:22:42 AM
1480 100 14 1 8/25/2006 9:22:42 AM
1661 100 16 1 8/29/2006 11:33:56 AM
1662 100 15 0 8/29/2006 11:33:56 AM
1663 100 18 1 8/29/2006 11:33:56 AM
2195 149 7 0 9/10/2006 6:53:39 PM
2196 149 9 0 9/10/2006 6:53:39 PM
2197 149 10 1 9/10/2006 6:53:39 PM
2249 149 11 0 9/13/2006 12:13:04 PM
2250 149 12 0 9/13/2006 12:13:04 PM
2251 149 13 1 9/13/2006 12:13:04 PM