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 |
|
savolol
Starting Member
2 Posts |
Posted - 2011-06-23 : 05:51:04
|
| Select dayofyear,hour,max(case when A.RunNr=1 then COUNT_A else 0 end) as [RunNr=1],max(case when A.RunNr!=1 then COUNT_A else 0 end) as [RunNr>1]from (Select count(distinct IDNR)as [COUNT_A],RunNr,DATEPART (dayofyear,"When") as dayofyear,DATEPART (hh,"When") as "hour" from table_xwhere "When" >CURRENT_TIMESTAMP-7Group by DATEPART (dayofyear,"When"),RunNr,DATEPART (hh,"When")) [A]group by dayofyear,hourorder by dayofyear,hourResponce:dayofyear hour RunNr=1 RunNr>1 ----------- ----------- ----------- ----------- 171 8 1 0171 9 2 0173 9 2 0173 12 0 1173 13 2 1173 14 0 1174 8 3 1174 9 0 1174 11 1 0How can I plot null lines also, so that time line continues?Like:dayofyear hour RunNr=1 RunNr>1 ----------- ----------- ----------- ----------- 171 23 1 0171 24 2 0172 1 0 0172 2 0 1172 3 0 0172 4 1 10....How can I ask timestamps from database and join them to this?Or better solution??? |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-06-23 : 10:22:42
|
| Since we know nothing about your database it's hard to say. In general you'll need to do an [LEFT | RIGHT] OUTER JOIN to the set of vaules that you want to display (DayOfYear?) and join that to your result set to see the NULL values.If you still need more help you might want to check out the link below. It will tell you how to prove DDL, DML and expected output in a consumable format so we cna help you better.http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
|
|
|
|
|