当前位置:Gxlcms > 数据库问题 > MYSQL数据库常用语句

MYSQL数据库常用语句

时间:2021-07-01 10:21:17 帮助过:22人阅读

int, name varchar(20), age int );

 


10.查看表定义信息

show create table student;
11.数据库的增、删、改(这里我是在图形化软件dataGrip里添加的数据)

/*增*/
insert into student(`num`,`name`,`age`,`class`,`math`) values (3,"赵子龙",20,3,100);
/*删*/
delete from student where name = "张三";
/*改*/
update student set age = 100 , num = 6 where name = "赵子龙";
12.数据库的查询(比较多)

/*查询表所有数据*/
select * from student;
/*查询表带条件数据*/
select * from student where age = 100;
/*查询表某个字段数据*/
select age,name from student;
/*查询表数据总数*/
select count(1) from student;
/*查询表数据带条件数目*/
select count(1) from student where age = 20 and class = 2; /*且*/
select count(1) from student where age = 20 or class = 2; /*或*/
/*查询表数据所有人数带条件(age)总和*/
select sum(age) from student;
/*查询表数据带条件(age)的平均数*/
select avg(age) from student;
/*查询表数据带条件(age)的平均数并且改名(as)为age_avg*/
select avg(age) as age_avg from student;
/*查询表数据按条件(class)进行分组求总数*/
select count(1) from student from group by class;
13.数据库分页查询

/*按10个一页查询第二页数据*/
select * from student limit 10,2;
/*按正序排*/
select * from student order by id;
/*按倒序排*/
select * from student order by id desc;
 
---------------------

MYSQL数据库常用语句

标签:databases   student   连接数   tag   math   tab   school   rip   tables   

人气教程排行