成都10班-向淦 发表于 2021-11-22 21:41:32

select * from student order by age asc;
order by 用于排序的关键字,对年龄进行从小到大进行排序

select * from student where class in(1833,1834)
查询班级在1833和1834里面的信息,功能和class=1833 or class=1834一样

select * from student where id limit 5;
查询前5行


select * from student where name=‘zhangsan’and class=1833;
查询姓名为zhangsan,班级为1833班的信息,and两边可以接两个字段等于具体值

select sum(math) from student;
查询student表数学成绩总分

select avg(math)from student;
查询student表平均数学成绩

select max(math)from student;
查询student表最大数学成绩

select * from student where class is not null;
查询班级不为空的信息

mysqldump -uroot -p123456 dcs10>/dcs10.sql
在Linux操作界面进行对dcs10数据库的备份,备份之后形成一个名为dcs10.sql的脚本,并在根目录下

insert into student1 select * from student;
备份数据往student1表里插入数据,插入的数据来源是从student表查询出来的所有数据

select * from student where name like ‘%ao%’;
查询姓名中包含ao的信息

use dcs10_back;
进入到dcs10_back数据库里,

show tables;
查看是否有还原的三张表

select * from student where class=NULL;
查询班级为空,不能用等于,空时空属性,不是具体的值

select * from student where class is null;
查询班级为空的信息,为空用 is

create database dcs10_back;
备份好数据库之后,接下来是还原数据库操作。在还原之前,先进入到mysql交互界面创建一个dcs10_back空库

select class,sum(math)as s from student group by class having s >100;
给聚合函数取别名的方式


页: [1]
查看完整版本: