Gets the hours in which a user has been active (enables you to see when a user sleeps!)
Q&A about the site for people looking to bypass life's everyday problems with simple tricks
-- Show the hours of the day a user is most active -- Gets the hours in which a user has been active (enables you to see when a user sleeps!) with hours as ( select datepart(hh, creationdate) as HoursSeen from posts where owneruserid = ##UserId## union all select datepart(hh, creationdate) as HoursSeen from comments where userid = ##UserId## ) select HoursSeen as Hour, count(*) as Count, '|' + replicate('*', count(*)) as Graph from hours group by HoursSeen order by HoursSeen