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

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -