SQL Server Group data by week but show the start of the week -


i have query select customer data , want keep evolution of number of customers. in week 1 have 2 new customers number 2. in week 2 receive 3 new customers, number of customers 5.

i have following query this

select last_updated_week, sum( num_customers ) on ( order last_updated_week rows between unbounded preceding , current row ) "number of customers" (   select dateadd(dd,datediff(dd,0,registration_date),0) last_updated_week,          count(distinct customer_id) num_customers     customers_table   group dateadd(dd,datediff(dd,0,registration_date),0)) t 

but when run query, doesn't group data week. read datepart function, returns integer, need have actual date. can me?

just replace dd in dateadd , datediff functions week


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -