I have this SQL Server query
SELECT count(distinct [IP]) as GlobalUniqueIPcount,
--RangeUniqueIPcount
(SELECT count(distinct [IP]) FROM [tblSequence] WHERE SiteID = @siteID AND ([Timestamp] > DATEADD(dd, -@days, (LEFT(GETDATE(),12))))) as RangeUniqueIPcount,
--RangeUrlUniqueIPcount
(SELECT count(distinct [IP]) FROM [tblSequence] WHERE SiteID = @siteID AND ([Timestamp] > DATEADD(dd, -@days, (LEFT(GETDATE(),12)))) AND Url = @Url) as RangeUrlUniqueIPcount,
--RangeUniquePageviews
(SELECT count (distinct url + SessionGuid) FROM [tblSequence] WHERE SiteID = @siteID AND ([Timestamp] > DATEADD(dd, -@days, (LEFT(GETDATE(),12))))) as RangeUniquePageViews,
--RangeUrlUniquePageviews
(SELECT count (distinct url + SessionGuid) FROM [tblSequence] WHERE SiteID = @siteID AND ([Timestamp] > DATEADD(dd, -@days, (LEFT(GETDATE(),12)))) AND Url = @Url) as RangeUrlUniquePageViews,
--GlobalUniquePageViews
(SELECT count (distinct url + SessionGuid) FROM [tblSequence] WHERE SiteID = @siteID) as GlobalUniquePageViews
FROM [tblSequence] WHERE SiteID = @siteID
I have more than 1,000,000 rows and it performs like crap. What to do - please help.
Thanks a lot