1、DQL基础用法:
 

 
2、实例:
 
(1)初始化表格:
 
# 创建表头
create table things(
    id int comment '编号',
    number int comment '学号',
    name char(5) comment '姓名',
    address char(6) comment '地址',
    `phone number` int comment '电话号',
    date char(4) comment '时间'
)comment '员工信息';
# 给表赋值
insert into things values
    (1,111,'lom','0x1231','1008611','2004'),
    (2,222,'kom','0x1123','1008622','2005'),
    (3,333,'jom','0x5531','1008633','2006'),
    (4,444,'hom','0x1531','1008644','2007'),
    (5,555,'gom','0x6631','1008655','2008'),
    (6,666,'fom','0x1663','1008666','2009'),
    (7,777,'dom','0x9611','1008677','2010'),
    (8,888,'som','0x8511','1008688','2011');
 

 
(2)查询指定字段:
 
基础语法:
 
select 字段名1,字段名2,…… from 表名;
 
 演示:
 
# 查询指定字段:(例:name和number)
select name,number from things;
 

 
(3)查询所有字段:
 
基础语法:
 
# 方法一
select 字段名1,字段名2,字段名3,…… from 表名;
# 方法二
select * from 表名;
 
 演示:
 
# 查询所有字段:(li)
select id,number,name,address,`phone number`,date from things;
 

 
(4)查询所有地址:
 
基础语法:
 
select 字段名 from 表名;
 
 演示:
 
# 查询所有地址
select address from things;
 

 
(5)在查询字段时,给字段起别名:
 
基础语法:
 
select 字段名 as 别名 from 表名;
 
 演示:
 
# 在查询所有员工的工作地址时,起别名
select address as '地址' from things;
 

 
(6)在查询某个字段的内容时,对其内容进行去重操作:
 
基础语法:
 
select distinct 字段名 '别名' from 表名;
 
演示:
 
# 去掉重复数据
select distinct address '工作地址' from things;