select * from user_tb;
比较运算符:
等于:= | 大于等于:>= | 不等于:!= 或者 <> |
---|---|---|
小于:< | is NULL | is not NULL |
逻辑运算符:
and or not
其它操作:
order by col [asc/desc] 按某列排序
limit [start, ]count 条件限制
limit 3; #限制输出3条记录
去重
select distinct * from user_tb; #去重查询出来的数据
模糊查询(like, %)
select * from user_tb where name like ‘李%’ ;
%代表任意多个字符,下划线_代表任意一个字符
范围查询
between a and b左闭右闭(连续) 返回
in (1,5,2) 罗列返回(间隔返回)
常用聚合函数:
count(字段) :统计个数
avg(字段):平均值
min max sum
group_concat(column) 列出字段全部值
group by分组
select class, group_concat(name) from student group by class;
聚合筛选,
having conditions;
别名 [as]
子查询
将一个查询的结果留下来用于下一次查询(select重嵌套select)
1)嵌套在查询语句内部
2)必须始终出现在圆括号内面
内连接
无条件内连接[inner ]join
有条件内连接
select *from student join detail_tb on student.id = detail_tb.id;
外连接
left join … on
right join … on