date - SQL Defining Weeks From Days -


i'm trying summarize data in table weeks on past 10 months. field in table lists days in format dd-mm-yy. there simple way group these data weeks?

you try (tested sql server):

just paste code empty query window , execute. adapt needs.

declare @tbl table(datevalue varchar(8),othervalue int); insert @tbl values  ('30-09-15',10) ,('29-09-15',20) ,('28-09-14',30) ,('28-08-14',10) ,('27-08-14',10);   select convert(datetime,datevalue,3) converteddate         ,datepart(wk,convert(datetime,datevalue,3)) weekindex         ,othervalue  @tbl  --and way use aggregates ;with mydata (     select convert(datetime,datevalue,3) converteddate             ,datepart(iso_week,convert(datetime,datevalue,3)) weekindex             ,othervalue      @tbl    ) select weekindex,sum(othervalue) mydata group weekindex 

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 -