emp

2019.9.26学习内容及小结

孤街浪徒 提交于 2019-11-30 14:28:58
复习 ''' 1.单表查询 增删改查的完整语法 select distinct 字段 from 表 where group by having order by limit 比较: > < = 区间: between and | in | not in 逻辑: and or not 相似: like _% (一个 _ 代表 一个任意字符, % 代表不限制数量任意字符) 正则: regexp '.*[0-9]' 表示包含数字[0-9],用 not regexp '.*[0-9]' 就是不包含数字 聚合函数: group_concat()、max()、min()等;注:group_concat就是将字段合在一起,用于group by的拼接,用法和直接concat是一样的 也可以用于直接加上某条字段:group_concat(name) 名字, 来用于group by 后面没有字段的情况 having: 可以对 聚合函数 结果进行筛选,不能使用 聚合函数 别名 order by: 分组后对 聚合函数 进行排序,能使用 聚合函数 别名 limit: 条数 | 偏移量,条数 如limit(5,3), 过滤掉前五条数据,取出之后三条数据 2. 多表查询 内连接:from emp [inner] join dep on emp.dep_id = dep.id :只保留两表有对应关系的记录 左连接

第一阶段:Python开发基础 day45 数据库基础知识之子查询视图的相关操作事务和游标等

房东的猫 提交于 2019-11-30 13:36:29
目录 复习 案例 联合分组 子查询 all与any:区间修饰条件 视图:view 视图的增删改 事务 pymysql:python操作mysql 游标操作 pymysql事务 sql注入 索引 复习 """ 1、单表查询 增删改查的完整语法 select distinct 字段 from 表 where group by having order by limit 比较:> < = 区间:between and | in | not in 逻辑: and or not 相似:like _% 正则:regexp 聚合函数:group_concat()、max() having:可以对 聚合函数 结果进行筛选,不能使用 聚合函数 别名 order by:分组后对 聚合函数 进行排序,能使用 聚合函数 别名 limit:条数 | 偏移,条数 2、多表查询 内连接:from emp inner join dep on emp.dep_id = dep.id 只保存两表有对应关系的记录 左连接:from emp left join dep on emp.dep_id = dep.id 左表记录全部保存,右边没有对应记录空填充 右连接:from emp right join dep on emp.dep_id = dep.id 右表记录全部保存,左边没有对应记录空填充 全连接: from

子查询/联合分组/all与any/视图/事务

青春壹個敷衍的年華 提交于 2019-11-30 13:36:01
子查询 将一条查询sql的结果作为另一条sql的条件 使用方法总结: # 增:insert into 表 select子查询 # 删:delete from 表 条件是select子查询(表不能与delete表相同) # 查:select 字段 from 表 条件是select子查询 # 改:update 表 set 字段=值 条件是select子查询(表不能与update表相同) 联合分组: 按多个字段综合结果进行分组 使用方法总结: # 按 area与port组合后的结果进行分组,只有组合后的结果还一致,才认为是一组 select group_concat(name),area,port from emp group by area,port; 区间修饰条件(all与any): 使用方法总结: # 语法规则 # where id in (1, 2, 3) => id是1或2或3 # where id not in (1, 2, 3) => id不是1,2,3 # where salary < all(3, 6, 9) => salary必须小于所有情况(小于最小) # where salary > all(3, 6, 9) => salary必须大于所有情况(大于最大) # where salary < any(3, 6, 9) => salary只要小于一种情况(小于最大)

数据库

痞子三分冷 提交于 2019-11-30 13:35:33
目录 联合分组 子查询 all与any 视图:view 视图的增删改 事务 pymysql:python操作mysql 安装 增删改查 创建表 增 删 改 查 游标操作 pymysql事务 sql注入 索引 联合分组 # 数据来源:在单表emp下 # 联合分组:按多个字段综合结果进行分组 # 按 area与port 组合后的结果进行分组,只有组合后的结果还一致,才认为是一组 select group_concat(name),area,port from emp group by area,port; 子查询 # 增:insert into 表 select子查询 # 删:delete from 表 条件是select子查询(表不能与delete表相同) # 改:select 字段 from 表 条件是select子查询 # 查:update 表 set 条件是select子查询(表不能与delete表相同) # 数据来源:在单表emp下 # 子查询:将一条查询saql的结果作为另一条sql的条件 # 思考:每个部门最高薪资的那个人所有信息 # 子查询的sql select dep,max(salary) from emp group by dep; # 子查询 - 查 select * from emp where(dep,salary) in (select dep,max

Mysql基础知识

笑着哭i 提交于 2019-11-30 13:33:59
Mysql学习 """ 1、字段修改 alter modify alter change alter add ''|first|after alter drop 2、表关系: 一对一:外键存在两边都可以 一对多:外键存在多的一方 多对多:外键必须存在第三张关系表 外键:外键是表的一个字段,值可以重复也可以唯一,值是被关联表被关联字段的值,被关联字段必须有唯一键 foreign key(外键字段) references 被关联表(被关联字段) create table book( id int not null primary key auto_increment, name varchar(64) unique ); create table author( id int not null primary key auto_increment, name varchar(64) unique ); create table book_author( id int not null primary key auto_increment, book_name varchar(64), author_name varchar(64), foreign key(book_name) references book(name) on update cascade on delete

子查询

梦想的初衷 提交于 2019-11-30 13:33:29
一、什么是子查询     (1)一个查询的结果作为另一个查询的条件     (2)有查询的嵌套,内部的查询称为子查询     (3)子查询要使用括号 二、子查询的三种情况    (1)子查询的结果是单行单列         (2)子查询的结果是多行单列          (3)子查询的结果是多行多列      三、子查询的结果是一个值的时候    子查询结果只要是单行单列, 肯定在 WHERE 后面作为条件, 父查询使用: 比较运算符, 如: > 、 < 、 <> 、 = 等    语法格式: SELECT 查询字段 FROM 表 WHERE 字段=(子查询) ;    Demo:   (1)查询工资最高的员工是谁? 1 -- 1) 查询最高工资是多少 2 select max(salary) from emp; 3 -- 2) 根据最高工资到员工表查询到对应的员工信息 4 select * from emp where salary = (select max(salary) from emp);    (2)查询工资小于平均工资的员工有哪些? 1 -- 1) 查询平均工资是多少 2 select avg(salary) from emp; 3 -- 2) 到员工表查询小于平均的员工信息 4 select * from emp where salary < (select avg

Java this关键字详解

青春壹個敷衍的年華 提交于 2019-11-30 13:31:28
Java中this关键字在构造方法中的使用 Java this关键字详解 this 关键字用来表示当前对象本身,或当前类的一个实例,通过 this 可以调用本对象的所有方法和属性。例如: public class Demo { public int x = 10 ; public int y = 15 ; public void sum () { // 通过 this 点取成员变量 int z = this .x + this .y ; System .out . println ( "x + y = " + z ); } public static void main (String [] args ) { Demo obj = new Demo (); obj . sum (); } } 运行结果: x + y = 25 上面的程序中,obj 是 Demo 类的一个实例,this 与 obj 等价,执行 int z = this.x + this.y;,就相当于执行 int z = obj.x + obj.y;。 注意:this 只有在类实例化后才有意义。 使用this区分同名变量 成员变量与方法内部的变量重名时,希望在方法内部调用成员变量,怎么办呢?这时候只能使用this,例如: public class Demo { public String name ; public

过往练习

半城伤御伤魂 提交于 2019-11-30 13:29:55
案例 # 按指定编码创建数据库 create database 数据库名 charset="编码格式"; # 修改数据库编码 alter database 数据库名 charset="编码格式"; # 修改字段 alter table 库.表 modify 字段 类型(长度) 约束; alter table 库.表 change 旧字段 新字段 类型(长度) 约束; # 创建一个学生student表,有主键id字段,name唯一字段、age字段、height字段、mobile字段 create table student( id int not null auto_increment, name varchar(64) unique not null, age int unsigned default 0, height decimal(5,2) unsigned not null, mobile char(11), primary key(id), unique(name, mobile) ); truncate student; # 字段的增加 alter table 表名 add 字段 类型(长度) 约束 alter table 表名 add 字段 类型(长度) 约束 first alter table 表名 add 字段 类型(长度) 约束 after 已有字段 #

Java 从入门到进阶之路(六)

孤街浪徒 提交于 2019-11-30 12:59:33
之前的文章我们介绍了 Java 的数组,本章我们来看一下 Java 的对象和类。 Java 是一种面向对象语言,那什么是对象呢,对象在编程语言中属于一个很宽泛的概念,我们可以认为万事万物都是对象,每个对象都有其状态和行为,例如一只狗会有颜色,品种,性别等状态,也有跑,吃,睡等行为。 在编程语言中,会用一个类来承载这个对象,类是一个模板,它描述一类对象的行为和状态。 在之前的文章中我们没有引入对象的概念,如果我们想要打印输出一个人的基本信息,如下: 1 public class HelloWorld { 2 public static void main(String[] args) { 3 String name = "zhangsan"; 4 int age = 18; 5 String gender = "男"; 6 print(name,age,gender); // 姓名:zhangsan 年龄:18 性别:男 7 } 8 9 static void print(String name, int age, String gender) { 10 System.out.print("姓名:"+ name); 11 System.out.print("年龄:"+ age); 12 System.out.print("性别:"+ gender); 13 } 14 }

sql自带库高级查询相关例题

孤街浪徒 提交于 2019-11-30 12:50:23
1. 查询部门 20 的员工,每个月的工资总和及平均工资。 Select depnto,sum ( sal ),avg( sal ) from emp where deptno = 20 order by deptno 2. 查询工作在 CHICAGO 的员工人数,最高工资及最低工资。 Select count(distinct ename ),max( sal ),min( sal ) from Emp e,dept d where d.loc =('CHICAGO') and e.deptno = d.deptno 3. 查询员工表中一共有几种岗位类型。 Select deptno,sum ( sal ),avg( sal ) from emp where deptno = 20 order by deptno Select count(distinct ename ),max( sal ),min( sal ) from Emp e,dept d where d.loc =('CHICAGO') and e.deptno = d.deptno Select count(distinct job) from Emp 1. 查询部门 20 的员工,每个月的工资总和及平均工资。 Select depnto,sum ( sal ),avg( sal ) from emp where