数据类型
tinyint 1字节 (-128,127) (0,128) 小整数类型
smallint 2 字节 (-32 768,32 767) (0,65 535)
mediumint 3 字节 (-8 388 608,8 388 607) (0,16 777 215)
int/integer 4 字节
bigint 8字节 超大整数
float 4字节 单精度浮点数
double 8字节 双精度
decimal M+2 定点数
char 0-255字节 定长字符串
varchar 0-65535 字节 变长字符串
text 0-65 535字节 长文本数据
mediumtext 0-16 777 215字节 中等长度文本数据
longtext 0-4 294 967 295字节 极大文本数据
date 3字节 YYYY-MM-DD日期
time 3字节 HH:MM:SS
year 1字节 YYYY年
datetime 字节 YYYY-MM-DD HH:MM:SS
timestamp 4字节 YYYYMMDD HHMMSS
enum 65535个 枚举类型
运算符
+ - * / %取余
= != < <= > >=
between 1 and 10;
in (1,2,3,4,5) ;
is null ;
like "%"
and or
函数
curdate()+0
curdate()
curtime()
now()
unix_timestamp(now())
from_unixtime( 1539659520)
from_unixtime(1515980716, '%Y-%m-%d %H:%i:%S')
date_format(now(), '%Y-%m-%d')
date( now()) 2019-07-10
year('2019-7-10')
month('2016-04-28')
day(now()) 11
hour('2019-12-6 14:7:50')
minute('2019-12-6 14:7:50')
second('2019-12-6 14:7:50')
last_day('2019-12-6 14:7:50')
quarter('2016-04-28') 2
dayofweek('2019-7-10')
weekday('2019-7-10')
dayofyear('2019-7-10')
to_days('2019-12-6 14:7:50')
from_days(733627) 2008-08-08
day(last_day(now()))
date_add('2019-12-6 14:7:50',INTERVAL 1 day)
date_sub('2019-12-6 14:7:50',INTERVAL 1 day)
timestamp('2008-08-08')
avg(col)
count(*)
min(col) max(col)
sum(col)