这是我正在使用的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