Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-03-05 : 10:44:45
|
Lokendra writes "I have a Blog Table which contain following Blog Details .Table: BlogUserId | BlogId | BlogDetail | CreatedDate 1 1 xyz 12/23/2007 1 2 fdf 12/23/2007 The data is about 10000 rows andaccording to above structure and sample data I want to use sql so that I can get the Data in Following formDay CountWednesday 30Tuesday 20Monday 30LastWeek 40Two Weeks Ago 55Last month 51 year Ago 200" |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-03-05 : 11:44:54
|
[code]declare @today datetimeselect @today = DATEADD(d, DATEDIFF(d, 0, GetDate()), 0) select @today select sum(case when CreatedDate >= @today then 1 else 0 end) as TodayCount, sum(case when CreatedDate >= @today-1 and CreatedDate < @today then 1 else 0 end) as OneDayAgoCount, -- this is generic for interval from N to M days ago sum(case when CreatedDate >= @today-N and CreatedDate < @today-N+M then 1 else 0 end) as NDaysAgoCountfrom YourTable[/code]Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
|
|