mysql学习总结(二)

查询关键字
in
between and
like 通配符 % 匹配一个或者多个字符 _只匹配一个字符
and
or
distinct 去除重复行 select distinct col form table;
order by 排序 asc升序 desc 降序
group by 关键字分组查询
limit 限制结果数量

聚合函数查询
count()
非* 的参数,返回非NULL行的数目
参数是* 返回记录总数
select count(*) from table;
sum()
统计字段的总和
select sum(row) from table;
avg()
字段的平均值
select avg(row) from table;
max()
字段的最大值
select max(row) from table;
min()
字段的最小值
select min(row) from table;

内连接查询
select name,book from table1,table2 where table1.id=table2.id;
外连接查询
select col from table1 left | right join table2 on table1.id=table2.id;

子查询
in
select * from table where id in (select user from table1);
比较运算符
select id,book,row from where row >=(select row from table where id=1);
exists
select * from table where exists (select * from table1 where id=22);
any
select book,row from table where row < any(select row from table);
all
select book,row from table where row > all(select row from table);

合并查询结果
union
select user from table1
union
select user from table2;
union all (用法一致,有重复)

定义表和字段的别名
select * from table aaa where aaa.id=123;
aaa为表的别名
字段名 [as] 别名
select row as bbb,id as ccc from table;
row的别名是bbb,id的别名是ccc

使用正则表达式查询
字段名 regexp ‘’
select * from table where name regexp ‘[abcd]’;

猜你喜欢

转载自blog.csdn.net/qq_41027345/article/details/88045870