语法
https://blog.csdn.net/qq_42992643/article/details/82959720
去重
https://www.cnblogs.com/sxshiblog/p/4387894.html
- 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供有distinct这个关键字来过滤掉多余的重复记录只保留一条,但 往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所有值。其原因是distinct只能返回它的目标字段,而无法返回其它字段
坑:select distinct test1, id from test – 同时作用了两个字段
采用:select id, test1 from test group by test1
主键自增
ALTER TABLE t_name
CHANGE f_id
f_id
INT(11) NOT NULL AUTO_INCREMENT;
唯一索引
alter table t_name ADD UNIQUEAPPID
USING BTREE (f_appid);
查询mysql中所有表
show tables;
Mysql 给表添加字段的三种方式
alter table student
add address
int – 在末尾添加字段
alter table student
add address
int first – 在开头添加字段
alter table student
add address
int after name
– 在指定字段之后添加字段
mysql怎么查询表结构
DESCRIBE 表名;
Mysql 插入或更新时字段自动获取当前时间
更新时间 字段
1. ALTER TABLE 表名
ADD COLUMN 字段名 timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘更新时间’ ;
2. (如果已经创建了时间字段,使用下面的修改方法)
ALTER TABLE t_free_pid_record MODIFY COLUMN f_updatedate timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ;
查询当天、当月等数据
https://www.cnblogs.com/javasuperman/p/8955711.html
当天
select * from 表名 where to_days(时间字段名) = to_days(now());
时间戳 查询近一年的记录
https://www.cnblogs.com/chenzhanxun/articles/6248056.html
时间戳形式:UNIX_TIMESTAMP()转化 为UNIX时间戳形式
select * from apply_info where apply_time>UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 YEAR));
时间形式:
where inputtime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)