mysql的正则查询 及sql中的时间转换

模糊查询我们都明白

select * from 表名 where 字段 like '%要查询的数据%'

接下来要说的就是 regexp

查找name字段中以“com”开头的所有数据

select name from 表名 where name regexp '^com'

查找name字段中以’ll‘结尾的的所有数据

select name from 表名 where name regexp 'com$'

查询name字段中包含“xixi”字符串的所有数据

select name from 表名 where name regexp 'xixi'

查找name字段中以元音字符开头或以“ok”字符串结尾的

select name from 表名 where name regexp ’^[aeiou]|pk$‘

#时间datetime转换为long格式
SELECT UNIX_TIMESTAMP(NOW());  #1410403824
#时间long转换为datetime格式
SELECT FROM_UNIXTIME(1410403824);  #2014-09-11 10:50:24
在实际的处理过程中,需要除以1000
SELECT id,mobile,CODE,FROM_UNIXTIME(create_time/1000) AS createTime,TYPE FROM `mobile_code` ORDER BY id DESC;