I have a large database (approx 1mil records created per week). I am trying to analyze the data into "buckets". I am counting the number of times (Occurrences) that an Event is Replayed.Ultimately, this is what I am look for:Event Status Replay OccurrencesADD COMPLETE 1 167ADD COMPLETE 2 33ADD COMPLETE 3 5ADD COMPLETE 4 6ADD COMPLETE 5 2ADD COMPLETE 6 1ADD COMPLETE 8 1ADD COMPLETE 12 1
The source data has a record per event (and status) with additional data including an event ID and datetime stamps. For the above example data, there would be 308 ADD/COMPLETE source records ((1*167) + (2*33) + (3*5) + ...).I am trying to create a view such that I could accomplish something similar to:SELECT Event, Status, ReplayCount, Occurrences FROM vw_WeeklyData WHERE StartDate >= '2010-09-29' AND StartDate <= '2010-10-06' AND Event = 'ADD' AND Status = 'COMPLETE'
I have a query now that does what I want but I need the flexibility of a view:SELECT t1.Event, t1.Status, t1.ReplayCount, COUNT(*) AS Occurrences FROM ( SELECT dw.Event, dw.EventID, dw.Status, COUNT(*) AS ReplayCount FROM DataWeekly AS dw WHERE StartDate >= '2010-09-29' AND StartDate <= '2010-10-06' AND Event = 'ADD' AND Status = 'COMPLETE' GROUP BY dw.Event, dw.EventID, dw.Status ) AS t1 GROUP BY t1.Event, t1.Status, t1.ReplayCount ORDER BY Event;
Essentially, the subselect is grouping by EventID to get the number of times the specific EventID has an Event/Status record. The outer select then counts the number of occurrences that events were replayed x number of times.So, how can I get from this query to a more flexibly view which would allow me to query by a range of dates for StartDate, Event and Status?Any help would be greatly appreciated!Thanks!