mysql字符串用法

replace(str,from_str,to_str)
--用字符串to_str替换字符串str中的子串from_str并返回

--mysql> select replace('www.mysql.com', 'w', 'ww');
--  -> 'wwwwww.mysql.com'


--SUBSTR(addtime, 1, 10)
--substr(string string,num start,num length);
--string为字符串
--start为起始位置
--length为长度

SELECT d.uid,
       SUBSTR(u.addtime, 1, 10) as 注册时间,
       d.cid as  cid
  FROM user_extra_device d,
       user u
 where d.uid= u.id
   and u.addtime>= "2017-01-09 00:00:00"
 order by SUBSTR(u.addtime, 1, 10)


--从左边开始截取3个字符
select left('example.com', 3)
--结果exa

--从右边开始截取3个字符
select right('example.com', 3)


--从字符串的第 4 个字符位置开始取,直到结束
select substring('example.com', 4)
--mple.com

--从字符串的第 4 个字符位置开始取,只取 2 个字符
select substring('example.com', 4, 2)


--从字符串的第 4 个字符位置(倒数)开始取,直到结束
select substring('example.com', -4)
--.com


--从字符串的第 4 个字符位置(倒数)开始取,只取 2 个字符
select substring('example.com', -4, 2)


concat(left(reg2 / install *100, 5), '%') as 注册率

$sql="select concat(id,"-",con) as res from article where id=1"


--#身份证件号码前"'",避免输出后显示为科学计算法
select uid,CONCAT(" '",cardno) as "身份证件号码" from  user_authentic  where state =2

  

posted @ 2017-05-26 11:25  Xiao|Deng  阅读(600)  评论(0编辑  收藏  举报