摘要:权限管理: 1.创建账号: #本地账号 create user 'egon1'@'localhost' identified by '123'; # mysql -uegon1 -p123 #远程账号 create user 'egon1'@'192.168.31.10' identified by
阅读全文
摘要:1 带IN关键字的子查询 2 带比较运算符的子查询 3 带EXISTS关键字的子查询 EXISTS关字键字表示存在。在使用EXISTS关键字时,内层查询语句不返回查询的记录。而是返回一个真假值。True或False当返回True时,外层查询语句将进行查询;当返回值为False时,外层查询语句不进行查
阅读全文
摘要:#查询平均年龄大于30岁的部门名 select department.name,avg(age) from employee inner join department on employee.dep_in = department.id group bydepartment.name having
阅读全文
摘要:内连接:只取两张表的共同部分 select * from employee inner join department on employee.dep_id = department.id; 左连接:在内连接的基础上保留左表的记录 select * from employee left join d
阅读全文
摘要:正则表达式: select * from employee where name like "jin%"; select * from employee where name regexp "^jin";
阅读全文
摘要:# 总结 语法顺序: select distinct 字段1,字段2,字段3,。。。from 库.表 where 条件 group by 分组条件 having 过滤 order by 排序字段 limit n; 执行顺序: from db.table > where 条件 > group by 分
阅读全文
摘要:order by 排序默认是id 升序排的! select * from employee order by age asc; (年龄从小到大排) select * from employee order by age desc; (年龄从大到小排) select * from employee o
阅读全文
摘要:#!!!执行优先级从高到低:where > group by > having #1. Where 发生在分组group by之前,因而Where中可以有任意字段,但是绝对不能使用聚合函数。 #2. Having发生在分组group by之后,因而Having中可以使用分组的字段,无法直接取到其他字
阅读全文
摘要:单独使用GROUP BY关键字分组 SELECT post FROM employee GROUP BY post; 注意:我们按照post字段分组,那么select查询的字段只能是post,想要获取组内的其他相关信息,需要借助函数 GROUP BY关键字和GROUP_CONCAT()函数一起使用
阅读全文
摘要:where字句中可以使用: 1. 比较运算符:> < >= <= <> !=2. between 80 and 100 值在10到20之间3. in(80,90,100) 值是10或20或304. like 'egon%' pattern可以是%或_, %表示任意多字符 _表示一个字符 5. 逻辑运
阅读全文
摘要:#简单查询 SELECT id,name,sex,age,hire_date,post,post_comment,salary,office,depart_id FROM employee; SELECT * FROM employee; SELECT name,salary FROM employ
阅读全文
摘要:增: 1.插入完整数据(顺序插入) 语法一: insert into 表名(字段1,字段2,字段3,。。。。。) values(值1,值2,值3,。。。。); 语法二: insert into 表名 values(值1,值2,值3,。。。。); 2.指定字段插入数据 语法: insert into
阅读全文
摘要:两种表之间的关系: 1.多对一 出版社 书 2.多对多 作者 书 3.一对一 客户 学生
阅读全文
摘要:foreign key #建立表之间的关系 建立表关系: 先建被关联表并且标准被关联的字段唯一 create table dep( id int primary key , name char(16), comment char(50) ); create table emp( id int pri
阅读全文
摘要:auto_increment # 自增长 create table t20( id int primeary key auto_increment, name char(16) ); 了解知识点: 查看参数 show variables like 'auto_inc%'; 步长 auto_incre
阅读全文
摘要:primary key (主键) 约束:not null unique (不为空且为唯一) 存储引擎(innodb): 对于innodb存储引擎来说,一张表内必须有一个主键 单列主键 create table t17( id int primary key, name char(16) ) 复合主键
阅读全文
摘要:unique key 单列唯一: 方式一: create table department( id int unique, name char(10) unique ); 方式二: create table department( id int, name char(10), unique(id),
阅读全文
摘要:create table t15 ( id int(11) unsigned zerofill ) create table t16( id int, name char(6), sex enum('male','female','other') not null default 'male' );
阅读全文
摘要:字符类型: 1.char:定长 2.varchar:变长
阅读全文
摘要:create table student( id int, name char(6), born_year year, #年格式如2018 birth_data data,#日期格式 如1981-11-12 class_time time,#时间格式 如10:10:10 reg_time datat
阅读全文