select * from 表名 where id> 3 and gender=2;select * from 表名 where id> 3 or gender=2;
模糊查询
查询姓李的
select * from 表名 where name like "李%";
非连续范围查询
查询年龄为18和34的
select * from 表名 where age in(18, 34);
连续范围查询
查询年龄在18到34之间的
select * from 表名 where age between 18 and 34;
排序
select * from 表名 order by 字段名 升序 asc 降序 desc
聚合函数
总数
select count(*) from 表名;
求和
select sum(字段名) from 表名;
最大值
select max(字段名) from 表名;
最小值
select min(字段名) from 表名;
平均值
select avg(字段名) from 表名;
分组查询
select * from 表名 group by 字段名
分页查询
select * from 表名 limit 当前第几页, 每页显示多少数据
连接查询
内连接
select * from 表名1 inner join 表名2 on 表名1.字段名 = 表名2.字段名
左连接
select * from 表名1 left join 表名2 on 表名1.字段名 = 表名2.字段名
右链接
select * from 表名1 right join 表名2 on 表名1.字段名 = 表名2.字段名