/*查询studenttable表*/
select *from studenttable;
/* select 字段列表 from 表名列表 where条件列表 group by分组字段 having分组之后的条件 order by排序 limit分页限定*/
/*查询多个字段**/
select name,age from studenttable;
/*查询所有字段*/
select * from studenttable;
/*去除重复的结果集*/
select distinct name,age studenttable;
/*计算age和score分数之和*/
select name,age,score,age+score from studenttable;
/*如果有null参与运算,计算结果都为null ifnull(score,0)如果score为null,score=0*/
select name,age,score,age+ifnull(score,0) from studenttable;
/*起别名*/
select name 姓名,age 年龄,score 分数,age+ifnull(score,0) as 总分 from studenttable;*
select name 姓名,age 年龄,score 分数,age+ifnull(score,0) 总分 from studenttable;**
/*查询年龄大于20岁的*/
select *from studenttable where age>20;
/*查询年龄等于20岁的*/
select *from studenttable where age=20;
/*查询年龄不等于于20岁的 */
select *from studenttable where age!=20;*
select *from studenttable where age<>20;
/*查询年龄大于等于20,小于等于30*/
select * from studenttable where age>=20 && age<=30;
select * from studenttable where age>=20 and age<=30;*
select * from studenttable where age between 20 and 30;**
/*注意: null值不能使用 = (!=) 判断*/
/*查询年龄17,20岁的信息 in(集合)*/
select * from studenttable where age=17 or age=20;
select * from studenttable where age in (17,20);
/*注意: null值不能使用 = (!=) 判断*/
select * from studenttable where age=nulll;/*这条是不对的*/
select * from studenttable where age is nulll;
select * from studenttable where age is not nulll;
/*like:模糊查询 _:单个任意字符 %:多个任意字符*/
/*查询姓 '赵' 的有哪些人*/
select * from studenttable where name like '赵%';
/*查询姓名第二个字是 '敏' 的人*/
select * from studenttable where name like '_敏%';
/*查询姓名是三个字的人*/
select * from studenttable where name like '___';/*3个 _*/
/*查询姓名中包含 '敏' 的人*/
select * from studenttable where name like '%敏%';\
DQL 查询表(select的各种命令)
最新推荐文章于 2023-12-03 17:36:23 发布