as关键字
为什么要使用as?
在使用SQL语句显示结果的时候,往往在屏幕上显示的字段名并不具备良好的可读性,此时可以使用as给字段起一个别名
①使用as给字段起别名
select id as 序号,name as 姓名, gender as 性别 from students;
②可以通过as给表起别名
–如果是单表查询可以省略表名
select id,name,gender from students;
–表名.字段名
select students.id,students.name,students.gender from students;
–可以通过as给表起别名
select s.id,s.name,s.gender from students as s;
distinct关键字
distinct 可以去重数据行
格式:select distinct 列1,… from 表名;
例:查询班级中学生的性别
select name,gender from students;
使用distinct关键字去重复查询
select distinct name,gender from students;
小结
as关键字可以给表中的字段 或者 表名起别名
在使用中as可以省略掉 good as g >> good g
distinct 关键字可以去重复数据行