我需要有关创建查询的帮助。
目前它看起来像这样
SELECT
COUNT(*) AS ALERTS,
EXTRACT (YEAR FROM DATE) AS YEAR,
EXTRACT (MONTH FROM DATE) AS MONTH,
EXTRACT (DAY FROM DATE) AS DAY,
HOST,
ALERTLEVEL
FROM
ALERTS
WHERE
EXTRACT (DAY FROM DATE) > EXTRACT (DAY FROM CURRENT_DATE) -7
AND
EXTRACT (MONTH FROM DATE) >= EXTRACT (MONTH FROM CURRENT_DATE)
AND
HOST = 'HOST'
GROUP BY
YEAR,MONTH,DAY,HOST,ALERTLEVEL
ORDER BY
YEAR ASC,MONTH ASC,DAY ASC, ALERTLEVEL ASC
结果:
ALERTS YEAR MONTH DAY HOST ALERTLEVEL
5 2013 9 5 HOST 1
64 2013 9 5 HOST 2
11 2013 9 5 HOST 3
15 2013 9 5 HOST 4
16 2013 9 8 HOST 2
2 2013 9 9 HOST 1
我想为 alertlevel 设置 4 列而不是 1 列,并对每个 alertlevel 每天的列警报求和。
期望的结果
YEAR MONTH DAY HOST ALERTLEVEL1 ALERTLEVEL2 ALERTLEVEL3 ALERTLEVEL4
2013 9 5 HOST 5 64 11 15
2013 9 8 HOST 0 16 0 0
2013 9 9 HOST 2 0 0 0
这可能吗?
非常感谢您的帮助!!