DQL

DQL
查询数据
select * from student where clazz = '文科一班' and gender= '女' limit 1000;
select name 姓名,clazz as class from student limit 10;
select * from limit 6,10; 偏移量 分页
查询语句中你可以使用一个或者多个表,表之间用逗号(,)分割,并使用where语句来设定查询条件
select命令可以读取一条或者多条记录
可以使用*select语句会返回表的所有字段数据
可以使用where语句来包含任何条件
可以使用limit属性来设定返回的记录数
可以通过offset指定select语句开始查询的数据偏移量,默认情况下偏移量为0.


where子句 用于筛选过滤
select * from student where age <> 22 limit 10;不等于
select * from student where age between 21 and 23 limit 10;
select * from student where age in (21,23,25) limit 10;
select * from student where age%2=1 limit 10;
select * from student where age is null;
select id+10 as new_id from student;
select * from student where clazz in('文科一班','文科二班','文科三班');
模糊匹配 (使用%或_)
select * from student where clazz like '文科%' limit 10; 查询文科的学生信息
select * from student where name like '%雪%' limit10; 查询名字里含雪字的学生信息

基本select语句
SELECT [DISTINCT] *|{column1, column2. column3..}
FROM table;

select 指定查询哪些列的数据。
column指定列名。
*号代表查询所有列。大数据查询一般不使用。
from指定查询哪张表。
DISTINCT可选,指显示结果时,是否剔除重复数据

在select语句中可使用表达式对查询的列进行运算
SELECT *|{column1|expression, column2|expression,..}
FROM table;
例如:select name,age,age-2 as new_age from student limit 10;

在select语句中可使用as语句
select id,name,age,gender,clazz,1 as col1 from student limit 10;

做判断、常量使用
select 1 from student_info;加入新一列 常量
select 1=0;

posted @ 2022-07-04 11:32  吴少侠在江湖  阅读(100)  评论(0)    收藏  举报