表dbo.AllApps
记录所有已运行的可执行文件,它具有存储exe文件哈希值的列ApplicationHash
,存储执行exe的用户ID的列UserName
。SQL Server:将结果返回一行并附加COUNT列
如果exe已经运行了10次,表中将会有10个条目具有相同的信息,但具有不同的时间戳和执行该实例的用户。
我想生成一个只返回10行(包括所有列时间,名称,desc ...)的报告,另外还有一列将提供exe的次数被执行(在这个例子中总共10行)和执行exe的唯一用户数量(在这个例子中是3)。
有什么建议吗?
ApplicationHash TimeStamp UserName
-----------------------------------
ABCDE12345 00:00:05 User1
ABCDE12345 00:02:05 User2
ABCDE12345 00:04:05 User1
ABCDE12345 00:10:05 User3
ABCDE12345 00:15:05 User3
ABCDE12345 00:20:05 User1
ABCDE12345 00:21:05 User2
ABCDE12345 00:33:05 User2
ABCDE12345 00:45:05 User1
ABCDE12345 00:55:05 User1
结果应该是somethine这样的:
ApplicationHash ProcessCount UserCount
--------------------------------------
ABCDE12345 10 3
这里是有人想出了这确实解决了ProcessCount
问题,但我需要一个唯一的用户名数,以及:
declare @StartDate datetime = '20170401';
declare @EndDate datetime = '20170406';
select top 1 with ties
ProcessCount = count(*) over (partition by ApplicationHash)
, ApplicationHash
, ProcessStartTime
, ApplicationType
, Description
, Publisher
, ProductName
, ProductVersion
, EventDescription
, CommandLine
, FileName
from dbo.AllApps aa
where TokenType = 'Elevated'
and ApplicationType != 'com Class'
and ApplicationType != 'ActiveX Control'
and ProcessStartTime >= @StartDate
and ProcessStartTime < @Enddate
and ProductName = 'WizSvcUt Application'
order by row_number() over (partition by ApplicationHash order by ProcessStartTime desc)
请缩短本文。 – niksofteng