mysql 中使用到的语句记录备用
1.将字符串时间转换成时间戳
select unix_timestamp('2015-09-17 19:29:00');
2.字段拼接
select CONCAT ('CO', ' ', 'NCAT');
3.行列转换
select user_id,
MAX(CASE WHEN TABLE.key1 = 'val1' THENTABLE.valkey ELSE NULL END) as setkey1,
MAX(CASE WHEN TABLE.key1 = 'val2' THEN TABLE.valkey ELSE NULL END) as setkey2;//表的行列转换
在同一张表(TABLE)中key1保存类型valkey保存数据 ,需要将纵向数据提取成一条横向数据
4.数据表之间的转移
insert into room1 select id,room_id,room_url,room_origin from room where id in (1,2,3,4,5);
insert into room1 (room_id,room_url,room_origin) select room_id,room_url,room_origin from room where id in (1,2,3,4,5);
5.空字段转化换
IFNULL(expr1,expr2) ,SELECT IFNULL(1,0);
如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2