2020.05.29

一天过去了,上午老师布置了要写测试总结,下午搞了下mysql的基础命令

查看数据库 show databases;
创建数据库 create database xxx;
删除数据库 drop database xxxx;
获取表结构 desc user;
查看表的字段 select * from user;
                     select user,host from uer;
给展示的数据库起别名 select user as ‘xxx’,host as ‘xxx’from user;
刷新权限 flush privileges;
创建数据表
CREATE TABLE xxx(
  -- 列名, 列描述(约束条件)
  id INTEGER PRIMARY KEY auto_increment,
  name VARCHAR(20) NOT NULL,
  age INTEGER,
  tel INTEGER NOT NULL,
  email VARCHAR(30),
  sex VARCHAR(2) NOT NULL,
  note VARCHAR(100)
);
查看信息 select * from xxxx;
插入数据 insert into score (stu_id,kemu,score,date) values (1,'language',100,'2020-01-10 14:00');
查看表数据多少 select count(*) from 表名;
单表数据分组查询 select stu_id as '学员ID',kemu as '科目',count(score) as '考试次数',avg(score) as '平均分',group_concat(score) as '成绩列表',
max(score) as '最大值',min(score) as '最小值' from score where kemu='maths' group by stu_id ;
分组 group by
查询表用分组来显示 select stu_id,avg(score) from score where kemu='maths' group by stu_id;
更改表中的数据 update list11 set age=33,email='[email protected]' where id=4;
 模糊查询
 select * from 表名 where tel like '139%';
 select * from 表名 where name regexp '小[红,灰]';
删除指定的一项 delete from 表名 where id=5;
删除一个表 drop table 表名 
清空表数据 delete form 表名;
查看数据表,给予别名
 select empno as "编号" , ename as "姓名", sal*12 as "年薪" from emp;
升序
select * from xx order by xx asc;
降序
select * from xx order by xx desc;

你可能感兴趣的:(2020.05.29)