Mysql数据库的简单操作03-函数增加数据 insert into 表名 values(1,'ss'),(null,'xx'),(null,'cc'); 更新数据 update 表名 set name=值 where ID=值; 删除数据 delete fron 表名 where id=""; 查看数据 select *from 表名 改字符集 set names 'gbk'; 备份数据库(作者王明昌发布时间2017-12-03最后更新2017-12-04文章目录统计count求和sum平均值avg最大最小值比较运算符逻辑运算符去重分组in() 和 not in()like 模糊查询limit排序order byunion多表查询子查询复制增加数据 insert into 表名 values(1,'ss'),(null,'xx'),(null,'cc'); 更新数据 update 表名 set name=值 where ID=值; 删除数据 delete fron 表名 where id=""; 查看数据 select *from 表名 改字符集 set names 'gbk'; 备份数据库(先退出数据库) mysqldump -uroot -proot sql3 >e:sql3.sql 还原数据库 mysql -uroot -proot < C:\backup.sql 备注 COMMENT '备注' 统计count复制select count(id) from score; 求和sum复制select sum(mat) from score; 平均值avg复制select avg(mat) from score; 最大最小值复制select max(mat) from score; select min(chinese)from score; 比较运算符复制select mat from score where mat>60; select * from score where mat>60; 逻辑运算符复制select *from score where mat>60 and chinese>60; select *from score where mat>60 or chinese >60; select *from score where mat!=90; 去重 distinct只能跟要去重的字段 #select distinct 去重字段 from 表名; 复制select distinct sex from stu; select distinct chinese from score; 分组 group by 复制select count(sex),sex from stu group by sex; +------------+-----+ | count(sex) | sex | +------------+-----+ | 6 | 0 | | 5 | 1 | +------------+-----+ in() 和 not in() 相当于或的关系 复制select * from score where chinese in (90,80,70,60); select *from score where chinese not in (50,90); like 模糊查询我% 前面匹配%我 后面匹配%我% 全匹配复制select *from score where chinese like '7%'; select *from score where chinese like '%7'; select *from score where chinese like '%7%'; limit limit限制显示个数,要放到最后 复制select *from score limit 6; select *from score limit 1, 6; +----+-----+---------+ | id | mat | chinese | +----+-----+---------+ | 2 | 55 | 70 | | 3 | 67 | 94 | | 4 | 56 | 90 | | 5 | 69 | 87 | | 6 | 89 | 43 | | 7 | 88 | 66 | +----+-----+---------+ 排序order by ==排序== 默认正序asc 倒序desc 复制select *from score order by id desc; select *from score order by mat desc; union UNION 操作符用于合并两个或多个 SELECT 语句的结果集。 复制SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2 多表查询复制select s.id,s.name,s.sex,sc.mat,sc.chinese from stu as s,score as sc where s.id=sc.id; 子查询复制大于平均值的 select *from score where mat >(select avg(mat) from score);
2017-12-04案例-多表查询、子查询实例(有答案)1.创建student和score表 CREATE TABLE student ( id INT(10) NOT NULL UNIQUE PRIMARY KEY , name VARCHAR(20)
2017-12-10案例-多表查询、子查询实例03(有答案)一、设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2
2017-12-06案例-多表查询、子查询实例02(有答案)以下所有操作在查询管理器中手工书写sql语句完成 1、按下列步骤创建数据库和表 1.2、在这个数据库中创建一个名为[学生表]的表,由[学号]、[姓名]、[专业]、[班级] 字段组成。[学号] 字段为主
2018-01-18mysql数据表同时使用创建时间/更新时间字段原因:一张表同时只能使用一个current_timestamp 创表 1. 用createtime记录创建时间 2. 用updatetime记录更新时间 create table test1(a va
2018-07-09MySQL 中TEXT的使用TINYTEXT 256 bytes TEXT 65,535 bytes ~64kb MEDIUMTEXT 16,777,215 bytes ~16MB LONGTEXT 4,294,967,295
2018-12-11mysql错误 | Error writing file‘frm‘(Errcode: 28)Error writing file‘frm‘(Errcode: 28) 磁盘空间不足引起的,删除一些没用的东西吧