我坚持使用SQL查询,所以我想也许一个SQL MVP / GOD可以在这里找到这个小运气。
我正在使用SQL Server 2008,这是我的表格的描述:
表格 - 列
NodesCustomProperties - NodeID / NodeZone
应用程序 - NodeID / ID
组件 - ApplicationID /名称
CurrentComponentStatus:ApplicationID / Data
当Component.Name类似于'HTTP%:在代理和服务器之间传输的字节'时,我想获取CurrentComponentStatus.Data的SUM用于相同的ApplicatioID并在NodesCustomProperties.NodeZone ='一个特定区域'时过滤这些结果
到目前为止,研究和测试已经引领我:SELECT
SUM(
CASE
WHEN [dbo].[APM_CurrentComponentStatus].StatisticData IS NOT NULL
THEN [dbo].[APM_CurrentComponentStatus].StatisticData
ELSE 0
END) AS 'Data'
FROM
[dbo].[APM_CurrentComponentStatus]
LEFT JOIN [dbo].[APM_Application]
ON [dbo].[APM_Application].ID = [dbo].[APM_CurrentComponentStatus].ApplicationID
WHERE
[dbo].[APM_Application].NodeID IN (
SELECT [dbo].[NodesCustomProperties].NodeID
FROM [dbo].[NodesCustomProperties]
WHERE [dbo].[NodesCustomProperties].NodeZone = 'one particular zone')
GROUP BY [dbo].[APM_CurrentComponentStatus].ApplicationID
HAVING [dbo].[APM_CurrentComponentStatus].ApplicationID
IN (
SELECT [dbo].[APM_Component].ApplicationID
FROM [dbo].[APM_Component]
WHERE [dbo].[APM_Component].Name LIKE 'HTTP%: Bytes Transferred Between Proxy and Servers')
这个查询实际上有效(万岁!)但结果太少,所以仍然没有。 (哇!)