( SELECT `ChName`,
SUM( IF((to_days(now()) - to_days(`time`) =1),1 ,0 ) ) as yesterday,
SUM( IF((to_days(now()) - to_days(`time`) =2),1 ,0 ) ) as today_2,
SUM( IF((to_days(now()) - to_days(`time`) =3),1 ,0 ) ) as today_3,
SUM( IF((to_days(now()) - to_days(`time`) =4),1 ,0 ) ) as today_4,
SUM( IF((to_days(now()) - to_days(`time`) =5),1 ,0 ) ) as today_5,
SUM( IF((to_days(now()) - to_days(`time`) =6),1 ,0 ) ) as today_6,
SUM( IF((to_days(now()) - to_days(`time`) =7),1 ,0 ) ) as today_7
FROM `log` WHERE `ChName`="CTV" and `AlarmOnOff`="1" )
UNION
( SELECT `ChName`,
SUM( IF((to_days(now()) - to_days(`time`) =1),1 ,0 ) ) as yesterday,
SUM( IF((to_days(now()) - to_days(`time`) =2),1 ,0 ) ) as today_2,
SUM( IF((to_days(now()) - to_days(`time`) =3),1 ,0 ) ) as today_3,
SUM( IF((to_days(now()) - to_days(`time`) =4),1 ,0 ) ) as today_4,
SUM( IF((to_days(now()) - to_days(`time`) =5),1 ,0 ) ) as today_5,
SUM( IF((to_days(now()) - to_days(`time`) =6),1 ,0 ) ) as today_6,
SUM( IF((to_days(now()) - to_days(`time`) =7),1 ,0 ) ) as today_7
FROM `log` WHERE `ChName`="PTS" and `AlarmOnOff`="1" )
UNION
( SELECT `ChName`,
SUM( IF((to_days(now()) - to_days(`time`) =1),1 ,0 ) ) as yesterday,
SUM( IF((to_days(now()) - to_days(`time`) =2),1 ,0 ) ) as today_2,
SUM( IF((to_days(now()) - to_days(`time`) =3),1 ,0 ) ) as today_3,
SUM( IF((to_days(now()) - to_days(`time`) =4),1 ,0 ) ) as today_4,
SUM( IF((to_days(now()) - to_days(`time`) =5),1 ,0 ) ) as today_5,
SUM( IF((to_days(now()) - to_days(`time`) =6),1 ,0 ) ) as today_6,
SUM( IF((to_days(now()) - to_days(`time`) =7),1 ,0 ) ) as today_7
FROM `log` WHERE `ChName`="FTV" and `AlarmOnOff`="1" )
UNION
( SELECT `ChName`,
SUM( IF((to_days(now()) - to_days(`time`) =1),1 ,0 ) ) as yesterday,
SUM( IF((to_days(now()) - to_days(`time`) =2),1 ,0 ) ) as today_2,
SUM( IF((to_days(now()) - to_days(`time`) =3),1 ,0 ) ) as today_3,
SUM( IF((to_days(now()) - to_days(`time`) =4),1 ,0 ) ) as today_4,
SUM( IF((to_days(now()) - to_days(`time`) =5),1 ,0 ) ) as today_5,
SUM( IF((to_days(now()) - to_days(`time`) =6),1 ,0 ) ) as today_6,
SUM( IF((to_days(now()) - to_days(`time`) =7),1 ,0 ) ) as today_7
FROM `log` WHERE `ChName`="HiHd" and `AlarmOnOff`="1" )
UNION
( SELECT `ChName`,
SUM( IF((to_days(now()) - to_days(`time`) =1),1 ,0 ) ) as yesterday,
SUM( IF((to_days(now()) - to_days(`time`) =2),1 ,0 ) ) as today_2,
SUM( IF((to_days(now()) - to_days(`time`) =3),1 ,0 ) ) as today_3,
SUM( IF((to_days(now()) - to_days(`time`) =4),1 ,0 ) ) as today_4,
SUM( IF((to_days(now()) - to_days(`time`) =5),1 ,0 ) ) as today_5,
SUM( IF((to_days(now()) - to_days(`time`) =6),1 ,0 ) ) as today_6,
SUM( IF((to_days(now()) - to_days(`time`) =7),1 ,0 ) ) as today_7
FROM `log` WHERE `ChName`="TTV" and `AlarmOnOff`="1" )
UNION
( SELECT `ChName`,
SUM( IF((to_days(now()) - to_days(`time`) =1),1 ,0 ) ) as yesterday,
SUM( IF((to_days(now()) - to_days(`time`) =2),1 ,0 ) ) as today_2,
SUM( IF((to_days(now()) - to_days(`time`) =3),1 ,0 ) ) as today_3,
SUM( IF((to_days(now()) - to_days(`time`) =4),1 ,0 ) ) as today_4,
SUM( IF((to_days(now()) - to_days(`time`) =5),1 ,0 ) ) as today_5,
SUM( IF((to_days(now()) - to_days(`time`) =6),1 ,0 ) ) as today_6,
SUM( IF((to_days(now()) - to_days(`time`) =7),1 ,0 ) ) as today_7
FROM `log` WHERE `ChName`="CTS" and `AlarmOnOff`="1" )