1.DQL语法
select
字段列表
from
表名列表
where
条件列表
group by
分组字段列表
having
分组后条件列表
order by
排序字段列表
limit
分页参数
基本查询
条件查询(where)
聚合函数(count、max、min、avg、sum )
分组查询(group by)
排序查询(order by)
分页查询 (limit)
2.基础查询
1.查询指定字段
select 字段1,字段2,字段3 from 表名;
例:
select name,workno,age from employee;
2.查询所有字段返回
select 字段1,字段2,字段3 from 表名;
select * from 表名;
例:
select id,workno,name,gender,age,idcard,workaddress,entrydate from employee;
select * from employee;
3.设置别名
select 字段 as 别名 from 表名;
例:
select workaddress as '工作地址' from employee;
select workaddress as from employee;
4.去除重复记录
select distinct 字段列表 from 表名;
例:
select distinct workaddress '工作地址' from employee;
select distinct workaddress from employee;
3.条件查询
1.语法
select 字段列表 from 表名 where 条件列表;