DQL 查询表中的记录
1、select * from 表名;
1、语法:
select
字段列表
from
表名列表
where
条件列表
group by
分组字段
having
分组之后的条件
order by
排序
limit
分页限定;
2、基础查询:
1、多个字段的查询
2、去除重复
3、计算列
4、起别名
-
查询姓名和年龄:
select name,age from student; select address form student;
-
去除重复字符集:
select distinct address from student;
-
计算math 和English的之和
select name,math,english from table; select name,math,english, math + english from table; -- 如果有null的运算都是null,用ifnull来处理 select name,math,english,math + ifnull(english,0) from table;
-
起别名
select name,math,english,math + ifnull(english,0) as 总分 from student3; SELECT NAME,math,english, math + IFNULL(english,0) 总分 FROM student3;