【个人知识备忘】mysql语法总结

日期转字符串
select count(*) from act_order where DATE_FORMAT(gmt_create,'%Y-%m-%d')='2012-10-1';

加减天数:
update act_order_timeout set validity_time= DATE_ADD(gmt_create, INTERVAL 15 DAY) where status=0;

自动更新的mofigytime
定义t5由一个自增字段,一个默认当前时间戳并update时随动更新字段组成。
mysql> CREATE TABLE t5 (
  id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  css timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  v int(11) DEFAULT NULL );
Query OK, 0 rows affected (0.13 sec)

mysql> insert into t5(v) values (1);
Query OK, 1 row affected (0.06 sec)
mysql> select * from t5;
+----+---------------------+------+
| id | css                 | v    |
+----+---------------------+------+
|  1 | 2012-09-06 08:04:29 |    1 |
+----+---------------------+------+
参考文档: http://www.w3school.com.cn/sql/func_date_format.asp


mysql  据主键查询,极限是多少?
外层删除操作与子查询同时操作同一张表
再在子查询建个子表吧
delete from category_trees  where root_id=0 and parent_id=0 and user_id=0 and  id not in (select cid from (select ct.id as cid from category_trees ct,localstore_categories lc where ct.id=lc.category_id) as c) ;

复制表的问题。
通过create table temp_limit_channel select * from limit_channel;只能复制表的结构和数据。无法复制主键、索引之类。


你可能感兴趣的:(mysql)