sql 计算两查询结果相除,输出百分比
最近遇到一个需求,计算处理率,直接sql输出结果。不废话,上sql:SELECT concat(TRUNCATE((查询结果1/查询结果2)* 100,2),'%') as rateFROM 表名称GROUP BY rateSELECT concat(TRUNCATE(((SELECT count(*) FROM fire_alarm_event WHERE DATE_FORMAT( alarm_
·
最近遇到一个需求,计算处理率,直接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
结果:
如果对您有帮助,随手点赞关注哦,谢谢!
更多推荐
已为社区贡献1条内容
所有评论(0)