SELECT hourStamp, SUM(CASE WHEN datestamp < GETDATE() THEN 1 ELSE 0 END) / @numberofdays AS HourAverage, SUM(CASE WHEN dateStamp BETWEEN DATEADD(d,DATEDIFF(d,0,GETDATE()),0)AND GETDATE() THEN 1 ELSE 0 END)AS HourToday
FROM webstats
GROUPBY hourStamp
ORDERBY hourStamp
I also have this query that pulls back correct results
Can you give me a little more information about what this particular query is trying to do? You may not need to use UNION, but perhaps different JOINs.
SELECT hourStamp,
SUM(CASE WHEN datestamp < GETDATE() THEN 1 ELSE 0 END) / @numberofdays as HourAverage,
SUM(CASE WHEN dateStamp BETWEEN DATEADD(d,DATEDIFF(d,0,GETDATE()),0) AND GETDATE() THEN 1 ELSE 0 END) as HourToday
FROM webstats
GROUP BY hourStamp
) t1
LEFT OUTER JOIN
(
SELECT hourstamp, COUNT(id) AS ActualVisits
FROM webStats
WHERE id IN
(SELECT ws.id
FROM webStats AS ws INNER JOIN webStatsTrace AS wst ON ws.id = wst.statsid
WHERE (ws.datestamp BETWEEN DATEADD(d, DATEDIFF(d, 0, GETDATE()), 0) AND GETDATE())
GROUP BY ws.id HAVING (COUNT(wst.statsid) > 1))
GROUP BY hourstamp
) t2 ON t1.hourStamp=t2.hourStamp
ORDER BY t1.hourStamp
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.