-- 查询学生表SELECT id,username,sex,age FROM student;-- 获取所有字段的简单写法SELECT*FROM student;-- 插入数据-- 语法: insert into 表名称(字段1,字段2,....,字段N) values(字段1的值,字段2的值,......字段N的值)-- 场景:向student表中出入一条数据insertinto student(username,sex,age)values('赵六','男',18);-- 删除表数据所有数据的语法: delete from 表名称-- 注意:这个操作是一个危险的操作,删除后就回不来了(删除库跑路)-- 场景:删除student表的全部数据deletefrom student;-- sql的更新语法:update 表名称 set 字段名称1='新值1',字段名称2='新值2'-- 场景:将student表中的名字全部改为张三-- 更新语句也是一个危险的操作update student set username ='张三';-- 查询所有的男同学(单条件)SELECT*from student WHERE sex ='男';SELECT*from student WHERE age >=18;-- 多条件查询 and 或者 or-- 查询年龄大于17岁的所有男同学 (and多条件写法)SELECT*from student WHERE age >17and sex='男';-- 查询年龄为16岁或者18岁的同学(or多条件写法)SELECT*from student WHERE age =16or age =18;-- 模糊匹配-- 场景:查询名字中带有三字的所有同学SELECT*from student where username like'%三%';-- 查找名字中以疯结束的名字SELECT*from student where username like'%疯';-- 查找名字中以疯开始的名字SELECT*from student where username like'疯%';-- 查找年龄在15到18岁之间的学生SELECT*FROM student WHERE age BETWEEN15and18;-- 查询所有的同学,按年龄升序排序select*from student orderby age asc;select*from student orderby age;-- asc是默认的排序方式,可以省略不写-- 查询所有的同学,按年龄降序排序(一定要显示写DESC)select*from student orderby age DESC;-- 查询所有的男同学,按年龄升序排序SELECT*from student WHERE sex='男'orderby age asc;-- 从0索引开始,查询1条同学表数据SELECT*from student LIMIT0,1;# 从1 索引开始,查询1条同学表数据SELECT*from student LIMIT1,1;-- 从1索引开始,查询2条同学表数据SELECT*from student LIMIT1,2;#查询所有的同学,按年龄降序排序后,从0索引开始,查询1条数据# 分页算法 索引 = (当前页码 - 1) * 页容量SELECT*from student ORDERBY age descLIMIT0,1;#查询所有的男同学,按年龄降序排序后,从0索引开始,查询1条数据-- where关键字在前,order by 居中,limit最后SELECT*from student WHERE sex='男'ORDERBY age descLIMIT0,1;