SQL CASE WHEN
给 响应时间 划分区间
SELECT response_ms/1000 as response_sec ,
CASE WHEN response_ms/1000 <= 1 THEN '0~1s'
WHEN response_ms/1000 > 1 AND response_ms/1000 <=10 THEN '1~2s'
WHEN response_ms/1000 > 10 AND response_ms/1000 <=15 THEN '10~15s'
WHEN response_ms/1000 > 15 THEN '15+s'
ELSE 'UNKNOWN' END AS interval_response
FROM table_a
1
2
3
4
5
6
7
2
3
4
5
6
7
使用 TRIM() 删除 CASE WHEN 新生成字段的 三个空格
reference
- [1] 携风沐雨共朝夕lv-1. SQL - case when then else end 的用法open in new window
- [2] Aliyun. CASE WHENopen in new window