Running total with cross join
Declare @tbl table (branch varchar(100), date date, amt numeric(12,2))insert into @tbl(branch, date, amt)select Branch, DATE, SUM(amount) from RPT_PledgedAmount awhere a.Branch in ('f001','F008','F009','F010','F011','F012','F013','F014')group
order
by Branch, DATE by Branchselect
group a.branch, a.date, a.amt, sum(b.amt) from @tbl a cross join @tbl b where a.branch = b.branch and b.date <= a.date by a.branch, a.date, a.amtorder by a.branch,a.date
Declare @tbl table (branch varchar(100), date date, amt numeric(12,2))insert into @tbl(branch, date, amt)select Branch, DATE, SUM(amount) from RPT_PledgedAmount awhere a.Branch in ('f001','F008','F009','F010','F011','F012','F013','F014')group
order
by Branch, DATE by Branchselect
group a.branch, a.date, a.amt, sum(b.amt) from @tbl a cross join @tbl b where a.branch = b.branch and b.date <= a.date by a.branch, a.date, a.amtorder by a.branch,a.date
No comments:
Post a Comment