July 23, 2013 at 3:00 pm
Looking for tips on how best to approach the following query - 10million rows. Subquery selects, sum, CTE, over with Partionioning, etc . Is there a better way to do this in 2012? using Windowing - My code base is 2008.
SELECT
[DateofScan]
,[DeviceType]
,count ofdistinct [PlugInID]
,count ofdistinct [PlugInID] that are Critical
,count ofdistinct [PlugInID] where [VulNotDate] is NULL --'1900-01-01'
,Count ofdistinct (PlugInID] where [VulNotDate] <= 90 daysofSan
,Count ofdistinct (PlugInID] where [VulNotDate] > 90 daysofSan
FROM [TCH_Metrix].[dbo].[VulMgmt]
GROUP BYDateofScan, DeviceType
John Zacharkan
July 23, 2013 at 3:07 pm
can you use the trick of a SUM(CASE...
not sure if you need a count, or the coutn distinct for each item:
SELECT
[DateofScan]
,[DeviceType]
,count([PlugInID])
,SUM(CASE WHEN Critical = 'Y' THEN 1 ELSE 0 END) AS Critical
,SUM(CASE WHEN [VulNotDate] is NULL THEN 1 ELSE 0 END) AS NotDates
,SUM(CASE WHEN [VulNotDate] <= 90 THEN 1 ELSE 0 END) AS daysofSan
,SUM(CASE WHEN [VulNotDate] > 90 THEN 1 ELSE 0 END) AS daysofSan
FROM [TCH_Metrix].[dbo].[VulMgmt]
GROUP BY DateofScan, DeviceType
Lowell
July 23, 2013 at 3:39 pm
Absolutely - anything is possible I was just looking for clean and efficient.
John Zacharkan
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply