cpuphantom
IS-IT--Management
Hello!
Here is what I have:
What is does is supposed to do is give me a printout of rows; each row being the sum of a week's worth of records ending on a Saturday. That part works great... but unfortunately I get a row for each user_id for each week. I just want a row per week for a sum of all users, but I can't remove "a.user_id" from the group by clause because I use it above.
So is there a better way to organize this?
Thanks.
Here is what I have:
Code:
select
(select sum(b.billings) from tbNumbers as b where b.datestamp between dateadd(d, -6, a.datestamp) and a.datestamp and b.user_id = a.user_id) as metric_week,
a.datestamp
from
tbNumbers as A
where
a.user_id in (64, 152, 72, 118, 95) and
a.datestamp between '1/1/2006' and '8/5/2006' and
datepart(dw, a.datestamp) = 7
group by
a.datestamp,
a.user_id
order by
a.datestamp
What is does is supposed to do is give me a printout of rows; each row being the sum of a week's worth of records ending on a Saturday. That part works great... but unfortunately I get a row for each user_id for each week. I just want a row per week for a sum of all users, but I can't remove "a.user_id" from the group by clause because I use it above.
So is there a better way to organize this?
Thanks.