DQL是数据库查询语言,就是我们平时最常用的查询的语句。
select完整语法
查询
select * from 表名 --查询表中所有数据
select 字段,字段 from 表名; --查询指定字段
给查出的数据加内容
select concat('姓名:',name) as 新名字 from 表名;
修改全部的查询结果
select score+1 from 表名; --表中查出的所有分数+1
通过别名查询
select 字段 as 别名,字段 as 别名 from 表名;
去重查询
去除查询结果中重复的数据
select distinct 字段 from 表名;
AND、OR、Not
--查询成绩在90-100之间的
select score from 表 where score>=90 and score<=100;
select score from 表 where score between 90 and 100;
--查询成绩为空的学生姓名
select name from student where score is null;
--查询成绩不为空的学生姓名
select name from student where score is not null;
模糊查询(like、in)
like + %(代表0到任意个字符)或 _(一个字符)
select name from student where name like '刘%'; --查询名字中姓刘的
select name from student where name like '刘_'; --查询名字姓刘且后面只有一个字的
in
--查询在河南的学生姓名
select name from student where address in ('河南');