MySQL记录

1.unixtime和可读时间的转换

unixtime是距"1970-01-01 08:00:00"的时间秒数

unixtime -> readable

 

select from_unixtime(double,format)

 

readable -> unixtime

 

select unix_timestamp(date)


例子:

 

 

select UNIX_TIMESTAMP('1997-10-04 22:23:00'); //返回875974980
select from_unixtime(875974980);//返回1997-10-04 22:23:00

 

2.replace into

使用mysql中经常碰到以下场景:首先判断数据是否存在;如果不存在,则插入;如果存在,则更新。

replace into table(fiedl1, field2) values(v1,v2);

replace into 首先尝试插入数据到表中,1.如果发现表中已经有此行数据(根据主键或者唯一索引判断)则先删除此行数据,然后插入新的数据; 2. 否则,直接插入新数据。插入的列必须有主键,否则会造成数据重复。

 

posted @ 2013-09-06 15:30  春文秋武  阅读(111)  评论(0编辑  收藏  举报