mysql数据操作DQL(一):select单表查询
一.mysql单表查询select:
1>简单查询
简单查询
select * from 表名;
select 字段1,字段2,...字段n from 表名;
2> 避免重复distinct(通常使用于某个字段)
select distinct 字段1 from 表名;
3> 通过四则运算查询
select 字段1*12 from 表名;
select 字段1,字段2 as 新字段名 from 表名;(定义别名,逗号分隔要查询的字段名)
select 字段1*15 sannual_fee from 表名;(定义别名)
4>定义显示格式(将多个字段整合成一个字段显示)
concat()函数用于连接字符串
select concat(字段1,‘新字段名‘,字段2)as 别名;
二.条件查询
1.单条件查询
select 字段1,字段2,字段3 from 表名 where 条件1;
2.多条件查询(用and或者or连接)
select 字段1,字段2,字段3 from 表名 where 条件1 and 条件2;
3.关键字:between and(在某个区间内)
not between ...and....(不在某个区间内)
select 字段1,字段2 from 表 where 字段1 between 条件区间1 and 条件区间2;
4.关键字: is null(只能查找出来自己定义的null,手动添加的null不能查找出来)
is not null
5.关键字:in()
not in()
6.关键字:like 模糊查询
%匹配任意多个字符
_ 明确匹配字符串的数量