Via a stored procedure in SQL Server 2008, I am trying to show the number of transactions from the past 7 days, and then compare those numbers to a 7 day period a year ago. Additionally, I’d like to be able to show month-to-date versus month-to-date a year ago. Or this month to last month. Etc. Essentially, time-series data.
I’ve got a table with all the individual transactions. The two options I can think of are:
-
Calculate each individual day or month and return the result set
at run time. -
Calculate each invididual day and put the result
into a table. Update that daily. Create another table for weeks.
Another table for months. Each day, add a record or update the
existing record. That certainly will make the query faster, since
the data is already calculated. However, if I had to make updates to previous days (taking into account returns/cancels)
Note: This is an internal application, so it won’t see thousands of requests a minute.
What is the best way to return this type of data?
The other alternative I’ve thought about is using HBase OpenTSDB via Option 2, but seems like it’s the same process.
I may be either misunderstanding the question, or need to see your table schema (or something similar), but I see this as a simple
SELECT COUNT(*)...WHERE DATE BETWEEN [2Dates]. If all you need to do is count transactions that is.