在多个内连接中选择MAX

时间:2017-07-13 12:10:29

标签: sql

我想选择与查询相关的最大值,但所有结果都将到来。任何的想法 ?

QUERY

SELECT MAXRecID,MAXSetID,MAXRID,PreReifiedValue,ComplianceState
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,setting_CI_ID,
MAX(RecordID) AS MAXRecID,
MAX(SettingID) AS MAXSetID,
MAX(RuleID) AS MAXRID
FROM CI_CurrentRuleDetail
GROUP BY PreReifiedValue,Setting_CI_ID,instancedata) AS D ON D.Setting_CI_ID = A.CI_ID
GROUP by MAXRecID,MAXSetID,MAXRID,PreReifiedValue,rulename,ComplianceState

结果

MAXRecID            MAXSetID    MAXRID  PreReifiedValue ComplianceState
72057594038117564   16780566    16780622    10                2
72057594038117565   16780570    16780620     0                2

0 个答案:

没有答案