有些sql语句需要用到时总不知道怎么写,开个博客记下来。
1.获取最近X天的数据
select * from points_order_info where datediff(now(), server_time) < X
文档:
DATEDIFF()
returns expr1
– expr2
expressed as a value in days from one date to the other. expr1
and expr2
are date or date-and-time expressions. Only the date parts of the values are used in the calculation.
mysql>SELECT DATEDIFF('2007-12-31 23:59:59','2007-12-30');
-> 1 mysql>SELECT DATEDIFF('2010-11-30 23:59:59','2010-12-31');
-> -31
2.索引
查看所有
show index from tablename
show keys from tablename
创建索引
CREATE INDEX index_name ON table_name (column_list)
删除索引
DROP INDEX index_name ON talbe_name