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 |
|
foupons
Starting Member
1 Post |
Posted - 2007-06-11 : 18:03:39
|
| I want to do a pull that will get me the count of clicks for a link for each of the last seven days.The problem is that not every day has a click, and I want each day to have a row even if it has 0 clicks. I can manage this if I create a table containing each day then left outer. But this is very slow compared to the inner join on the dates.Is there an Over() or outer apply that is faster? What is the best/fastest way to do this?the restule table should be DAY Clicks7/5 107/6 07/7 657/8 127/9 07/10 457/11 27Thanks! |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-06-11 : 19:11:51
|
One that comes to mind, is that you could run yuor query to get your counts, then left join to that result. SOmething like:SELECT temp.Date COALESCE(derived.Clicks, 0) AS ClicksFROM #Temp temp -- all the days you care aboutLEFT OUTER ( SELECT Date, SUM(Clicks) FROM MyTable WHERE Date BETWEEN <StartDate> AND <EndDate> ) derived ON temp.Date = derived.DateORDER BY temp.Date |
 |
|
|
|
|
|