SQL Server-平均30天(不包括周末)

时间:2018-09-06 20:08:36

标签: sql sql-server average vertica weekend

这是我正在使用的SQL代码,在计算平均值时,我只考虑工作日。任何建议都将受到高度赞赏。

WITH DATA1 AS 
( 
     SELECT 
         lci.client_mnemonic,
         to_char(ENDDATETIME, 'DD') AS DAY,
         COUNT(timername) AS error_count
     FROM
         sat.aaaa
     WHERE 
         ENDDATETIME >= GETDATE() - 30
         AND ENDDATETIME < GETDATE()
     GROUP BY 
         lci.client_mnemonic,
         to_char(r.ENDDATETIME, 'DD')
)
SELECT 
    DATA1.client_mnemonic,
    (AVG(UCLDATA1.error_count)) as AVERAGE_ERROR_COUNT
GROUP BY 
    UCLDATA1.client_mnemonic

0 个答案:

没有答案