0
        SELECT TOP 92 PERCENT 
        Convert(DateTime,Floor(Cast((DateTime) as Float)*24)/24,0) AS SummaryDateTime,
        MIN(APM_ApplicationAvailability.PercentAvailability) AS MIN_of_ApplicationAvailability,
        Nodes.Caption AS NodeName 

        FROM 
        (Nodes INNER JOIN APM_AlertsAndReportsData ON (Nodes.NodeID = APM_AlertsAndReportsData.NodeId))  INNER JOIN APM_ApplicationAvailability ON (APM_AlertsAndReportsData.ApplicationId = APM_ApplicationAvailability.ApplicationID)


        WHERE 
        ( DateTime BETWEEN 40907 AND 41205 )
         AND  
        (
          (APM_AlertsAndReportsData.ApplicationName LIKE '%HTTP%') AND 
          (Nodes.Caption = 'www.example.com')
        )
GROUP BY Convert(DateTime,Floor(Cast((DateTime) as Float)*24)/24,0), 
Nodes.Caption


ORDER BY SummaryDateTime ASC

上面的查询给了我以下结果,作为图像附加。在此处输入图像描述

我想编写一个查询来过滤掉所有0.00%结果,所以它只会给出0.00%数据,因为我不关心100%数据。我不知道如何过滤数据。

4

1 回答 1

2

这是您的完整查询吗?您有混合聚合 ( MIN) 和非聚合 ( Datetime)。
我假设您在某处有一个 GROUP BY,但无论如何,直接的方法是对其进行子查询。

SELECT *
FROM (
    SELECT TOP 92 PERCENT
        Convert(DateTime,Floor(Cast((DateTime) as Float)*24)/24,0) AS SummaryDateTime,
        MIN(APM_ApplicationAvailability.PercentAvailability) AS MIN_of_ApplicationAvailability,
        Nodes.Caption AS NodeName 
    FROM Nodes
    INNER JOIN APM_AlertsAndReportsData
            ON Nodes.NodeID = APM_AlertsAndReportsData.NodeId
    INNER JOIN APM_ApplicationAvailability
            ON APM_AlertsAndReportsData.ApplicationId = APM_ApplicationAvailability.ApplicationID
    WHERE DateTime BETWEEN 40907 AND 41205
      AND APM_AlertsAndReportsData.ApplicationName LIKE '%HTTP%'
      AND Nodes.Caption = 'www.example.com'
    -- GROUP BY..
) X
WHERE MIN_of_ApplicationAvailability = 0.0

通常,对于聚合查询,您还可以使用 HAVING 子句,例如

    SELECT TOP 92 PERCENT
        Convert(DateTime,Floor(Cast((DateTime) as Float)*24)/24,0) AS SummaryDateTime,
        MIN(APM_ApplicationAvailability.PercentAvailability) AS MIN_of_ApplicationAvailability,
        Nodes.Caption AS NodeName 
    FROM Nodes
    INNER JOIN APM_AlertsAndReportsData
            ON Nodes.NodeID = APM_AlertsAndReportsData.NodeId
    INNER JOIN APM_ApplicationAvailability
            ON APM_AlertsAndReportsData.ApplicationId = APM_ApplicationAvailability.ApplicationID
    WHERE DateTime BETWEEN 40907 AND 41205
      AND APM_AlertsAndReportsData.ApplicationName LIKE '%HTTP%'
      AND Nodes.Caption = 'www.example.com'
    GROUP BY DateTime, Nodes.Caption
    HAVING MIN(APM_ApplicationAvailability.PercentAvailability) = 0.0
于 2012-10-24T20:24:17.783 回答