Compare Monday's data to previous Mondays in SQL Server -


i trying figure out how compare current day's data same data week ago, 2 weeks, etc. let's have table called "order" 2 columns:

order table ----------- orderid int identity orderdate datetime 

if today, monday, able compare number of orders today previous mondays entire year. possible single sql server query? i'm using sql 2008 if makes difference.

select cast (orderdate  date) [date], count(*) orders orderdate  > dateadd(year,-1, getdate())       , datepart(dw,orderdate ) = datepart(dw,getdate()) group cast (orderdate  date) 

Comments

Popular posts from this blog

List<T>().Add problem C# -

Javascript natural sort array/object and maintain index association -