I have a query that returns the number of grouped rows by date:
SELECT Convert (date, run.TimeStamp) as the timestamp, count (*) join the Race Insert as ScriptResult run ScriptRun form run.ScriptRunID = res.ScriptRunID interiWorkListItems as wli on wli.WorkListItemID = res .WorklistItemID Join InsLine WorkList Join WL as WL .WorkListID = wli.WorkListID Where (wli.WorkListID = @WLID) changed by group (date, Run.TimeStamp) order by converting (date, run.TimeStamp);
This generates a result set like this:
Timestamp (Madcount) 2015-03-10 5364 2015-03-11 22027 2015- 03-12 18037
Now what I want, cumulative ITEMCOUNT to summarize, is like this:
timestamp ITEMCOUNT TOTALCOUNT 2015-03-10 5364 5364 2015 -03 -11 22027 27391 2015-03-12 18037 45428
The query should be compatible with 2008R2. I have played in many variations [count ... more than ... division] but the problem is that the window function limit was needed. And I can not use ROWS or RANGE.
Any thoughts please? Thanks in advance
Try the correlated subquery:.
; With the form of CTE (change the timestamp as (date, run.TimeStamp), run on the run.criptRunID = res.ScriptRunID interiors on the wli.WorkListItemID = ResWliListItems join the form as Run ScriptResult Race Insiders Join ScriptRun as Count (*) S. WorklistItemID Change interiors (date, run.TimeStamp)) Select Timestamp, S, (select s) by WorkList as wL.WorkListID on WL = Wli.WorkListID Where (wli.WorkListID = @WLID) join group CTE T2 Where T2 with .t Imstamp & lt; = t1.TimeStamp) from T to CT T1
No comments:
Post a Comment