最近遇到一个需求,计算处理率,直接sql输出结果。
不废话,上sql:
SELECT concat(
TRUNCATE(
(
查询结果1/
查询结果2
)
* 100,2),'%'
) as rate
FROM 表名称
GROUP BY rate
SELECT concat(
TRUNCATE(
(
(SELECT count(*) FROM fire_alarm_event WHERE DATE_FORMAT( alarm_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) and is_deleted = 0 AND alarm_state <> 1)/
(SELECT count(*) FROM fire_alarm_event WHERE DATE_FORMAT( alarm_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) and is_deleted = 0)
)
* 100,2),'%'
) as rate
FROM fire_alarm_event
GROUP BY rate
结果: