2016-10-17 33 views
1

我寫了一個查詢總和全部共涉及到一個Vulnarability名稱

SELECT Year(outertblissues.opendt)  AS Years, 
     Month(outertblissues.opendt)  AS Months, 
     outertblvulnerability.vulname, 
     Count(outertblvulnerability.vulid) Vulcount 
FROM tbl_apptestdetails AS outertblapptestdetails 
     INNER JOIN tbl_applicationlist AS outertblapplicationlist 
       ON outertblapptestdetails.appid = outertblapplicationlist.appid 
     INNER JOIN tbl_bu AS outertblbu 
       ON outertblbu.buid = outertblapplicationlist.buid 
     INNER JOIN tbl_issues AS outertblissues 
       ON outertblapptestdetails.testdetailid = 
        outertblissues.testdetailid 
        AND outertblissues.status NOT IN('1', '4') 
     INNER JOIN tbl_vulnerability AS outertblvulnerability 
       ON outertblissues.vulid = outertblvulnerability.vulid 
GROUP BY Year(outertblissues.opendt), 
      Month(outertblissues.opendt), 
      outertblvulnerability.vulname 
ORDER BY vulcount DESC 

其中給出以下結果 enter image description here

現在想多了一個列名作爲SumOfCount這給所有的總和VulCount與特定VulName相關例如,在「其他問題」前面SumOfCount應爲8,與其他問題類似

+0

任何幫助,請 – Ashu

回答

2

如果使用Sql Server 2012或更高版本,則可以嘗試通過分區指令Sum()

SUM(VulCount) OVER(PARTITION BY VulName) 
+0

@Henry第一解決方案爲我,請刪除第二個查詢,我將其標記爲答案,非常感謝你 – Ashu