最大选择结果

时间:2017-07-13 06:07:26

标签: sql

我想要一个查询来获得与MAX()相关的结果,但查询列出了所有数据而不是过滤MAX。我哪里错了?

QUERY

USE CM_T01
SELECT
  D_PreReifiedValue,
  D_Setting_CI_ID,
  D_InstanceData,
  B.rulename AS B_rulename,
  B.criteria AS B_criteria,
  A.CIVersion AS A_CIVersion,
  A.CI_ID AS A_CI_ID,
  b.CI_ID AS B_CI_ID,
  B.Rule_ID AS B_Rule_ID,
  A.ComplianceState AS A_ComplianceState,
  A.LastComplianceMessageTime AS A_LastComplianceMessageTime,
  B.rule_uniqueID AS B_rule_uniqueID,
  B.rulenameRID AS B_rulenameRID,
  B.ruledescriptionRID AS B_ruledescriptionRID,
  B.rowversion AS B_Rowversion
FROM v_CI_CurrentComplianceStatus AS A
INNER JOIN v_CIRules AS B
  ON B.CI_ID = A.CI_ID
INNER JOIN v_R_System AS C
  ON C.ResourceID = A.ItemKey
INNER JOIN (SELECT
  PreReifiedValue AS D_PreReifiedValue,
  Setting_CI_ID AS D_Setting_CI_ID,
  instancedata AS D_InstanceData,
  MAX(RecordID) OVER (PARTITION BY instancedata) AS MAX_D_RecordID,
  MAX(SettingID) OVER (PARTITION BY instancedata) AS MAX_D_SettingID,
  MAX(RuleID) OVER (PARTITION BY instancedata) AS MAX_D_RuleID
FROM CI_CurrentRuleDetail
GROUP BY PreReifiedValue,
         Setting_CI_ID,
         instancedata,
         RecordID,
         SettingID,
         RuleID) AS D
  ON D.D_Setting_CI_ID = A.CI_ID
WHERE Netbios_Name0 = 'TRISTSCCM-PS'
AND rulename = 'OS Hardening: Authentication Types - Network security: LAN Manager authentication level'
AND RuleDescription LIKE '%not applicable%'
GROUP BY D_PreReifiedValue,
         D_Setting_CI_ID,
         D_InstanceData,
         MAX_D_RecordID,
         MAX_D_SettingID,
         MAX_D_RuleID,
         B.rulename,
         B.criteria,
         A.CIVersion,
         A.CI_ID,
         b.CI_ID,
         B.Rule_ID,
         A.ComplianceState,
         A.LastComplianceMessageTime,
         B.rule_uniqueID,
         B.rulenameRID,
         B.ruledescriptionRID,
         B.rowversion

结果

D_PreReifiedValue   D_Setting_CI_ID D_InstanceData  B_rulename  B_criteria  A_CIVersion A_CI_ID B_CI_ID B_Rule_ID   A_ComplianceState   A_LastComplianceMessageTime B_rule_uniqueID B_rulenameRID   B_ruledescriptionRID    B_Rowversion
0   16803678    Location = [Is64Bit=true]:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Property = scremoveoption   OS Hardening: Authentication Types - Network security: LAN Manager authentication level Equals 5    1015    16803678    16803678    16780614    2   2017-07-05 13:55:35.003 Rule_6629dfe6-1d8e-4713-829e-a5c72224dd1b   ID-de0d34d4-4265-4df3-a436-ad808b0fd265 ID-3c9250ae-bafb-4940-81b4-4840a0e771fc 0x000000000676D556
10  16803678    Location = [Is64Bit=true]:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Property = cachedlogonscount    OS Hardening: Authentication Types - Network security: LAN Manager authentication level Equals 5    1015    16803678    16803678    16780614    2   2017-07-05 13:55:35.003 Rule_6629dfe6-1d8e-4713-829e-a5c72224dd1b   ID-de0d34d4-4265-4df3-a436-ad808b0fd265 ID-3c9250ae-bafb-4940-81b4-4840a0e771fc 0x000000000676D556
4   16803678    Location = [Is64Bit=true]:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa, Property = LmCompatibilityLevel  OS Hardening: Authentication Types - Network security: LAN Manager authentication level Equals 5    1015    16803678    16803678    16780614    2   2017-07-05 13:55:35.003 Rule_6629dfe6-1d8e-4713-829e-a5c72224dd1b   ID-de0d34d4-4265-4df3-a436-ad808b0fd265 ID-3c9250ae-bafb-4940-81b4-4840a0e771fc 0x000000000676D556
536870912   16803678    Location = [Is64Bit=true]:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\MSV1_0, Property = NTLMMinClientSec   OS Hardening: Authentication Types - Network security: LAN Manager authentication level Equals 5    1015    16803678    16803678    16780614    2   2017-07-05 13:55:35.003 Rule_6629dfe6-1d8e-4713-829e-a5c72224dd1b   ID-de0d34d4-4265-4df3-a436-ad808b0fd265 ID-3c9250ae-bafb-4940-81b4-4840a0e771fc 0x000000000676D556
536870912   16803678    Location = [Is64Bit=true]:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\MSV1_0, Property = NTLMMinServerSec   OS Hardening: Authentication Types - Network security: LAN Manager authentication level Equals 5    1015    16803678    16803678    16780614    2   2017-07-05 13:55:35.003 Rule_6629dfe6-1d8e-4713-829e-a5c72224dd1b   ID-de0d34d4-4265-4df3-a436-ad808b0fd265 ID-3c9250ae-bafb-4940-81b4-4840a0e771fc 0x000000000676D556

0 个答案:

没有答案