一,数据类型:
整数类型:
tinyint 很小的整数
smallint 小的整数
mediumint 中等大小的整数
int 普通大小的整数
bigint 大整数
浮点类型:
float 单精度浮点数
double 双精度浮点数
decimal 定点数
时间类型:
year 年份
time 时分秒
date 年月日
datetime 年月日时分秒
timestamp 世界时间
字符串类型:
char 固定二进制
varchar 变长非二进制
tinytext 非常小的非二进制
text 小的非二进制
mediumtext 中等大小非二进制
longtext 大的非二进制
enum 枚举类型
set 可以去重排序
二进制类型:
bit 位字段类型
binary 固定长度二进制
varbinary 可变长度二进制
二,单表查询
2.1 查询所有字段:
select * from 表名;
2.2 查询制定字段:
select 字段名 from 表名;
2.3 查询制定记录:
select * from 表名 where (条件);
2.4 带 IN 关键字查询:
select * from 表名 where 字段名 IN (条件);
2.5 带 between and 范围查询;
select * from 表名 where 字段名 between 条件 and 条件;
2.6 带like字符查询:
" % ":作用是能匹配任意长度的字符(以....开头);
" _ ":只能匹配一个字符(以...结尾);
select * from 表名 where 字段名 like(条件);
2.7 查询空值:
select * from 表名 where 字段名 is null;(查询字段名是null的记录)
select * from 表名 where 字段名 is not null;(查询字段名不是null的记录)
2.8 带 and 多条件查询:
select * from 表名 where (条件)and (条件);
2.9 带 or 多条件查询:
select * from 表名 where (条件)or (条件);
2.10 关键字 distinct(查询结果不重复):
select distinct 字段名 from 表名;
2.11 对查询结果排序(order by):
select * from 表名 order by 字段名 asc;(默认升序);(默认升序)
select * from 表名 order by 字段名 desc;(降序)
2.12 分组查询(group by):
select * from 表名 group by 字段名;
count():计算有多少条记录;
group_count():将分组的值显示出来;
2.13 使用limit限制查询结果数量:
select * from 表名 limit (位置偏移量,个数)没有写位置偏移量,默认为0;
2.14 count()函数:
select count() from 表名;(计算个数);
2.15 sum()函数:
select count() from 表名;(计算总和);
2.16 avg()函数:
select count() from 表名;(计算平均数);
2.17 max()函数:
select count() from 表名;(计算最大值);
2.18 min()函数:
select count() from 表名;(计算最小值);