1. 字符串转换成int
cast(str_a as signed)
int 转换成字符串
concat(c4,'')
2.字符串转换成小数
convert(str_a, decimal(15,1))
3.中位数计算方法:
select "中位数" name, max(case when ID=((@ID+1) div 2) then duration else 0 end) result from ( select @ID:=@ID+1 AS ID, duration from test a, (SELECT @ID:=0) as b order by duration asc ) as t
20 、80分位数等都可以用上面的方法
4. Mysql正则简单用法
-- mysql 如何判断"字符串"是否是"纯数值" select ('123a' REGEXP '[^0-9.]'); --‘123a'中含有字符 输出结果为false -- mysql 以'ok'为结尾 name REGEXP 'ok$' -- mysql 以1-9开头或者以ok结尾 name REGEXP '^[1-9]|ok$'
5. 生成自增长列(与3类似)
select (@i:=@i+1) id, -- 生成的自增长id area_code, area_name from ( select area_code, area_name from test_table ) s, (select @i:=0)t order by area_code asc -- 自增长列的排序字段, 根据code升序
6. update & join
update result_table a join ( select id, area_code, area_name from test_table ) b on a.id=b.id set a.area_name=b.area_name, a.area_code=b.area_code ;
每天进步一点点