From bd8ee6cea205a75ee64ce6bd19b089f06d99f379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=B5=A9?= <2643621434@qq.com> Date: Mon, 27 Mar 2023 13:36:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=BE=E6=B5=A9=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...50\345\255\220\346\237\245\350\257\242.md" | 320 ++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 "38 \346\233\276\346\265\251/20230322 \350\201\224\350\241\250\345\255\220\346\237\245\350\257\242.md" diff --git "a/38 \346\233\276\346\265\251/20230322 \350\201\224\350\241\250\345\255\220\346\237\245\350\257\242.md" "b/38 \346\233\276\346\265\251/20230322 \350\201\224\350\241\250\345\255\220\346\237\245\350\257\242.md" new file mode 100644 index 0000000..3717cd5 --- /dev/null +++ "b/38 \346\233\276\346\265\251/20230322 \350\201\224\350\241\250\345\255\220\346\237\245\350\257\242.md" @@ -0,0 +1,320 @@ +```mysql +create database test charset utf8; +use test; +create table price( + id int primary key auto_increment, -- 价格编号 + price double -- 水果价格 +); +insert into price values(1,2.30); +insert into price values(2,3.50); +insert into price values(4,null); +insert into price values(3,5.5); +create table fruit( + id int primary key auto_increment, -- 水果编号 + name varchar(20) not null, -- 水果名称 + price_id int, -- 价格编号 + foreign key(price_id) references price(id) +); +insert into fruit values(1,'苹果',1); +insert into fruit values(2,'橘子',2); +insert into fruit values(3,'香蕉',null); +-- 3.多表查询 +-- 3.1.笛卡尔积 + -- 需求:查询水果和价格信息 +select price,name from price as a left join fruit as b on a.id=b.id; +-- 3.2.内连接 +-- 避免笛卡尔积问题怎么处理? +select *from price as a inner join fruit as b on a.id=b.id; +-- 练习:查询苹果信息,显示苹果id和价格 +-- 分析:在水果表中可以查看苹果id 名字 ,在价格表中可以查看价格和价格id +select *from price as a inner join fruit as b on a.id=b.id where name='苹果'; +-- 3.3左外连接 +-- 练习:查询所有水果信息和对应价格信息 +-- fruit f 位于left左边,称为左表,左外连接以左表为主 +-- price p 位于left右边,称为右表 +-- f.* :获取fruit水果表中的所有数据 +-- p.price : 获取price价格表的字段price的值 +-- 练习:查询没有写价格的水果及价格(先查询所有水果的价格信息,再筛选。) +select name,b.id from price as a right join fruit as b on a.id=b.price_id where price is null; +-- 3.4右外连接 +-- 练习:使用右外连接查询所有价格对应的水果名称和价格信息, +select *from price as a right join fruit as b on a.id=b.price_id; +-- right join 表示右连接 +-- price p 称为右表 右外连接会查询右表即price表的全部数据以及和左表fruit f的交集 +-- 练习:查询出没有对应水果的价格编号和价格,水果名 +select price_id,name,price from price as a right join fruit as b on a.id=b.price_id where price_id is null; +-- 练习:使用左外连接查询价格对应的水果,显示所有价格 +select name,price from fruit as a left join price as b on a.price_id=b.id; + +CREATE TABLE dept ( + id INT PRIMARY KEY AUTO_INCREMENT, -- 部门编号 + NAME VARCHAR(20) -- 部门名称 + ); + + INSERT INTO dept (NAME) VALUES ('开发部'),('市场部'),('财务部'); + + -- 创建员工表 n + CREATE TABLE emp ( + id INT PRIMARY KEY AUTO_INCREMENT, + NAME VARCHAR(10), + gender CHAR(1), -- 性别 + salary DOUBLE, -- 工资 + join_date DATE, -- 入职日期 + dept_id INT, -- 部门编号 + foreign key(dept_id) references dept(id) + ); + + INSERT INTO emp(NAME,gender,salary,join_date,dept_id) VALUES('孙悟空','男',7200,'2013-02-24',1); + INSERT INTO emp(NAME,gender,salary,join_date,dept_id) VALUES('猪八戒','男',3600,'2010-12-02',2); + INSERT INTO emp(NAME,gender,salary,join_date,dept_id) VALUES('唐僧','男',9000,'2008-08-08',2); + INSERT INTO emp(NAME,gender,salary,join_date,dept_id) VALUES('白骨精','女',5000,'2015-10-07',3); + INSERT INTO emp(NAME,gender,salary,join_date,dept_id) VALUES('蜘蛛精','女',4500,'2011-03-14',1); + +-- 1.查询工资最高的员工是谁 + -- 1.1 在emp员工表中查询最高工资 -- 9000 单行单列 + -- 1.2在emp员工表中根据上述查询的最高工资查询员工信息 +select max(salary) from emp; +select emp.*,max(salary) from emp; +-- 2.查询工资小于平均工资的员工有哪些? + -- 2.1在emp员工表中查询平均工资 -- 单行单列 5860 +select avg(salary) from emp; + -- 2.2在emp员工表中查询小于上述的平均工资查询员工信息 +select *from emp where salary<(select avg(salary) from emp); +-- 3.查询工资大于5000的员工,来自于哪些部门,显示部门的名字 + -- 3.1 在员工表emp中查询工资大于5000的员工部门编号 -- 1 2 单列多值 作为子查询的条件使用in +select *from emp where salary>5000; + -- 3.2在dept部门表中根据上述查询的部门编号查询部门名字 +select b.name,b.id from emp as a left join dept as b on a.dept_id=b.id where salary>5000; +-- 4. 查询开发部与财务部所有的员工信息 + -- 4.1 在dept表查询开发部和财务部的部门编号 -- 1 3 多行单列 作为子查询的条件使用in +select b.id from emp as a left join dept as b on a.dept_id=b.id where b.id in (1,3); + -- 4.2在emp员工表中根据上述查询的部门编号查询员工信息 +select * from emp as a left join dept as b on a.dept_id=b.id where b.id in (1,3); +-- 5.查询出2011年以后入职的员工信息,包括部门名称 + -- 5.1在emp表中查询2011年以后入职的员工信息 -- 多行多列,作为子查询一般使用as起别名作为临时表和其他表查询. +select * from emp where join_date>'2011-%-%'; + -- 5.2 将上述查询的结果作为临时表和dept表关联查询最后查询员工信息和部门名称 +select * from dept as a left join (select * from emp where join_date>'2011-%-%') as b on a.id=b.dept_id ; + +create table teacher ( + id int(11) primary key auto_increment, -- 教师编号 + name varchar(20) not null unique -- 教师姓名 + ); + +-- 学生表 + create table student ( + id int(11) primary key auto_increment, -- 学生编号 + name varchar(20) NOT NULL unique, -- 学生姓名 + city varchar(40) NOT NULL, -- 学生城市 + age int -- 学生年龄 + ) ; + +-- 课程信息表 + create table course( + id int(11) primary key auto_increment, -- 课编号 + name varchar(20) not null unique, -- 课程名称 + teacher_id int(11) not null, -- 教师编号 + foreign key(teacher_id) references teacher (id) + ); + +-- 学生选课表 + create table studentcourse ( + student_id int NOT NULL, -- 学生编号 + course_id int NOT NULL, -- 课程编号 + score double NOT NULL, -- 考试成绩 + foreign key (student_id) references student (id), + foreign key (course_id) references course (id) + ); + + insert into teacher values(null,'关羽'); + insert into teacher values(null,'张飞'); + insert into teacher values(null,'赵云'); + + insert into student values(null,'小王','北京',20); + insert into student values(null,'小李','上海',18); + insert into student values(null,'小周','北京',22); + insert into student values(null,'小刘','北京',21); + insert into student values(null,'小张','上海',22); + insert into student values(null,'小赵','北京',17); + insert into student values(null,'小蒋','上海',23); + insert into student values(null,'小韩','北京',25); + insert into student values(null,'小魏','上海',18); + insert into student values(null,'小明','广州',20); + + insert into course values(null,'语文',1); + insert into course values(null,'数学',1); + insert into course values(null,'生物',2); + insert into course values(null,'化学',2); + insert into course values(null,'物理',2); + insert into course values(null,'英语',3); + + insert into studentcourse values(1,1,80); + insert into studentcourse values(1,2,90); + insert into studentcourse values(1,3,85); + insert into studentcourse values(1,4,78); + insert into studentcourse values(2,2,53); + insert into studentcourse values(2,3,77); + insert into studentcourse values(2,5,80); + insert into studentcourse values(3,1,71); + insert into studentcourse values(3,2,70); + insert into studentcourse values(3,4,80); + insert into studentcourse values(3,5,65); + insert into studentcourse values(3,6,75); + insert into studentcourse values(4,2,90); + insert into studentcourse values(4,3,80); + insert into studentcourse values(4,4,70); + insert into studentcourse values(4,6,95); + insert into studentcourse values(5,1,60); + insert into studentcourse values(5,2,70); + insert into studentcourse values(5,5,80); + insert into studentcourse values(5,6,69); + insert into studentcourse values(6,1,76); + insert into studentcourse values(6,2,88); + insert into studentcourse values(6,3,87); + insert into studentcourse values(7,4,80); + insert into studentcourse values(8,2,71); + insert into studentcourse values(8,3,58); + insert into studentcourse values(8,5,68); + insert into studentcourse values(9,2,88); + insert into studentcourse values(10,1,77); + insert into studentcourse values(10,2,76); + insert into studentcourse values(10,3,80); + insert into studentcourse values(10,4,85); + insert into studentcourse values(10,5,83); + + -- 1.查询获得最高分的学生信息。 + select c.*,max(score) from studentcourse as a left join course as b on a.course_id=b.id left join student as c on c.id=a.student_id; + -- 1.1 在中间表中查询最高分-- 95 单行单列 + select max(score) from studentcourse; + -- 1.2 在中间表中根据上述查询的最高分查询学生id 30 + -- 1.3在学生表中根据上述查询的学生id查询学生信息 -- 一个班级最高分95,可以有多名学员,结果有可能是多行多列 + select max(score),a.id from student as a right join studentcourse as b on a.id=b.student_id group by a.id; +-- 2.查询编号是2的课程比编号是1的课程最高成绩高的学生信息。 + select *from (select *from studentcourse where course_id=2) as a inner join (select *from studentcourse where course_id=1) as b on a.student_id=b.student_id where b.score>a.score; + -- 2.1在中间表查询课程编号是1的最高分数 -- 80 + select max(score) from studentcourse where course_id=1; + -- 2.2在中间表中查询课程编号是2并且分数大于上述结果的学生编号 -- 多行单列 + select *from studentcourse where course_id=2 and score>80; + -- 2.3 在学生表中根据上述查询的学生编号查询学生信息* + select student_id from studentcourse where course_id=2 and score>80; +-- 3.查询编号是2的课程比编号是1的课程最高成绩高的学生姓名和成绩。 + select *from (select *from studentcourse where course_id=2) as a inner join (select *from studentcourse where course_id=1) as b on a. student_id=b.student_id where a.score>b.score; + -- 3.1在中间表查询课程编号是1的最高分数 -- 80 + select max(score) from studentcourse where course_id=1 ; + -- 3.2在中间表中查询课程编号是2并且分数大于上述结果的学生编号和分数 -- 多行多列作为临时表 + select*from (select*from studentcourse where score>80 and course_id=2) as a; + -- 3.3 将上述查询的结果作为临时表 + select * from (select*from studentcourse where score>80 and course_id=2) as a; +-- 4.查询每个同学的学号、姓名、选课数、总成绩 + select*from student as a right join studentcourse as b on a.id=b.student_id left join course as c on c.id=b.course_id left join teacher as d on d.id=c.teacher_id ; + -- 4.1在中间表中根据学号分组查询学号 选课数 总成绩 -- 多行多列,作为临时表 + select count(a.name),sum(score) from course a right join studentcourse b on a.id=b.course_id group by a.name; + -- 4.2将上述查询的结果作为临时表和学生表进行关联查询 + select* from student right join (select * from course a right join studentcourse b on a.id=b.course_id group by a.name) as n on student.id=n.student_id; + + +CREATE TABLE deptt( + id INT PRIMARY KEY PRIMARY KEY, -- 部门id + dname VARCHAR(50), -- 部门名称 + loc VARCHAR(50) -- 部门位置 + ); + + -- 添加4个部门 + INSERT INTO deptt(id,dname,loc) VALUES + (10,'教研部','北京'), + (20,'学工部','上海'), + (30,'销售部','广州'), + (40,'财务部','深圳'); + + -- 职务表,职务名称,职务描述 + CREATE TABLE job ( + id INT PRIMARY KEY, -- 职务编号 + jname VARCHAR(20), -- 职务名称 + description VARCHAR(50) -- 职务简介 + ); + + -- 添加4个职务 + INSERT INTO job (id, jname, description) VALUES + (1, '董事长', '管理整个公司,接单'), + (2, '经理', '管理部门员工'), + (3, '销售员', '向客人推销产品'), + (4, '文员', '使用办公软件'); + + -- 员工表 + CREATE TABLE empp ( + id INT PRIMARY KEY, -- 员工id + ename VARCHAR(50), -- 员工姓名 + job_id INT, -- 职务id + mgr INT , -- 上级领导 + joindate DATE, -- 入职日期 + salary DECIMAL(7,2), -- 工资 + bonus DECIMAL(7,2), -- 奖金 + deptt_id INT, -- 所在部门编号 + CONSTRAINT emp_jobid_ref_job_id_fk FOREIGN KEY (job_id) REFERENCES job (id), + CONSTRAINT emp_deptid_ref_dept_id_fk FOREIGN KEY (deptt_id) REFERENCES deptt (id) + ); + + -- 添加员工 + INSERT INTO empp(id,ename,job_id,mgr,joindate,salary,bonus,deptt_id) VALUES + (1001,'孙悟空',4,1004,'2000-12-17','8000.00',NULL,20), + (1002,'卢俊义',3,1006,'2001-02-20','16000.00','3000.00',30), + (1003,'林冲',3,1006,'2001-02-22','12500.00','5000.00',30), + (1004,'唐僧',2,1009,'2001-04-02','29750.00',NULL,20), + (1005,'李逵',4,1006,'2001-09-28','12500.00','14000.00',30), + (1006,'宋江',2,1009,'2001-05-01','28500.00',NULL,30), + (1007,'刘备',2,1009,'2001-09-01','24500.00',NULL,10), + (1008,'猪八戒',4,1004,'2007-04-19','30000.00',NULL,20), + (1009,'罗贯中',1,NULL,'2001-11-17','50000.00',NULL,10), + (1010,'吴用',3,1006,'2001-09-08','15000.00','0.00',30), + (1011,'沙僧',4,1004,'2007-05-23','11000.00',NULL,20), + (1012,'李逵',4,1006,'2001-12-03','9500.00',NULL,30), + (1013,'小白龙',4,1004,'2001-12-03','30000.00',NULL,20), + (1014,'关羽',4,1007,'2002-01-23','13000.00',NULL,10); + + -- 工资等级表 + CREATE TABLE salarygrade ( + grade INT PRIMARY KEY, + losalary INT, -- 最低薪资 + hisalary INT -- 最高薪资 + ); + + -- 添加5个工资等级 + INSERT INTO salarygrade(grade,losalary,hisalary) VALUES + (1,7000,12000), + (2,12010,14000), + (3,14010,20000), + (4,20010,30000), + (5,30010,99990); + + -- 1.查询所有员工信息。显示员工编号,员工姓名,工资,职务名称,职务描述。 + -- 1.1 确定几张表关联查询:2张表 emp job + -- 1.2 确定连接查询的条件即避免笛卡尔积的条件 emp.job_id = job.id + -- 1.3 确定要查询的结果字段:员工编号,员工姓名,工资,职务名称,职务描述 +select * from empp left join job on empp.job_id=job.id; + +-- 2.查询所有员工信息。显示员工编号,员工姓名,工资,职务名称,职务描述,部门名称,部门位置 + -- 2.1 确定几张表关联查询:3张表 emp job dept + -- 2.2 确定连接查询的条件即避免笛卡尔积的条件 emp.job_id = job.id and emp.dept_id=dept.id + -- 2.3 确定要查询的结果字段:员工编号,员工姓名,工资,职务名称,职务描述,部门名称,部门位置 +select empp.id,ename,salary,jname,dname,loc from empp left join job on empp.job_id=job.id left join deptt on deptt.id=empp.deptt_id; + +/* + 连接查询规律: + 1.确定几张表关联 + 2.确定连接查询的条件 + 3.确定要查询的结果字段 + 4.如果是n张表关联,那么避免笛卡尔积的条件的个数是:n-1 + */ +-- 3.查询所有员工信息。显示员工姓名,工资,职务名称,职务描述,部门名称,部门位置,工资等级。 + -- 1.确定几张表关联 4张表 emp job dept salarygrade + -- 2.确定连接查询的条件 :emp.job_id = job.id and emp.dept_id=dept.id + -- 其他条件:e.salary between salarygrade.losalary and salarygrade.hisalary + -- 3.确定要查询的结果字段 +select *from empp left join job on empp.job_id=job.id left join deptt on deptt.id=empp.deptt_id left join salarygrade on salarygrade.grade=empp.job_id where salary between salarygrade.losalary and salarygrade.hisalary ; +-- 4.查询出每个部门的部门编号、部门名称、部门位置、部门人数 + -- 4.1 在emp表中按照部门编号分组查询部门编号和每个部门人数 + -- 4.2 几张表关联:dept 上述临时表 + -- 4.3 条件 dept.id和临时表的dept_id相等 + -- 4.4 分析查询的结果部门编号、部门名称、部门位置、部门人数 +select empp.id,ename,salary,jname,dname,loc,count(ename) 人数 from empp left join job on empp.job_id=job.id left join deptt on deptt.id=empp.deptt_id group by dname ; +``` \ No newline at end of file -- Gitee From ae01f096b6dd6273db404739d3886de8f9119f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=B5=A9?= <2643621434@qq.com> Date: Wed, 29 Mar 2023 12:08:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=BE=E6=B5=A9=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...27\347\254\246\344\275\234\344\270\232.md" | 92 +++++++++++++++++++ java-object-oriented-notes | 1 + 2 files changed, 93 insertions(+) create mode 100644 "38 \346\233\276\346\265\251/20230327 java\350\277\220\347\256\227\347\254\246\344\275\234\344\270\232.md" create mode 160000 java-object-oriented-notes diff --git "a/38 \346\233\276\346\265\251/20230327 java\350\277\220\347\256\227\347\254\246\344\275\234\344\270\232.md" "b/38 \346\233\276\346\265\251/20230327 java\350\277\220\347\256\227\347\254\246\344\275\234\344\270\232.md" new file mode 100644 index 0000000..c7436c5 --- /dev/null +++ "b/38 \346\233\276\346\265\251/20230327 java\350\277\220\347\256\227\347\254\246\344\275\234\344\270\232.md" @@ -0,0 +1,92 @@ +```java +import javax.security.sasl.SaslClient; +import java.util.Scanner; +public class hello { + public static void main(String[] args) { +// 1、判断一个字符数据是否是数字字符 +//**分析:** +//1、需要判断一个字符是否是数字字符,首先需要提供一个字符数据 +//2、字符是否为数字字符: 数字字符的范围 0 - 9 之间都属于数字字符,因此提供的字符只要大于或等于字符0,并且还要下于或等于字符9即可。 +//3、判断完成之后,打印判断的结果。 +//2、判断一个字符数据是否是字母字符** + Scanner sc = new Scanner(System.in); + System.out.println("请输入一个数字"); + String a= sc.next(); + char a1 = a.charAt(0); + if(a.length()==1){ + if (a1>=48&&a1<=57) { + System.out.println("是数字字符"); + } + }else{ + System.out.println("不是数字字符"); + } +//1、需要判断一个字符是否是字母字符,首先需要提供一个字符数据 +//2、字符是否为字母字符: 数字字符的范围 a - z 或者 A - Z 之间都属于字母字符, +// 因此提供的字符只要大于或等于a,并且还要下于或等于z 或者 大于或等于A,并且还要下于或等于Z + System.out.println("请输入一个字母或者数字"); + String b = sc.next(); + char c = b.charAt(0); + if (c >=97 && c<=122) { + System.out.println("是字母"); + } else { + System.out.println("不是字母"); + } +//3、判断完成之后,打印判断的结果。 +//3、判断指定的年份是否为闰年,请使用键盘录入** +//**分析:** +//1、闰年的判断公式为:能被4整除,但是不能被100整除 或者 能被400整除 +//2、首先需要提供一个需要判断的年份,判断完成之后,打印判断的结果。 + System.out.println("请输入一个年份"); + int d = sc.nextInt(); + if (d / 100 != 0) { + System.out.println("不是闰年"); + } else if (d / 4 == 0 && d / 400 == 0) { + System.out.println("是闰年"); + } +//**4、判断一个数字是否为水仙花数,请使用键盘录入** +//水仙花是指3位数字,表示的是每位上的数字的3次幂相加之后的和值和原数相等,则为水仙花数, +//**分析:** +//如:153 ---> 1×1×*1 + 5*×5×*5 + 3×*3×3 = 153; 就是水仙花数 +//1、首先需要提供一个需要判断的3位数字,因此需要一个数值 +//2、判断的过程 +//a) 将3位数字的每一位上的数字拆分下来 +//b) 计算每位数字的3次幂之和 +//C) 用和值 和 原来的数字进行比较 +//D) 打印判断的比较结果即可 + System.out.println("请输入一个数字(三位数)"); + int e = sc.nextInt(); + int eg = e % 10; + int es = e / 10 % 10; + int eb = e / 100 % 10; + int shx = eg * eg * eg + es * es * es + eb * eb * eb; + if (shx == e) { + System.out.println("是水花仙数"); + } else { + System.out.println("不是水花仙数"); + } +// **5、判断一个5位数字是否为回文数,使用键盘录入** +// 五位数的回文数是指最高位和最低位相等,次高位和次低位相等。如:12321 23732 56665 +//1、首先需要提供一个需要判断的5位数字,因此需要一个数值 +//2、判断的过程 +//a) 将5位数字的万、千、十、个位数拆分出来 +//b) 判断比较万位和个位 、 千位和十位是否相等 +//3、判断完成之后,打印判断的结果。 + System.out.println("请输入一个五位数"); + int h = sc.nextInt(); + int hg = h % 10; + int hs = h / 10 % 10; + int hb = h / 100 % 10; + int hq = h / 1000 % 10; + int hw = h / 10000; + if (hs == hq && hw == hg) { + System.out.println("是回文数"); + } else { + System.out.println("不是回文数"); + } + + } + } + + +``` + diff --git a/java-object-oriented-notes b/java-object-oriented-notes new file mode 160000 index 0000000..40181c2 --- /dev/null +++ b/java-object-oriented-notes @@ -0,0 +1 @@ +Subproject commit 40181c2538cc41f967cb73f70bba4395a4e0feb4 -- Gitee