2012-10-24 228 views
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 

上面的查詢給我下面的結果,附加爲圖像。 enter image description hereSQL查詢過濾出匹配結果

我想編寫一個查詢過濾掉所有0.00%結果,因此它只是只給出0.00%數據,因爲我不關心100%數據。我不知道如何過濾數據。

回答

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 
+0

對不起,我已經更新了我的問題有些部分缺失..抱歉.. – Satish

+0

只需添加缺少的一部分以上我的回答 – RichardTheKiwi

+0

您發佈了兩個查詢我應該使用哪一個? – Satish