안녕하세요
cpu 사용률을 30분단위로 평균값을 보고 싶은데 어떻게 할까 고민중입니다.
15분에 한건씩 insert됩니다.
table cpu_info
pk HW_ID varchar(20)
pk YMD char(8)
pk HMS char(6)
CPU_USAGE int
번호 일자 시분초 cpu사용률
000000001 20180803 001000 30
000000001 20180803 002500 45
000000001 20180803 004000 15
000000001 20180803 004000 23
000000001 20180803 005500 20
000000001 20180803 001000 30
.
.
.
.
SELECT SUM(CASE WHEN HMS BETWEEN '000001' AND '003000' THEN CPU_USAGE ELSE 0 END) / SUM(CASE WHEN HMS BETWEEN '000001' AND '003000' THEN 1 ELSE 0 END) AS AVG_0030
, SUM(CASE WHEN HMS BETWEEN '003001' AND '010000' THEN CPU_USAGE ELSE 0 END) / SUM(CASE WHEN HMS BETWEEN '003001' AND '010000' THEN 1 ELSE 0 END) AS AVG_0100
, SUM(CASE WHEN HMS BETWEEN '010001' AND '013000' THEN CPU_USAGE ELSE 0 END) / SUM(CASE WHEN HMS BETWEEN '010001' AND '013000' THEN 1 ELSE 0 END) AS AVG_0130
, SUM(CASE WHEN HMS BETWEEN '010001' AND '013000' THEN CPU_USAGE ELSE 0 END) / SUM(CASE WHEN HMS BETWEEN '010001' AND '013000' THEN 1 ELSE 0 END) AS AVG_0200
, SUM(CASE WHEN HMS BETWEEN '020001' AND '023000' THEN CPU_USAGE ELSE 0 END) / SUM(CASE WHEN HMS BETWEEN '020001' AND '023000' THEN 1 ELSE 0 END) AS AVG_0230
, SUM(CASE WHEN HMS BETWEEN '023001' AND '030000' THEN CPU_USAGE ELSE 0 END) / SUM(CASE WHEN HMS BETWEEN '023001' AND '030000' THEN 1 ELSE 0 END) AS AVG_0300
.
.
.
FROM CPU_INFO
WHERE HW_ID = '000000001'
AND YMD = '20180803'
제가 생각한것인데 더 좋은 방법이 있을듯해서 문의합니다.
DB는 MS-SQL이면 TABLE HW_ID 번호하나당 하루 96건이 생기며 HW_ID는 몇만개가 정도 있어서 테이블안에 데이타량은 많습니다.
읽어주셔서 감사합니다.
|