平均数:
avg(字段名)
百分率:分子/分母
count(case when 字段名及条件 then 1 else bull end) / count(*)
最大值:
max(字段名)
最小值:
min(字段名)
应用举例:
select openapi_id as interface_id,
count(*) as total_count,
count(CASE WHEN timeout_flag != '1' THEN 1 ELSE NULL END) as success_times,
round(count(CASE WHEN timeout_flag= '0' THEN 1 ELSE NULL END)/count(*),2) as success_rate,
round(avg(UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(begin_time)),2) as avg_response_time,
round(min(UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(begin_time)),2) as min_response_time,
round(max(UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(begin_time)),2) as max_response_time
from 表名
where 条件
group by 分组的字段名
ps1:
round(值,2)
表示如果值为小数,则保留小数点后2位;为整数就没有小数部分。ps2:
UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(begin_time)
表示字段end_time与begin_time相差的秒数
前提是这两个字段都为日期类型