diff --git "a/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DCL.txt" "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DCL.txt" new file mode 100644 index 0000000000000000000000000000000000000000..ba61331beed3d0d488abeacdf696cef1ef426113 --- /dev/null +++ "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DCL.txt" @@ -0,0 +1,22 @@ +==========DCL========== +--------------------------- +--->>>管理用户<<<--- +1.查询用户: +USE mysql; +SELECT * FROM user; +2.创建用户: +CREATE USER '用户名'@'主机名' IDENTIFIED BY '密码'; +3.修改用户密码: +ALTER USER '用户名'@'主机名' IDENTIFIED WITH mysql_native_password BY '新密码'; +4.删除用户: +DROP USER '用户名'@'主机名'; +--------------------------- +--->>>权限控制<<<--- +1.查询权限 +SHOW GRANTS FOR '用户名'@'主机名'; +2.授权权限 +GRANT 权限列表 ON 数据库名.表名 TO '用户名'@'主机名'; +3.撤销权限 +REVOKE 权限列表 ON 数据库名.表名 FROM '用户名'@'主机名'; +--------------------------- +======================= \ No newline at end of file diff --git "a/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DDL.txt" "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DDL.txt" new file mode 100644 index 0000000000000000000000000000000000000000..f86d0062f88fbd0991d2d9d07fe27f6abc1aac5b --- /dev/null +++ "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DDL.txt" @@ -0,0 +1,80 @@ +==========DDL========== +--------------------------- +>>>数据库操作-创建<<< +1.查询所有数据库: +SHOW DATABASES; +2.查询当前数据库: +SELECT DATABASES(); +3.创建: +CREATE DATABASE [IF NOT ESISTS] 数据库名 [DEFAULT CHARSET 字符集] [COLLATE 排序规则]; +4.删除: +DROP DATABASE [IF EXISTS] 数据库名; +5.使用: +USE 数据库名; +--------------------------- +>>>表操作-创建<<< +6.CREATE TABLE 表名( + 字段1 类型[COMMENT 字段1注释], + 字段2 类型[COMMENT 字段2注释], + 字段3 类型[COMMENT 字段3注释], + 字段n 类型[COMMENT 字段n注释] +)[COMMENT 表注释]; +表操作-查询 +7.查询当前数据库所有表: +SHOW TABLES; +8.查询表结构: +DESC 表名; +9.查询指定表的建表语句: +SHOW CREATE TABLE 表名; +---------------------------- +>>>表操作-修改<<< +10.往表里添加字段: +ALTER TABLE 表名 ADD 字段名 类型(长度) [COMMENT 注释] [约束]; +11.修改指定字段的类型: +ALTER TABLE 表名 MODIFY 字段名 新数据类型(长度); +12.修改字段名和字段类型: +ALTER GHANGE 旧字段名 新字段名 类型(长度) [COMMENT 注释] [约束]; +13.删除字段: +ALTER 表名 DROP 字段名; +14.修改表名: +ALTER TABLE 表名 RENAME TO 新表名; +--------------------------- +>>>表操作-删除<<< +15.删除表: +DROP TABLE [IF EXISTS] 表名; +16.删除指定表,并重新创建该表: +TRUNCATE TABLE 表名; (删除表内数据) +--------------------------- +数值类型 +TINYINT 1 byte 小整数值 +SMALLINT 2bytes 大整数值 +MEDIUMINT 3bytes 大整数值 +INT或INTEGER 4bytes 大整数值 +BIGINT 8bytes 极大整数值 +FLOAT 4bytes 单精度浮点数值 +DOUBLE 8bytes 双精度浮点数值 +DECIMAL 需要精度和标度的值 小数值(精确点数) +例子: +age TINYINT UNSIGNED (无负数) +score double(4,1) +--------------------------- +字符串类型 +CHAR 长字符串 +VARCHAR 变长字符串 +TINYBLOB 不超过255个字符的二进制数据 +TINYTEXT 短文本字符串 +BLOB 二进制形式的长文本数据 +TEXT 长文本数据 +MEDIUMBLOB 二进制形式的中等长度文本数据 +MEDIUMTEXT 中等长度文本数据 +LONGBLOB 二进制形式的极大文本数据 +LONGTEXT 极大文本数据 +--------------------------- +日期类型 +DATE 3 +TIME 3 +YEAR 1 +DATETIME 8 +TIMESTAMP 4 +--------------------------- +======================= \ No newline at end of file diff --git "a/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DML.txt" "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DML.txt" new file mode 100644 index 0000000000000000000000000000000000000000..2c0640e66e6cbe861b1379c921c620cd80d72b69 --- /dev/null +++ "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DML.txt" @@ -0,0 +1,18 @@ +==========DML========== +--------------------------- +>>>添加数据<<< +1.给指定字段添加数据 +INSERT INTO 表名 (字段名1,字段名2,...) VALUES(值1,值2,...); +2.给全部字段添加数据 +INSERT INTO 表名 VALUES (值1,值2,...); +3.批量添加数据 +INSERT INTO 表名 (字段名1,字段名2,...) VALUES (值1,值2,...),(值1,值2,...),(值1,值2,...); +INSERT INTO 表名 VALUES (值1,值2,...),(值1,值2,...),(值1,值2,...); +--------------------------- +>>>修改数据<<< +4.UPDATE 表名 SET 字段名 1=值1,字段名2=值2,...[WHERE 条件]; +--------------------------- +>>>删除数据<<< +4.DELETE FROM 表名 [WHERE 条件]; +--------------------------- +======================= \ No newline at end of file diff --git "a/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DQL.txt" "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DQL.txt" new file mode 100644 index 0000000000000000000000000000000000000000..a4c56a67303fcedc4271a7e5591d2d138fc4d24b --- /dev/null +++ "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/SQL-DQL.txt" @@ -0,0 +1,45 @@ +==========DQL========== +--------------------------- +聚合函数(count、max、min、avg、sum) +SELECT 聚合函数(字段列表) FROM 表名; +count 统计数量 +max 最大值 +min 最小值 +avg 平均值 +sum 求和 +--------------------------- +1.基本查询: +SELECT 字段列表 +FROM 表名列表 +2.条件查询: +WHERE 条件列表 +3.分组查询: +GROUP BY 分组字段列表 +HAVING 分组后条件表 +4.排序查询: +ORDER BY 排序字段列表 +5.分页查询: +LIMIT 分页参数 +--------------------------- +基本查询: +1.查询多个字段 +SELECT 字段1,字段2,字段3... FROM 表名; +SELECT * FROM 表名; +2.设置别名 +SELECT 字段1 [AS 别名1],字段2 [AS 别名2]... FROM 表名; +3.去除重复记录 +SELECT DISTINCT 字段列表 FROM 表名; +--------------------------- +条件查询: +SELECT 字段列表 FROM 表名 SHERE 条件列表; +--------------------------- +分组查询: +SELECT 字段列表 FROM 表名[WHERE 条件] GROUP BY 分组字段名 [HAVING 分组后过滤条件]; +--------------------------- +排序查询: +SELECT 字段列表 FROM 表名 ORDER BY 字段1 排序方式1,字段2 排序方式2; +--------------------------- +分页查询: +SELECT 字段列表 FROM 表名 LIMT 起始索引,查询记录数; +--------------------------- +======================= \ No newline at end of file diff --git "a/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\344\272\213\345\212\241.txt" "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\344\272\213\345\212\241.txt" new file mode 100644 index 0000000000000000000000000000000000000000..7d1961f33385457e3daff6d7f8922c6393de46f7 --- /dev/null +++ "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\344\272\213\345\212\241.txt" @@ -0,0 +1,42 @@ +==========事务========== +--------------------------- +--->>>事务操作<<<--- +开启事务: +SELECT @@autocommit; +SET @@autocommit = 0; +START TRANSACTION 或 BEGIN; +回滚事务: +ROLLBACK; +提交事务: +COMMIT; +--------------------------- +--->>>事务四大特性(ACID)<<<--- +原子性: +事务是不可分割的最小操作单元,要么全部成功,要么全部失败。 +一致性: +事务完成时,必须使所有的数据都保持一致状态。 +隔离性: +数据库系统提供的隔离机制,保证事务在不受外部并发操作影响的独立环境下运行。 +持久性: +事务一旦提交或回滚,它对数据库中的数据的改变就是永久的。 +--------------------------- +--->>>并发事务问题<<<--- +脏读: +一个事务读到另外一个事务还没有提交的数据。 +不可重复读: +个事务先后读取同一条记录,但两次读取的数据不同,称之为不可重复读。 +幻读: +一个事务按照条件查询数据时,没有对应的数据行,但是在插入数据时,又发现这行数据已经存在,好像出现了 +幻影”。 +--------------------------- +--->>>事务隔离级别<<<--- +Read uncommitted (读未提交) +Read committed (读已提交) +Repeatable Read (可重复读) mysql默认 +Serializable (串行化) +查看事务隔离级别: +SELECT @@TRANSACTION_ISOLATION; +设置事务隔离级别: +SET [SESSION | GLOBAL] TRANSACTION LEVEL {READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE} +--------------------------- +======================= \ No newline at end of file diff --git "a/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\345\207\275\346\225\260.txt" "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\345\207\275\346\225\260.txt" new file mode 100644 index 0000000000000000000000000000000000000000..b70ad403babaeaeb6c3de9ef3db649ce4cc97eb5 --- /dev/null +++ "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\345\207\275\346\225\260.txt" @@ -0,0 +1,64 @@ +==========函数========== +--------------------------- +--->>>字符串函数<<<--- +-- concat //字符串拼接 +select concat('Hello','MySQL'); +-- lower //全部转为小写 +select lower('HELLO'); +-- upper //全部转为大写 +select upper('Hello'); +-- lpad //左填充 +select lpad('01', 5, '-'); +-- rpad //右填充 +select rpad('01', 5, '-'); +-- trim //去掉字符串头部和尾部的空格 +select trim(' Hello MySQL'); +-- substring //返回从字符串str从start位置起的len个长度的字符串 +select substring('Hello MySQL',1,5) +--------------------------- +--->>>数值函数<<<--- +-- ceil //向上取整 +select ceil(1.5); +-- floor //向下取整 +select floor(1.1); +-- mod //取模 +select mod(5,4); +-- rand //返回0~1的随机数 +select rand(); +-- round //四舍五入 +select round(1.55,1); +--------------------------- +--->>>日期函数<<<--- +-- curdate() //当前日期 +select curdate(); +-- curtime() //当前时间 +select curtime(); +-- now() //当前日期时间 +select now(); +-- YEAR,MONTH,DAY //年 月 日 +select year(now()); +select month(now()); +select day(now()); +-- date_add //往后推七十天 +select date_add(now(), interval 70 day); +-- datediff //两个日期的差值 +select datediff('2021-12-01','2021-10-01'); +--------------------------- +--->>>流程控制函数<<<--- +-- if //如果为true返回第一个,如果为false返回第二个 +select if(false, 'ok', 'Error'); +-- ifnull //如果为null返回第二个 +select ifnull('ok', 'Default'); +select ifnull(null, 'Default'); +-- case [...] when ... then ... else ... end //条件分支的判断 +select name, + score, + (case + when score >= 85 then '优秀' + when score < 85 and score >=70 then '良好' + when score < 70 and score >= 60 then '及格' + when score < 60 then '不及格' + else '数据有误' end) as '等级' +from user; +--------------------------- +======================= \ No newline at end of file diff --git "a/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\345\244\232\350\241\250\346\237\245\350\257\242.txt" "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\345\244\232\350\241\250\346\237\245\350\257\242.txt" new file mode 100644 index 0000000000000000000000000000000000000000..6adf0652aaa5ecc3fd7dba1fd89419ecf0596a2a --- /dev/null +++ "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\345\244\232\350\241\250\346\237\245\350\257\242.txt" @@ -0,0 +1,154 @@ +==========多表查询========== +--------------------------- +1.多表关系 +2.多表查询概述 +3.内连接 +4.外连接 +5.自连接 +6.子查询 +7.多表查询案例 +--------------------------- +--->>>多表关系<<<--- +一对多(多对一) +多对多 +一对一 +--------------------------- +--->>>多表查询概述<<<--- +-- 多表查询 -- 笛卡尔积 +select * +from users as user, + dept +where user.def_id = dept.id ; +--------------------------- +--->>>内连接<<<--- +隐式内连接: +SELECT 字段列表 FROM 表1,表2,WHERE 条件...; +显示内连接: +SELECT 字段名称 FROM 表1 [INNER] JOIN 表2 ON 连接条件...; +--------------------------- +--->>>外连接<<<--- +左外连接: +SELECT 字段列表 FROM 表1 LEFT [OUTER] JOIN 表2 ON 条件; +右外连接: +SELECT 字段列表 FROM 表1 RIGHT [OUTER] JOIN 表2 ON 条件; +--------------------------- +--->>>自连接<<<--- +自连接查询: +SELECT 字段列表 FROM 表A 别名 A JOIN 表A 别名 B ON 条件...; +联合查询: +SELECT 字段列表 FROM 表A +UNION [ALL] +SELECT 字段列表 FROM 表B ...; +--------------------------- +--->>>子查询<<<--- +嵌套查询(子查询): +SELECT * FROM t1 WHERE column1 = (SELECT column FROM t2) +1.标量子查询: +select * +from users s +where s.def_id = (select id + from dept + where name = '销售部'); +2.列子查询: +select * +from users a +where a.def_id in (select id + from dept + where name = '销售部' + or name = '市场部'); +3.行子查询: +select * +from users b +where (b.money, b.managerid) = (select a.money, a.managerid from users a where name = '张无忌'); +4.表子查询: +-- 1.查询与“张无忌”"方东白”的职位和薪资相同的员工信息 +select * +from users b +where (b.managerid, b.money) in (select a.managerid, a.money + from users a + where name in ('张无忌', '方东白')); +-- 2.查询入职日期是“2024-01-25”之后的员工信息,及其部门信息 +select e.*,d.* +from (select * + from users a + where a.entrydate > '2024-01-24') e + left join dept d on e.def_id = d.id; +--------------------------- +--->>>多表查询案例<<<--- +-- 多表查询案例 +-- 1.查询员工的姓名、年龄、部门信息(隐式内连接) +select u.name, u.age, d.name +from users u, + dept d +where u.def_id = d.id; +-- 2.查询年龄小于20岁的员工的姓名、年龄、职位、部门信息(显式内连接) +select u.name, u.age, d.name +from users u + inner join dept d on u.def_id = d.id +where u.age < 20; +-- 3.查询拥有员工的部门ID、部门名称 +select distinct u.def_id, d.name +from users u, + dept d +where u.def_id = d.id; +-- 4.查询所有年龄大于20岁的员工,及其归属的部门名称;如果员工没有分配部门,也需要展示出来 +select u.*, d.name +from users u + left outer join dept d on u.def_id = d.id +where u.age > 20; +-- 5.查询所有员工的工资等级 +select u.*, s.grade, s.losal, s.hisal +from users u, + salgrade s +where u.money between s.losal and s.hisal; + +select u.*, s.grade, s.losal, s.hisal +from users u, + salgrade s +where u.money >= s.losal + and u.money <= s.hisal; +-- 6.查询“研发部”所有员工的信息及工资等级 +select u.*, s.grade +from users u, + salgrade s, + dept d +where u.def_id = d.id + and (u.money between s.losal and s.hisal) + and d.name = '研发部'; + +-- 7.查询“研发部”员工的平均工资 +select avg(u.money) +from users u, + dept d +where u.def_id = d.id + and d.name = '研发部'; +-- 8.查询工资比“张无忌”高的员工信息。 +select * +from users +where money > (select u.money + from users u + where name = '张无忌'); +-- 9.查询比平均薪资高的员工信息 +select * +from users +where money > (select avg(money) from users); + +-- 10.查询低于本部门平均工资的员工信息 + +select *, + (select avg(u1.money) + from users u1 + where u1.def_id = u2.def_id) '平均薪资' +from users u2 +where u2.money < (select avg(u1.money) + from users u1 + where u1.def_id = u2.def_id); +-- 11.查询所有的部门信息,并统计部门的员工人数 +select d.id, + d.name, + (select count(*) + from users u + where u.def_id = d.id) '人数' +from dept d; +--------------------------- +======================= \ No newline at end of file diff --git "a/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\347\272\246\346\235\237.txt" "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\347\272\246\346\235\237.txt" new file mode 100644 index 0000000000000000000000000000000000000000..8b359805f0498e7b6a9d6fb514a520c904573fcf --- /dev/null +++ "b/my-mysql/mysql\345\237\272\347\241\200\347\257\207/\347\272\246\346\235\237.txt" @@ -0,0 +1,31 @@ +==========约束========== +--------------------------- +1.非空约束:not null +2.唯一约束:unique +3.主键约束:primary key (auto_increment) +4.默认约束:default +5.检查约束:check +6.外键约束:foreign key +--------------------------- +create table users +( + id int primary key auto_increment comment '主键', /*主键并且自动增长*/ + name varchar(10) not null unique comment '姓名', /*不为空并且唯一*/ + age int check ( age > 0 and age<=120 ) comment '年龄', /*大于0,并且小于等于120*/ + status char(1) default '1' comment '状态', /*如果没有指定该值,默认为1*/ + gender char(1) comment '性别' +) comment '用户表'; +--------------------------- +--->>>外键约束<<<--- +添加外键: +CREATE TABLE 表名( + 字段名 数据类型, + ... + [CONSTRAINT] [外键名称] FOREIGN KEY (外键字段名) REFERENCES 主表 (主表列名) +) + +ALTER TABLE 表名 ADD CONSTRAINT 外键名称 FOREIGN KEY (外键字段名) REFERENCES 主表 (主表列名) +删除外键: +ALTER TABLE 表名 DROP FOREIGN KEY 外键名称; +--------------------------- +======================= \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_47_\350\224\241\347\216\256\351\223\255.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_47_\350\224\241\347\216\256\351\223\255.docx" new file mode 100644 index 0000000000000000000000000000000000000000..ccc27b8e3c933333743406b668927a2eb4c4e9dd Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_47_\350\224\241\347\216\256\351\223\255.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\273\243\347\240\201.txt" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\273\243\347\240\201.txt" new file mode 100644 index 0000000000000000000000000000000000000000..b8e89324e088ad9be9b38ec0095d887d1e29dcd6 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\273\243\347\240\201.txt" @@ -0,0 +1,44 @@ +create table if not exists student_info( + student_name varchar(255) comment'学生姓名', + student_sex char(1) comment'学生性别', + student_age int(3) comment'学生年龄', + student_birthday datetime comment'学生生日', + student_address varchar(255) comment'学生住址', + student_class varchar(255) comment'学生所属班级' +) comment'学生信息表'; + +insert into student_info(student_name,student_sex,student_age,student_birthday,student_address,student_class) values +('刘小东',1,24,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',2); + +insert into student_info(student_name,student_sex,student_age,student_birthday,student_address) values +('黄龙辉',1,25,'1999-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区'); + +insert into student_info(student_name,student_sex,student_age,student_birthday,student_address,student_class) values +('陈丽',2,24,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区',1), +('林小松',1,22,'2002-03-09','云南省昆明市五华区华山街道华山小区',1), +('舒燕',2,22,'2002-07-09','福建省龙岩市新罗区万宝社区',2); + +insert into student_info(student_name,student_sex,student_age,student_address,student_class) values +('王海欣',2,22,'福建省龙岩市新罗区东肖社区',1); + +insert into student_info(student_name,student_sex,student_age,student_birthday,student_class) values +('吴韦林',1,24,'2000-06-09',3); + +insert into student_info(student_name,student_sex,student_age,student_birthday,student_address,student_class) values +('欧阳武',1,20,'2004-07-15','陕西省西安市雁塔区雁塔社区',3); + +create table if not exists course_info( + course_id int comment'课程ID', + course_name varchar(255) comment'课程名称', + course_credit float comment'课程学分' +) comment'课程学分表'; + +insert into course_info(course_id,course_name,course_credit) values +(1,'数据库高级应用',3), +(2,'javascript编程基础',3); + +insert into course_info(course_id,course_name) values +(3,'web前端程序设计基础'); + +insert into course_info(course_id,course_name,course_credit) values +(4,'动态网页设计.net基础',6); diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\232.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\232.zip" new file mode 100644 index 0000000000000000000000000000000000000000..7550469f6803bea6dc76b22b5d7888d0862d6dfb Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\232.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2321.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2321.docx" new file mode 100644 index 0000000000000000000000000000000000000000..c3e6abe70f1628261507155bb03365879d7c8e7f Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2321.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2322.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2322.docx" new file mode 100644 index 0000000000000000000000000000000000000000..49ce55f1f3f15407fcb235dde50981fba47ad871 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2322.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2323.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2323.docx" new file mode 100644 index 0000000000000000000000000000000000000000..cbf3044366a04805b1bf2ccea7947194d047aee2 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2323.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2324.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2324.docx" new file mode 100644 index 0000000000000000000000000000000000000000..6d71721f45a695d2b373f4281d77d1a2353ca26b Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\344\275\234\344\270\2324.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\350\265\204\346\226\231.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\350\265\204\346\226\231.zip" new file mode 100644 index 0000000000000000000000000000000000000000..7db768f76d636558c03b5b54b92415c04ced98a1 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.07/\350\265\204\346\226\231.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_47_\350\224\241\347\216\256\351\223\255.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_47_\350\224\241\347\216\256\351\223\255.md" new file mode 100644 index 0000000000000000000000000000000000000000..0f55d8654d61697162dfb23b5eb4df2004ec1624 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_47_\350\224\241\347\216\256\351\223\255.md" @@ -0,0 +1,69 @@ +**综合练习1** + +1.使用SQL语句,创建公司 company 数据库,要求使用判断的SQL方式 + +create database if not exists company; + +指定数据库字符集:utf8mb4,排序规则:utf8mb4_0900_ai_ci + +create database if not exists default utf8mb4 colloate utf8mb4_0900_ai_ci; + +2.使用SQL语句,在公司数据库中,创建员工信息表 staff_info_01,要求将备注填入每个字段的注释中,同时使用带判断的SQL方式 + +| 字段名称 | 数据类型 | 备注 | +| ------------- | ------------ | --------------------- | +| id | int(11) | 员工ID | +| staff_name | varchar(255) | 员工姓名 | +| staff_age | int(2) | 员工年龄 | +| staff_sex | int(1) | 员工性别(1-男 2-女) | +| staff_time | datetime(0) | 入职日期 | +| staff_address | varchar(255) | 家庭住址 | +| dept_id | int(11) | 部门ID | + +create table if not exists staff_info_01( + +​ id int(11) comment'员工ID', + +​ staff_name varchar(255) '员工姓名', + +​ staff_age int(2) comment'员工姓名', + +​ staff_sex int(1) comment'员工性别(1-男 2-女)', + +​ staff_time datetime(0) comment'入职日期', + +​ staff_address varchar(255) comment'家庭住址', + +​ dept_id int(11) comment'部门ID' + +) comment'员工信息表'; + +3.使用SQL语句,修改员工信息的表名,由staff_info_01修改成staff_info; + +alter table staff_info_01 rename to staff_info; + +4.使用SQL语句,向员工信息表staff_info中新增员工身高:staff_high 字段,数据类型:int(3) + +要求该字段位置位于staff_sex后面 + +alter table staff_info_01 add staff_high int(3) after staff_sex; + +5.使用SQL语句,修改字段名称,将staff_high 字段名称修改为 staff_height ,数据类型:int(3) + +alter table staff_info_01change staff_high staff_height int(3); + +6.使用SQL语句,修改字段staff_height 数据类型,修改为varchar(3) + +alter table staff_info_01 modify staff_height varchar(3); + +7.使用SQL语句,删除字段dept_id; + +alter table staff_info_01 drop dept_id; + +8.使用SQL语句,删除员工信息表(只写命令,不执行操作); + +drop staff_info_01; + +9.使用SQL语句,删除公司数据库(只写命令,不执行操作); + +drop company; \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232.zip" new file mode 100644 index 0000000000000000000000000000000000000000..eff9ea0c119c853977bb854e9a2c53671016e3fb Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" new file mode 100644 index 0000000000000000000000000000000000000000..8e516c045bb1336c6034fc7105fd397c924db440 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/5.SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/5.SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..9ec28e18e60741fe5992ce7b7112a912b2d57380 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/5.SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,22 @@ +**注:作业以电脑屏幕截图为准,不得局部截图,如果以局部截图交上来,按照未按时完成作业来算。** + + + +## SQL修改数据练习题 + +### 数据准备 + +请使用Navicat 执行 修改数据示例 语句进行数据准备 + +``` +修改数据示例.sql +``` + +### 修改数据(请写上SQL,并附上修改前后的截图) + +1. 学生信息表中,刘小东同学的年龄写错了,正确年龄是 24,请使用sql修改。 +2. 学生信息表中,黄龙辉同学的生日写错了,正确生日是 1999-03-20,请使用sql修改。 +3. 学生信息表中,林小松同学的性别(1:男生,2:女生)和班级写错了,他是男生,而且是软件技术1班的,请使用sql修改 +4. 陈丽和王海欣同学 转到软件技术1班了,请使用sql修改 +5. 学校对课程学分进行了调整,每门课程学分都增加1分,请使用sql修改 +6. 假设目前获取不到欧阳武学生的ID数据,请把地址修改成 “福建省龙岩市新罗区新罗社区” diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/5.SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\344\277\256\346\224\271\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/5.SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\344\277\256\346\224\271\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..f1872557f3dbb05b6d66834769da4c8ac346fbab --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/5.SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\344\277\256\346\224\271\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,192 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '22', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '2001-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 2, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '24', '2000-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (1, '数据库高级应用', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (2, 'javascript编程基础', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (3, 'web前端程序设计基础', 4); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (4, '动态网页设计.net基础', 6); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (31, 8, 3, 82); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (33, 8, 4, 67); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/6.SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/6.SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..7b94d2a0ff78c945c779bcc1bb1ff8f33895469b --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/6.SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,21 @@ +**注:作业以电脑屏幕截图为准,不得局部截图,如果以局部截图交上来,按照未按时完成作业来算。** + + + +## SQL删除数据练习题 + +### 数据准备 + +请使用Navicat 执行 数据示例 语句进行数据准备 + +``` +数据示例.sql +``` + +### 删除数据(请写上SQL,并附上删除前后的截图) + +1. 删除学生信息表中,姓名是 '欧阳武'的学生信息; +1. 删除学生信息表中,年龄为22,且家庭住址在'东肖社区'的学生信息; +1. 删除学生信息表中,年龄为22 或者年龄为24的学生信息; +1. 学校不开设 '动态网页设计.net基础' 的课程了,请帮忙删除该数据; +1. 由于课程变动,所有需要删除所有的成绩信息数据; diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/6.SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/6.SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..f1872557f3dbb05b6d66834769da4c8ac346fbab --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/6.SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,192 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '22', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '2001-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 2, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '24', '2000-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (1, '数据库高级应用', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (2, 'javascript编程基础', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (3, 'web前端程序设计基础', 4); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (4, '动态网页设计.net基础', 6); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (31, 8, 3, 82); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (33, 8, 4, 67); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.docx" new file mode 100644 index 0000000000000000000000000000000000000000..0be7d6feff6711cf9c01a2caf6c7d849f8cdf9d3 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/SQL\346\226\271\345\274\217\344\277\256\346\224\271\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.docx" new file mode 100644 index 0000000000000000000000000000000000000000..048099d9d63aa01869e9e1de553fb066c3569b01 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.11/\344\275\234\344\270\232/SQL\346\226\271\345\274\217\345\210\240\351\231\244\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.zip" new file mode 100644 index 0000000000000000000000000000000000000000..cd16e2f8451358d48ff368d9ee5d56d73a131de6 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" new file mode 100644 index 0000000000000000000000000000000000000000..c8440b03afcb64bfee00c7c3b213abc936276e9f Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\345\210\240\351\231\244\345\222\214\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\345\210\240\351\231\244\345\222\214\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..fa8d10d27386239edb83553785be1b59cdfd6cc5 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\345\210\240\351\231\244\345\222\214\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,46 @@ +**注:作业以电脑屏幕截图为准,不得局部截图,如果以局部截图交上来,按照未按时完成作业来算。** + +## SQL删除及查询练习题 + +### 删除数据 + +``` +数据示例.sql +``` + + + +1. 分数表中 欧阳武 数据库高级应用 成绩 插入重复了,请帮忙删除其中一条数据; +2. 删除分数表的所有数据(写出三种方式); + +### 查询数据 + +掌握: + +-- 1.查询所有数据; +-- 2.查询指定列名; +-- 3.添加条件的查询 限于 大于等于 大于 小于等于 小于 不等于 等于 6种; + +注:需写上SQL并带上查询结果截图; + +``` +数据示例.sql +``` + + + +1. 查询所有的班级信息。 +2. 查询所有的学生信息。 +3. 查询所有的课程信息。 +4. 查询所有的班级课程信息。 +5. 查询所有的分数信息。 +6. 查询所有学生的姓名和年龄、地址信息。 +7. 查询所有的课程 信息,并且按照学分从高到低排列。 +8. 查询所有的分数 信息,并且按照分数从低到高排列。 +9. 查询所有的学生 信息,并且按照年龄从小到大排列。 +10. 查询学生信息表中,不是女生的学生信息。 +11. 查询学生信息表中,年龄为22岁的学生信息。 +12. 查询课程表中,学分大于3分的课程信息。 +13. 查询学生信息表中,年龄大于等于23岁的学生信息。 +14. 查询学生信息表中,年龄小于20岁的学生信息。 +15. 查询学生信息表中,年龄小于等于22岁的学生信息。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..07b87e7ac80f3241f54d67e768bdacf100e374c6 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.12/7.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,193 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (4, '新媒体1班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (1, '数据库高级应用', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (2, 'javascript编程基础', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (3, 'web前端程序设计基础', 4); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (4, '动态网页设计.net基础', 6); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (31, 8, 3, 82); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (33, 8, 4, 67); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242).zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242).zip" new file mode 100644 index 0000000000000000000000000000000000000000..33fbd4f2c15d628ff93ed36cd5449ac3ab97b794 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242).zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" new file mode 100644 index 0000000000000000000000000000000000000000..5cc910993ae460eae9d62c68283b21e0f9c18b38 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..8d797a29d194c700d38eaa1a9fbd14019faf09fc --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,56 @@ +create database if not exists commerce; + +use commerce; + +drop table if exists customer_info; + +drop table if exists goods_info; + + +-- 创建客户信息表 +create table customer_info ( + id int(11) primary key auto_increment NOT NULL COMMENT '客户编号', + customer_name varchar(255) COMMENT '客户名称', + customer_phone varchar(11) COMMENT '客户手机号码' +); + +-- 创建商品信息表 +create table goods_info ( + id int(11) primary key auto_increment NOT NULL COMMENT '商品编号', + goods_name varchar(255) COMMENT '商品名称', + goods_price decimal COMMENT '商品价格', + goods_color varchar(10) COMMENT '商品颜色', + goods_time datetime(0) COMMENT '商品生产日期', + goods_weight int(5) COMMENT '商品重量', + customer_id int(11) COMMENT '客户编号' +); + + + +-- 新增客户数据 +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES (1, '刘小东', '15120202333'); +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES (2, '黄龙辉', '18121282553'); +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES (3, '陈丽', '19033202893'); +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES (4, '林小松', '15120023330'); +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES (5, '舒燕', '13559802253'); +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES (6, '王海欣', '17339783658'); +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES (7, '王韦林', '15178952008'); +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES (8, '欧阳武', '18536580028'); + + +-- 新增商品信息数据 +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`,`customer_id`) VALUES +(1, '冰箱', 5399, '白色', '2023-06-30 00:00:00',100, 1), +(2, '洗衣机', 4999, '白色', '2024-07-05 00:00:00',130, 1), +(3, '微波炉', 399, '黑色', '2022-01-30 00:00:00',10, 2), +(4, '烤箱', 1999, '灰色', '2021-02-15 00:00:00',5, 3), +(5, '蒸锅', 599, '粉色', '2022-09-10 00:00:00',5, 5), +(6, '电饭锅', 599, '白色', '2024-10-21 00:00:00',3, 6); + +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`,`customer_id`) VALUES +(7, '电视', 6999, '', '2020-10-21 00:00:00',60, 8); + +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`,`customer_id`) VALUES +(8, '电脑', 1399, '卡其色', '2019-11-11 00:00:00', 2); + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..377b88ac39373b5038d6b7e4d40420e5a740b0db --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.14/8.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256\347\273\203\344\271\240\351\242\230-(\346\237\245\350\257\242\346\235\241\344\273\266,\346\250\241\347\263\212\346\237\245\350\257\242)/\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,36 @@ +**注:作业以电脑屏幕截图为准,不得局部截图,如果以局部截图交上来,按照未按时完成作业来算。** + +## SQL查询练习题 + +### 查询数据 + +掌握: + +-- 1.范围查询; + +-- 2.是null 不是null; + +-- 3.是空 不是空; + +-- 4.在列表 不在列表; + +-- 5.模糊查询; + +注:需写上SQL并带上查询结果截图; + +``` +数据示例.sql +``` + + + +1. 查询价格在1000~2000元的商品信息; +2. 查询重量在100~150之间的商品的编号、名称、重量信息; +3. 查询没有颜色信息的商品信息; +4. 查询重量信息为null的商品的编号、名称、颜色信息; +5. 查询没有被客户购买的商品信息; +6. 查询手机号码是以 “151” 字开头的客户信息; +7. 查询姓名中包含“王”字的客户信息; +8. 查询手机号码是以“53”结束的客户信息; +9. 查询姓名是以“陈”字开头,且只有两个字的名字的客户信息; +10. 查询生产日期是2020年1月1号到2023年12月31号生产的商品信息; diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230.zip" new file mode 100644 index 0000000000000000000000000000000000000000..938bea6f865465c5c160a07ad9a379c8ff4745b7 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" new file mode 100644 index 0000000000000000000000000000000000000000..9ae4e94a410148441c3fcdef6e12ba998e9a4c6a Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..6dd0616881e6356f9c026e021c51f6711d755ac6 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,91 @@ +create database if not exists commerce; + +use commerce; + +drop table if exists customer_info; + +drop table if exists goods_info; + +drop table if exists order_info; + + +-- 创建客户信息表 +create table customer_info ( + id int(11) COMMENT '客户编号', + customer_name varchar(255) COMMENT '客户名称', + customer_phone varchar(11) COMMENT '客户手机号码' +); + +-- 创建商品信息表 +create table goods_info ( + id int(11) COMMENT '商品编号', + goods_name varchar(255) COMMENT '商品名称', + goods_price decimal COMMENT '商品价格', + goods_color varchar(10) COMMENT '商品颜色', + goods_time datetime(0) COMMENT '商品生产日期', + goods_weight int(5) COMMENT '商品重量' +); + + +-- 创建订单信息表 +create table order_info ( + id int(11) COMMENT '订单编号', + order_num varchar(255) COMMENT '订单数量', + order_price decimal COMMENT '订单价格', + order_time datetime(0) COMMENT '订单日期', + order_address varchar(255) COMMENT '订单地址', + customer_id int(11) COMMENT '客户标号', + goods_id int(11) COMMENT '商品编号' +); + +-- 新增订单数据 +INSERT INTO `order_info`(`id`, `order_num`, `order_price`, `order_time`, `order_address`, `customer_id`, `goods_id`) VALUES +(1,5,1995,'2024-01-30 15:32:51','广西省桂林市七星区空明西路10号鸾东小区', 1,3), +(2,3,1797,'2022-07-07 20:15:51','江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1,5), +(3,2,13998,'2023-05-20 21:16:51','福建省龙岩市新罗区曹溪街道万达小区', 3,7), +(4,1,13999,'2024-02-22 05:22:51','云南省昆明市五华区华山街道华山小区', 3,8), +(5,1,599,'2021-12-20 09:31:51','福建省龙岩市新罗区万宝社区', 7,6), +(6,9,44991,'2022-12-18 03:38:51','福建省龙岩市新罗区东肖社区', 8,2), +(7,5,26995,'2022-08-15 00:59:51','陕西省西安市雁塔区雁塔路1号雁塔社区', 1,1), +(8,1,6999,'2022-09-22 16:15:51','福建省厦门市集美区杏林村', 2,7), +(9,3,14997,'2023-06-11 15:11:51','福建省泉州市鲤城区成功路1号', 2,2), +(10,3,1197,'2023-02-02 18:12:51','贵州省贵阳市白云区白云小区10号楼', 4,3), +(11,1,5399,'2022-11-11 11:30:56','福建省龙岩市新罗区南城街道1号', 5,4), +(12,1,599,'2023-05-02 19:00:51','河南省郑州市中原区中环路5号', 6,5) + +; + + + +-- 新增客户数据 +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES +(1, '刘小东', '15120202333'), +(2, '黄龙辉', '18121282553'), +(3, '陈丽', '19033202893'), +(4, '林小松', '15120023330'), +(5, '舒燕', '13559802253'), +(6, '王海欣', '17339783658'), +(7, '王韦林', '15178952008'), +(8, '欧阳武', '18536580028') +; + + +-- 新增商品信息数据 +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`) VALUES +(1, '冰箱', 5399, '白色', '2023-06-30 00:00:00',100), +(2, '洗衣机', 4999, '白色', '2024-07-05 00:00:00',130), +(3, '微波炉', 399, '黑色', '2022-01-30 00:00:00',10), +(4, '烤箱', 1999, '灰色', '2021-02-15 00:00:00',5), +(5, '蒸锅', 599, '粉色', '2022-09-10 00:00:00',5), +(6, '电饭锅', 599, '白色', '2024-10-21 00:00:00',3), +(6, '电饭锅', 599, '白色', '2024-10-21 00:00:00',3); + +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`) VALUES +(7, '电视', 6999, '灰色', '2020-10-21 00:00:00',60); + +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`) VALUES +(8, '电脑', 13999, '卡其色', '2019-11-11 00:00:00',20); +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`) VALUES +(8, '电脑', 13999, '卡其色', '2019-11-11 00:00:00',20); + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..f9e91a86438f73a1d8497b24c401fe52f75f9cd9 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,55 @@ +**注:作业以电脑屏幕截图为准,不得局部截图,如果以局部截图交上来,按照未按时完成作业来算。** + +## SQL查询练习题 + +### 查询数据 + +掌握: + +-- 1.查询若干条数据; + +-- 2.查询结果不重复; + +-- 3.聚合函数查询; + +-- 4.分组查询; + +-- 5.分组后筛选; + +注:需写上SQL并带上查询结果截图; + +``` +数据示例.sql +``` + + + +1.查询所有商品数据,去除重复数据,并展示3条 + +2.查询所有客户数据,并展示5条 + +3.查询所有订单的平均价格 + +4.查询所有订单的总价格 + +5.查询所有订单的最高金额 + +6.查询所有订单的最低金额 + +7.查询所有订单数量 + +8.查询所有客户数量 + +9.查询每个客户的订单总额 + +10.查询每个客户的订单数 + +11.查询每个客户的平均订单金额,并按金额倒序 + +12.查询最高单价的商品编号、名称、金额,并去除重复数据 + +13.查询每个商品的总订单金额,且总金额大于3000元,并按总金额倒序排列 + +14.查询客户编号为1的客户购买的订单总金额 + +15.查询每种商品颜色对应的商品数量,去除重复数据,并按数量升序排列,且展示其中2条 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\350\257\276\345\240\202\347\254\224\350\256\260.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\350\257\276\345\240\202\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..66666352989797570a45bdebfd7a4cc3b7d84888 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.18/9.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\350\257\276\345\240\202\347\254\224\350\256\260.md" @@ -0,0 +1,150 @@ +-- 查询当前表中若干条数据 + +-- 关键字:limit 限制 ,界限 + +-- SELECT * from 表名 LIMIT rows; + +-- 查询学生信息表中,5条数据 + +SELECT * FROM student_info ORDER BY student_age desc LIMIT 5; + +-- 数据不到需要的条数时,不会自动补齐对应条数的数据 + +-- LIMIT 还可以用于 分页 + + +-- +-- 查询结果不重复 + +-- 关键字:distinct 去除重复 + +-- SELECT distinct * 或者 字段 from 表名; + +SELECT DISTINCT * FROM score_info; + +-- 去除是需要:数据完全一致 + +-- 如果你需要查询单表的数据去重,需要去指定字段查询,不能把主键带进去 + +SELECT DISTINCT student_id,course_id,score from score_info; + +-- 主要使用场景:多表联查时 + + +-- +-- 聚合函数查询 + +-- 求条数:统计当前这张表有多少记录、求和:把值进行相加、求平均值:针对当前表的记录、求最大值:针对当前表的记录、求最小值:针对当前表的记录 + +-- 求条数 count() 关键字() 函数 + +-- SELECT count() from 表名; + +-- count()函数的使用 + +-- 四种方式 + +-- 1.count(*) 查询所有条数 + +SELECT count(*) from student_info; + +-- 2.count(1) 查询所有条数 恒真表达式 + +SELECT count(1) from student_info; + +-- 3.count(字段名称) 查询所有条数 + +SELECT count(id) from student_info; + +-- 4. SELECT count(任意字段名称) from 表名 基本不用; + +SELECT count(student_sex) from student_info; + + +-- 求和 sum() + +-- SELECT sum(字段名) from 表名; + +-- 1.统计所有课程的总学分 + +SELECT sum(course_credit) from course_info; + +-- 统计所有成绩 + +SELECT sum(score) from score_info; + + +-- 求平均值 avg() + +-- SELECT avg(字段名) from 表名; + +-- 1.统计所有课程的平均学分 + +SELECT avg(course_credit) from course_info; + +-- 求最大值 max() + +-- SELECT max(字段名) from 表名; + +SELECT max(course_credit) from course_info; + + +-- 求最小值 min() + +-- SELECT min(字段名) from 表名; + +SELECT min(course_credit) from course_info; + + +-- +-- 分组查询 GROUP BY + +-- 需要一组一组统计,再进行相加 比较麻烦点 + +-- SELECT sum(1) from 表; +-- SELECT sum(1) from 表; +-- SELECT sum(1) from 表; +-- SELECT sum(1) from 表; +-- SELECT sum(1) from 表; + +-- 按组别进行统计分数功能 + +-- GROUP BY 分组条件; + +-- SELECT 分组字段,聚合函数 from 表名 GROUP BY 分组字段; + +-- 按照学生进行分组,统计他们所有成绩 + +SELECT student_id,sum(score) from score_info GROUP BY student_id; + +-- 按照学生进行分组,统计他们所有课程的平均成绩 + +SELECT student_id,avg(score) from score_info GROUP BY student_id; + +-- 按照课程id进行分组,统计每门课程的总成绩 + +SELECT course_id,sum(score) from score_info GROUP BY course_id; + + +SELECT course_id,COUNT(id) from score_info GROUP BY course_id; + +-- +-- 分组后筛选:分组过后,给 HAVING 条件 ,等效余where,HAVING 只能配合 GROUP BY 进行使用(分组后的条件) + +-- select 分组条件字段名,聚合函数 from 表名 group by 分组条件字段名 HAVING 分组条件字段名,聚合函数(查询的结果集里面的字段当做条件) + + + +SELECT course_id,COUNT(id) from score_info GROUP BY course_id HAVING COUNT(id) > 8 ; + +-- 多字段条件分组查询 + +SELECT course_id,student_id ,COUNT(id) from score_info GROUP BY course_id,student_id; + +-- GROUP BY 后面的条件字段,要在查询结果集里面体现 + +-- HAVING 后面条件字段,只能结果集里面去取,不能使用结果集以外的字段当做条件 + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" new file mode 100644 index 0000000000000000000000000000000000000000..e32e23165e164cf664168905bffb82b2d4186429 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" new file mode 100644 index 0000000000000000000000000000000000000000..2045ddfe56e76cf517fce91ba967380158901e55 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\345\210\206\351\241\265\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\345\210\206\351\241\265\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..484065aeba4b471e86a7be282c3c0777a73c0bd0 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\345\210\206\351\241\265\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260.md" @@ -0,0 +1,114 @@ +-- 分组查询 GROUP BY + +-- 其实就按类别去进行统计数据 + +-- select sum(字段) from 表; 统计第一组 +-- select sum(字段) from 表; 统计第一组 +-- select sum(字段) from 表; 统计第一组 +-- select sum(字段) from 表; 统计第一组 + +-- SELECT 分组字段(决定分组维度),统计(求和、求平均值) from 表名 group by 分组字段(决定分组维度) + +-- 按学生为分组字段,查询每位学生总成绩 + +SELECT student_id,sum(score) from score_info GROUP BY student_id; + + +-- 分组后筛选(给条件处理结果集) 不跟where去处理语句的条件 + +-- HAVING 需要配合 GROUP BY 进行使用,先查出数据后,再进行筛选 + +-- where 是针对所有结果先进行筛选,后进行统计 + +SELECT student_id,sum(score) from score_info GROUP BY student_id + +HAVING sum(score) > 300; + + +-- 分组后排序 ORDER BY + +SELECT student_id,course_id,sum(score) from score_info GROUP BY student_id + +HAVING sum(score) > 290 ORDER BY sum(score) desc; + +-- 分组后排序,有要查我只需要展示多少条数据 + + + + +SELECT student_id,sum(score) from score_info where student_id = 1 GROUP BY student_id + +HAVING sum(score) > 290 ORDER BY sum(score) desc LIMIT 5; + + +-- select [列1,列2,...|*] from 表名 +-- +-- ​ [where 条件] +-- +-- ​ [group by 字段] +-- +-- ​ [having 条件] +-- +-- ​ [order by 字段] +-- +-- ​ [limit ] + + +-- 分页查询 页码 第一页 展示多少条 + +-- 第1页 6条 6 +-- 第2页 6条 12 +-- 第3页 6条 18 +-- 第4页 6条 24 + +-- 页码*条数 = 最大ID值 + +-- limit 用于分页查询: [OFFSET] (偏移量,也可以称为页码),rows(条数) + +-- OFFSET 其实叫作 偏移量,简单来讲 叫作页码(会变动) + + +select * FROM student_info; -- OFFSET 从0开始数,不从1开始 OFFSET+1 = 需要的值 + +-- 从第2条开始,查询3条记录 + +select * from student_info limit 1,3; + +-- 从第3条开始,查询2条记录 + +select * from student_info LIMIT 2,2; + +-- 查询学生数据,按每页2条数据展示 + +-- 分页查询,页码 1 2 3 + +-- 数据库查询的时候:OFFSET+1 = 页码 + +-- 如果客户端传页码参数过来 页码 : OFFSET = 页码-1 + + +-- SELECT * from student_info LIMIT (页码-1),条数; + +-- 页码 1, 偏移量 0,条数 2条 + +SELECT * from student_info LIMIT 0,2; + +-- 页码 2, 偏移量 1,条数 2条 + +SELECT * from student_info LIMIT 2,2; + +-- 页码 3, 偏移量 2,条数 2条 + +SELECT * from student_info LIMIT 4,2; + +-- 页码 4, 偏移量 3,条数 2条 + +SELECT * from student_info LIMIT 6,2; + + +-- 分页查询的时候遵循这个公式来计算偏移量: (页码-1)*条数,条数 + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\345\210\206\351\241\265\347\273\203\344\271\240.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\345\210\206\351\241\265\347\273\203\344\271\240.sql" new file mode 100644 index 0000000000000000000000000000000000000000..68cc4f8224fde1626b62432594499a2bdfc5446b --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\345\210\206\351\241\265\347\273\203\344\271\240.sql" @@ -0,0 +1,13 @@ +-- 查询前5条订单数据 + +-- 查询从2条开始,查询2条订单数据 + +-- 查询从5条开始,查询3条订单数据 + +-- 查询第1页订单数据,按每页2条显示 + +-- 查询第2页订单数据,按每页2条显示 + +-- 查询第3页订单数据,按每页2条显示 + +-- 查询第4页订单数据,按每页2条显示 \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..6dd0616881e6356f9c026e021c51f6711d755ac6 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.19/10.SQL\346\226\271\345\274\217\346\237\245\350\257\242\346\225\260\346\215\256(limit,distinct,\345\210\206\347\273\204)\347\273\203\344\271\240\351\242\230/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,91 @@ +create database if not exists commerce; + +use commerce; + +drop table if exists customer_info; + +drop table if exists goods_info; + +drop table if exists order_info; + + +-- 创建客户信息表 +create table customer_info ( + id int(11) COMMENT '客户编号', + customer_name varchar(255) COMMENT '客户名称', + customer_phone varchar(11) COMMENT '客户手机号码' +); + +-- 创建商品信息表 +create table goods_info ( + id int(11) COMMENT '商品编号', + goods_name varchar(255) COMMENT '商品名称', + goods_price decimal COMMENT '商品价格', + goods_color varchar(10) COMMENT '商品颜色', + goods_time datetime(0) COMMENT '商品生产日期', + goods_weight int(5) COMMENT '商品重量' +); + + +-- 创建订单信息表 +create table order_info ( + id int(11) COMMENT '订单编号', + order_num varchar(255) COMMENT '订单数量', + order_price decimal COMMENT '订单价格', + order_time datetime(0) COMMENT '订单日期', + order_address varchar(255) COMMENT '订单地址', + customer_id int(11) COMMENT '客户标号', + goods_id int(11) COMMENT '商品编号' +); + +-- 新增订单数据 +INSERT INTO `order_info`(`id`, `order_num`, `order_price`, `order_time`, `order_address`, `customer_id`, `goods_id`) VALUES +(1,5,1995,'2024-01-30 15:32:51','广西省桂林市七星区空明西路10号鸾东小区', 1,3), +(2,3,1797,'2022-07-07 20:15:51','江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1,5), +(3,2,13998,'2023-05-20 21:16:51','福建省龙岩市新罗区曹溪街道万达小区', 3,7), +(4,1,13999,'2024-02-22 05:22:51','云南省昆明市五华区华山街道华山小区', 3,8), +(5,1,599,'2021-12-20 09:31:51','福建省龙岩市新罗区万宝社区', 7,6), +(6,9,44991,'2022-12-18 03:38:51','福建省龙岩市新罗区东肖社区', 8,2), +(7,5,26995,'2022-08-15 00:59:51','陕西省西安市雁塔区雁塔路1号雁塔社区', 1,1), +(8,1,6999,'2022-09-22 16:15:51','福建省厦门市集美区杏林村', 2,7), +(9,3,14997,'2023-06-11 15:11:51','福建省泉州市鲤城区成功路1号', 2,2), +(10,3,1197,'2023-02-02 18:12:51','贵州省贵阳市白云区白云小区10号楼', 4,3), +(11,1,5399,'2022-11-11 11:30:56','福建省龙岩市新罗区南城街道1号', 5,4), +(12,1,599,'2023-05-02 19:00:51','河南省郑州市中原区中环路5号', 6,5) + +; + + + +-- 新增客户数据 +INSERT INTO `customer_info`(`id`, `customer_name`, `customer_phone`) VALUES +(1, '刘小东', '15120202333'), +(2, '黄龙辉', '18121282553'), +(3, '陈丽', '19033202893'), +(4, '林小松', '15120023330'), +(5, '舒燕', '13559802253'), +(6, '王海欣', '17339783658'), +(7, '王韦林', '15178952008'), +(8, '欧阳武', '18536580028') +; + + +-- 新增商品信息数据 +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`) VALUES +(1, '冰箱', 5399, '白色', '2023-06-30 00:00:00',100), +(2, '洗衣机', 4999, '白色', '2024-07-05 00:00:00',130), +(3, '微波炉', 399, '黑色', '2022-01-30 00:00:00',10), +(4, '烤箱', 1999, '灰色', '2021-02-15 00:00:00',5), +(5, '蒸锅', 599, '粉色', '2022-09-10 00:00:00',5), +(6, '电饭锅', 599, '白色', '2024-10-21 00:00:00',3), +(6, '电饭锅', 599, '白色', '2024-10-21 00:00:00',3); + +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`) VALUES +(7, '电视', 6999, '灰色', '2020-10-21 00:00:00',60); + +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`) VALUES +(8, '电脑', 13999, '卡其色', '2019-11-11 00:00:00',20); +INSERT INTO `goods_info`(`id`, `goods_name`, `goods_price`, `goods_color`, `goods_time`, `goods_weight`) VALUES +(8, '电脑', 13999, '卡其色', '2019-11-11 00:00:00',20); + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242.zip" new file mode 100644 index 0000000000000000000000000000000000000000..06cbd0f0c016be75eca5747937dc31c0cb4c0a33 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" new file mode 100644 index 0000000000000000000000000000000000000000..ac28d9e001a55129c6191e7269f0ee567874b0eb Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..0d874c990fd4ea0b2b27f84bf21971f57a7a8c39 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,212 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; +drop table if exists course_type; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table if not exists class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table if not exists student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table if not exists course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL, + ctype_id int(11) +); + +-- 创建课程类型表,存储课程类型信息,其中字段包含:课程id、课程名称、课程类型 +create table if not exists course_type ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table if not exists class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table if not exists score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (4, '软件技术4班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有3个同学,软件技术2班有2个同学,软件技术3班、4班各有1个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区'); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (1, '数据库高级应用', 3, 1); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (2, 'javascript编程基础', 3, 2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (3, 'web前端程序设计基础', 4, 2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (4, '动态网页设计.net基础', 6, 2); + +-- 新增课程类别数据 +INSERT INTO `course_type`(`id`, `course_name`) VALUES (1, '数据库'); +INSERT INTO `course_type`(`id`, `course_name`) VALUES (2, '计算机语言'); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (13, 4, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (14, 4, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (15, 4, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (16, 4, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `course_id`) VALUES (29, 1); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (30, 2); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (31, 3); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (32, 4); + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..fde270d347db3081edd96bcd91e73987cc539b09 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,31 @@ +**注:作业以电脑屏幕截图为准,不得局部截图,如果以局部截图交上来,按照未按时完成作业来算。** + +## SQL连接查询练习题 + +``` +数据示例.sql +``` + +概念题: + +1.笛卡尔积是什么? + + + +SQL题: + +1.查询所有学生和对应的班级信息; + +2.使用左连接,查询学生及对应的班级信息; + +3.使用右连接,查询学生及对应的班级信息; + +4.查询课程和课程类别信息; + +5.查询学生信息及对应的成绩信息; + +6.查询班级信息及对应的课程信息,包含班级id、班级名称、课程名称、课程学分; + +7.查询学生ID为1的班级课程信息,展示学生ID、学生姓名、班级名称、课程名称、课程学分; + +注:SQL题除第一题外,所有题目都应该消除笛卡尔积现象; \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260/Snipaste_2024-03-21_16-35-22.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260/Snipaste_2024-03-21_16-35-22.png" new file mode 100644 index 0000000000000000000000000000000000000000..00456b31a83ffc7555bd35d883be48a966b29f5f Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260/Snipaste_2024-03-21_16-35-22.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..668d9712997d1903a7873a3f5a9377a3b471a0ef --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.20/11.SQL\346\226\271\345\274\217\350\277\236\346\216\245\346\237\245\350\257\242/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260/\350\277\236\346\216\245\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260.md" @@ -0,0 +1,193 @@ +-- 分组查询作业 + +-- 11.查询每个客户的平均订单金额,并按平均订单金额倒序 + +SELECT customer_id,avg(order_price) from order_info GROUP BY customer_id ORDER BY avg(order_price) desc; + +-- +-- 12.查询最高单价的商品编号、名称、金额,并去除重复数据 + +SELECT DISTINCT id,goods_name,goods_price from goods_info ORDER BY goods_price desc LIMIT 1; + +-- 子查询 + +SELECT DISTINCT id,goods_name,goods_price from goods_info where goods_price = (select max(goods_price) from goods_info); + +-- +-- 13.查询每个商品的总订单金额,且总金额大于3000元,并按总金额倒序排列 + +SELECT goods_id,sum(order_price) as sump from order_info group by goods_id HAVING sump > 3000 ORDER BY sump desc; + +-- +-- 14.查询客户编号为1的客户购买的订单总金额 + +SELECT sum(order_price) from order_info where customer_id = 1; + +-- +-- 15.查询每种商品颜色对应的商品数量,去除重复数据,并按数量升序排列,且展示其中2条 + +-- count函数使用 + +SELECT goods_color,COUNT(DISTINCT id) as cno from goods_info GROUP BY goods_color ORDER BY cno asc LIMIT 2; + +-- 子查询 + +SELECT temp.goods_color,count(temp.id) as cno from (SELECT DISTINCT * from goods_info) temp GROUP BY temp.goods_color ORDER BY cno asc LIMIT 2; + +-- 分页查询作业 + +-- 查询前5条订单数据 + +SELECT * from order_info limit 5; + +-- 查询从2条开始,查询2条订单数据 + +SELECT * from order_info limit 1,2; + +-- 查询从5条开始,查询3条订单数据 + +SELECT * from order_info limit 4,3; + +-- 查询第1页订单数据,按每页2条显示 + +SELECT * from order_info limit 0,2; + +-- 查询第2页订单数据,按每页2条显示 + +-- limit (n-1)*条数,条数 + +SELECT * from order_info limit 2,2; + +-- 查询第3页订单数据,按每页2条显示 + +SELECT * from order_info limit 4,2; + +-- 查询第4页订单数据,按每页2条显示 + +SELECT * from order_info limit 6,2; + + + + +----------------------------------------------------------- + +![Snipaste_2024-03-21_16-35-22](.\Snipaste_2024-03-21_16-35-22.png) + + + + + +-- 连接查询 + +-- 笛卡尔积 + +-- A表:{a,b} 2条数据 B表:{1,2,3} 3条数据 + +-- 笛卡尔积: A*B = c==> {(a,1),(a,2),(a,3),(b,1),(b,2),(b,3)} 2*3=6条数据 + + +select * from student_info,class_info; + +-- 怎么来消除笛卡尔积现象? 增加限制条件(寻找 两张表中字段含义相同的字段来当做相等条件) + +-- 需要查询学生对应班级信息 + +-- 其中 si 和ci 是两张表的别名 + +select * from student_info si,class_info ci WHERE si.class_id = ci.id; + + +-- 内连接 inner join ... on 限制条件 + +-- 分类:隐式【无join】、显式【有join】、等值连接、非等值连接、自连接 + +-- 这条就是内连接 + +-- 第一个分类:隐式【无join】 + +select * from student_info si,class_info ci WHERE si.class_id = ci.id; + +-- 第二个分类:显式【有join】 + +-- SELECT * from A inner join B on 消除笛卡尔积现象条件; + +SELECT * from student_info si INNER JOIN class_info ci on si.class_id = ci.id; + +-- 第三个分类:等值连接 + +-- SELECT * from A inner join B on 消除笛卡尔积现象条件; + +SELECT * from student_info si INNER JOIN class_info ci on si.class_id = ci.id; + +-- 第四个分类:非等值连接 + +-- SELECT * from A inner join B on 消除笛卡尔积现象条件; + +-- 查询学生对应的班级信息,班级id在1-2之间 + +SELECT * from student_info si INNER JOIN class_info ci on si.class_id = ci.id and si.class_id BETWEEN 1 and 2; + +-- 第五种分类:自连接 + +-- 查询学生信息中,学生id和班级id相等的数据 + +SELECT * from student_info si1 inner join student_info si2 on si1.id = si2.class_id; + +-- 注意点:内连接查询里面,这个 inner 是可以省略; + + +-- 外连接 左外连接、右外连接、全外连接、全连接 + +-- 左外连接 left join ...on + +-- 查询两张表的数据的时候,左连接会查出两张表相交的数据,且还会查出左表其它数据,但是右表如果没有匹配的数据的时候,就是展示null + +-- 以左表数据为主 + +SELECT * from student_info si LEFT JOIN class_info ci on si.class_id = ci.id; + + +-- 右外连接 right join ...on + +-- 查询两张表的数据的时候,右连接会查出两张表相交的数据,且还会查出右表其它数据,但是左表如果没有匹配的数据的时候,就是展示null + +-- 以右表数据为主 + +SELECT * from student_info si right JOIN class_info ci on si.class_id = ci.id; + + +-- 全外连接 full outer join 在Mysql中没有 + +-- 集合函数 union all 不可以帮助我们去除重复数据 + +-- SELECT * from A; +-- union all +-- SELECT * from B; + + +-- 全连接 full join 在Mysql中没有 + +-- 集合函数 union 可以帮助我们去除重复数据 + +-- SELECT * from A; +-- union +-- SELECT * from B; + +-- 注意点:两张表的 字段数要一致 + +SELECT id, +(select class_name from class_info where class_id = id) as class_name +from student_info +UNION +SELECT id,class_name from class_info; + + + + + + + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232.zip" new file mode 100644 index 0000000000000000000000000000000000000000..3e60e67372a253b8aace68370158a0add0609b02 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" new file mode 100644 index 0000000000000000000000000000000000000000..1e8ba5584d336cf7bd288fef8956d206cb6b7cdd Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.sql" new file mode 100644 index 0000000000000000000000000000000000000000..dfcfb98fb387289563a6642e2e666db7e2296644 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.sql" @@ -0,0 +1,35 @@ +-- 1.查询每门课程的最高分,并展示对应课程ID、最高分和老师名称; +select +ci.id '课程ID',(select max(si.score) from score_info si where si.course_id = ci.id group by si.course_id) '最高分', +(select ti.teacher_name from teacher_info ti where ci.teacher_id = ti.id) '老师名称' +from course_info ci; + +-- 2.查询每个学生的课程数量,并展示每位学生的学生的编号、姓名、所在班级名称、选课数量; +select si.id '学生ID', +si.student_name '学生姓名', +(select ci.class_name from class_info ci where ci.id = si.class_id ) '所在班级', +(select count(si2.student_id) from score_info si2 where si2.student_id = si.id) '选课数量' +from student_info si; + +-- 3.查询班级编号、名称和每个班的学生人数; +select ci.id '班级编号', +ci.class_name '班级名称', +(select count(si.id) from student_info si where si.class_id = ci.id) '学生人数' +from class_info ci; + +-- 4.查询成绩信息表,并展示每位学生的编号、姓名、课程成绩、课程名称、科任教师名称; +select si.student_id '学生编号', +(select stu.student_name from student_info stu where stu.id = si.student_id) '姓名', +si.score '课程成绩', +(select ci.course_name from course_info ci where ci.id = si.course_id) '课程名称', +(select ti.teacher_name from teacher_info ti where ti.id = +(select ci2.teacher_id from course_info ci2 where ci2.id = +(select ci.id from course_info ci where ci.id = si.course_id))) '科任老师' +from score_info si; + +-- 5.查询班级课程信息,并展示班级编号、课程名称; +select cc.class_id '班级编号', +(select ci.course_name from course_info ci where ci.id = cc.course_id) '课程名称' +from class_course cc; + +## 注:使用子查询作为虚拟表和作为列进行查询;v \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" new file mode 100644 index 0000000000000000000000000000000000000000..ee354de93942287506880303243b3072cce7e9af Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/\345\255\220\346\237\245\350\257\242\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/\345\255\220\346\237\245\350\257\242\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..9716598d0bbe7f8a6e4185c29fce9caf865a87b0 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/\345\255\220\346\237\245\350\257\242\347\244\272\344\276\213.sql" @@ -0,0 +1,132 @@ +drop database if exists student; + +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11) +); + +-- 创建教师表 +create table teacher_info ( + id int(11) primary key auto_increment NOT NULL, + teacher_name varchar(255) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT null, + teacher_id int(11) +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (4, '新媒体1班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + +-- 学院有两位老师 +INSERT INTO `teacher_info`(`id`, `teacher_name`) VALUES (1, '赖晓琳'); +INSERT INTO `teacher_info`(`id`, `teacher_name`) VALUES (2, '谢海峰'); + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`,`teacher_id`) VALUES (1, '数据库高级应用', 3,1); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`,`teacher_id`) VALUES (2, 'javascript编程基础', 3,2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`,`teacher_id`) VALUES (3, 'web前端程序设计基础', 4,2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`,`teacher_id`) VALUES (4, '动态网页设计.net基础', 6,2); + +-- 新增班级课程信息 +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); + + +-- 考试完成后,各学生各课程得分: + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/\345\255\220\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/\345\255\220\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..b416215c3882f38083681bf6391acd1fe5238bbb --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/12.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\350\231\232\346\213\237\350\241\250\357\274\214\345\210\227/\345\255\220\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,23 @@ +**注:作业以电脑屏幕截图为准,不得局部截图,如果以局部截图交上来,按照未按时完成作业来算。** + +## SQL子查询练习题 + +``` +数据示例.sql +``` + + + +SQL题: + +1.查询每门课程的最高分,并展示对应课程ID、最高分和老师名称; + +2.查询每个学生的课程数量,并展示每位学生的学生的编号、姓名、所在班级名称、选课数量; + +3.查询班级编号、名称和每个班的学生人数; + +4.查询成绩信息表,并展示每位学生的编号、姓名、课程成绩、课程名称、科任教师名称; + +5.查询班级课程信息,并展示班级编号、课程名称; + +注:使用子查询作为虚拟表和作为列进行查询; \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\345\212\240\345\274\272\347\273\203\344\271\240/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\345\212\240\345\274\272\347\273\203\344\271\240/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..0d874c990fd4ea0b2b27f84bf21971f57a7a8c39 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\345\212\240\345\274\272\347\273\203\344\271\240/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,212 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; +drop table if exists course_type; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table if not exists class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table if not exists student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table if not exists course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL, + ctype_id int(11) +); + +-- 创建课程类型表,存储课程类型信息,其中字段包含:课程id、课程名称、课程类型 +create table if not exists course_type ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table if not exists class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table if not exists score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (4, '软件技术4班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有3个同学,软件技术2班有2个同学,软件技术3班、4班各有1个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区'); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (1, '数据库高级应用', 3, 1); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (2, 'javascript编程基础', 3, 2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (3, 'web前端程序设计基础', 4, 2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (4, '动态网页设计.net基础', 6, 2); + +-- 新增课程类别数据 +INSERT INTO `course_type`(`id`, `course_name`) VALUES (1, '数据库'); +INSERT INTO `course_type`(`id`, `course_name`) VALUES (2, '计算机语言'); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (13, 4, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (14, 4, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (15, 4, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (16, 4, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `course_id`) VALUES (29, 1); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (30, 2); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (31, 3); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (32, 4); + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\345\212\240\345\274\272\347\273\203\344\271\240/\347\273\203\344\271\240\351\242\230.txt" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\345\212\240\345\274\272\347\273\203\344\271\240/\347\273\203\344\271\240\351\242\230.txt" new file mode 100644 index 0000000000000000000000000000000000000000..fb0d32aff479c58bc31e07c0da0ffde450914bef --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\345\212\240\345\274\272\347\273\203\344\271\240/\347\273\203\344\271\240\351\242\230.txt" @@ -0,0 +1,11 @@ +-- 1.查询班级及对应的课程和课程类别数据 + +-- 2.查询所有学生的班级和成绩数据 + +-- 3.查询每个学生的学生编号、学生姓名和平均成绩 + +-- 4.查询每个班级的学生数量 + +-- 5.查询平均成绩在70分以上的学生编号、姓名、平均成绩 + +-- 6.查询选修了课程编号为1的学生数量 \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\345\255\220\346\237\245\350\257\242\347\254\224\350\256\2601.txt" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\345\255\220\346\237\245\350\257\242\347\254\224\350\256\2601.txt" new file mode 100644 index 0000000000000000000000000000000000000000..792f417cfb4c600e76585adf3487acbbd287ec18 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.25/\345\255\220\346\237\245\350\257\242\347\254\224\350\256\2601.txt" @@ -0,0 +1,144 @@ +-- 1.查询所有学生和对应的班级信息; + +select * from student_info st INNER join class_info ci on st.class_id = ci.id; + +-- 2.使用右连接,查询学生及对应的班级信息; + +SELECT * from student_info si RIGHT JOIN class_info ci on si.class_id=ci.id; + +-- 3.查询学生ID为1的班级课程信息,展示学生ID、学生姓名、班级名称、课程名称、课程学分; + +-- 需要什么数据? + +-- 学生ID、学生姓名 --> student_info + +-- 班级名称 --> class_info + +-- 中间表 --> class_info + +-- 课程名称、课程学分 --> course_info + +-- 有什么条件 ? 学生ID = 1; + +-- 规则(限制条件):就是找关联表的主键,在当前这张表里面有没有连接字段(外键) + + +SELECT * FROM student_info st +INNER JOIN class_info cl on st.class_id = cl.id +inner join class_course cou on cl.id = cou.class_id +INNER JOIN course_info co on cou.course_id = co.id +WHERE st.id = 1; + +SELECT si.id, si.student_name,ci.class_name,ci2.course_name,ci2.course_credit FROM +student_info si, class_info ci ,class_course cc, course_info ci2 +WHERE si.class_id=ci.id AND ci.id=cc.class_id and cc.course_id=ci2.id AND si.id=1; + + +-- 4.查询课程和课程类别信息; + +select*from course_type cc INNER JOIN course_info ci on cc.id = ci.ctype_id; + +-- 5.使用左连接,查询学生及对应的班级信息; + +SELECT * from student_info si left JOIN class_info ci on si.class_id=ci.id; + + +-- 6.查询班级信息及对应的课程信息,包含班级id、班级名称、课程名称、课程学分; + +select class_info.id,class_name,course_info.id,course_name,course_credit from class_info +left join class_course on +class_info.id=class_course.class_id left join course_info on class_course.course_id=course_info.id; + + +-- select 字段 from 表名 +-- 连接关系 +-- 条件; + + +-- 7.查询学生信息及对应的成绩信息; +SELECT * FROM student_info s JOIN score_info d on s.id = d.student_id + + + +-- SELECT * from 表A where 字段 in(1,2,3); + +-- 1,2,3 值 我们现在不知道有多少个? + +-- 查询表A,表A字段1的值要在 表B的某一个条件范围内 + +-- SELECT * from 表A where 字段1 in(select * from 表B where 相关条件); + +-- 嵌套查询(子查询) + + + +-- #### 1.子查询作为表 + +-- 嵌套的语句查询出来的结果(子查询结果) = 表 +-- +-- 示例1:查询每门课程的最高分信息:课程编号、课程名称和最高分信息 + +-- 课程编号、课程名称 ---> 课程表 course_info id + +-- 最高分信息 --> score_info course_id + + +-- SELECT 字段1,字段2 from 表1 INNER join 表2 on 连接条件; + +-- SELECT 字段1,字段2 from 表1 INNER join (虚拟表结果) on 连接条件; + +-- SELECT 字段1,字段2 from (虚拟表结果) where 连接条件; + +SELECT si.course_id,ci.course_name,max(si.score) as max_score from score_info si +INNER JOIN course_info ci on si.course_id = ci.id +GROUP BY si.course_id; + +-- 不存在数据库里面的表 --> 虚拟表 + +SELECT ci.id,ci.course_name,temp.max_score from course_info ci INNER JOIN +(SELECT si.course_id,max(si.score) as max_score from score_info si GROUP BY si.course_id) temp +on ci.id = temp.course_id +; + +-- +-- #### 2.子查询作为列 +-- +-- 示例1:查询学生的成绩信息:学生id,姓名,课程名称,成绩 + +-- SELECT 字段1,(子查询) as 字段2 from 表1; + +-- 学生id,姓名 --> student_info id + +-- 成绩 --> score_info student_id,course_id + +-- 课程名称 --> course_info id + +SELECT si.id,si.student_name,ci.course_name,sc.score from student_info si +INNER JOIN score_info sc on si.id = sc.student_id +inner join course_info ci on sc.course_id = ci.id; + + +-- 子查询作为列 + + +SELECT +-- 学生姓名 +-- (select si.student_name from student_info si where sc.student_id = si.id) +sc.student_id, + +-- 把student_id 替换成 student_name +(select si.student_name from student_info si where si.id = sc.student_id) as student_name, + +-- 把course_id 替换成 course_name +(SELECT course_name from course_info ci where sc.course_id = ci.id) as course_name, + +sc.score + +from score_info sc; + + + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists.zip" new file mode 100644 index 0000000000000000000000000000000000000000..0ceecc265e32fdc34702309a47ef552b6ae96264 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" new file mode 100644 index 0000000000000000000000000000000000000000..a9222fdfc488164ad94c77812a5acb7d2db1f1b6 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.docx" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b924e3668fa2ae0ef773048b64b46bcdfdb57bbd --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.sql" @@ -0,0 +1,47 @@ +-- SQL题: +-- 1:查询成绩比平均成绩低的成绩信息 +select si.score '比平均成绩低的成绩' +from score_info si +where si.score < (select avg(score) from score_info); + +-- 2:查询选修课程数量与学号为1的选修课程数量一样多的其他学生的学号和姓名、选课数量 +select si2.id '学号', +si2.student_name '姓名', +count(si2.id) '选课数量' +from student_info si2 +inner join class_course cc2 on si2.class_id = cc2.class_id group by si2.id having count(si2.id) = +(select count(cc.course_id) '选课数量' from class_course cc where cc.class_id = (select class_id from student_info si where si.id = 1)) +order by si2.id asc; + +-- 3:查询平均成绩大于总平均成绩的学生编号、姓名、平均成绩 +select si.student_id '学生编号', +(select si2.student_name from student_info si2 where si2.id = si.student_id) '学生姓名', +avg(si.score) '平均成绩' +from score_info si +group by si.student_id +having avg(score) > (select avg(score) from score_info); + +-- 4:查询所有班级,并查询出这些班级的学生信息 +select * +from student_info si +where si.class_id in (select ci.id from class_info ci); + +-- 5:查询选修了课程编号为3和4的学生信息 +select * +from student_info si +where si.id in (select distinct si.student_id from score_info si where si.course_id in (3,4)); + +-- 6:查询没有选修课程编号为3和4的学生信息 +select * +from student_info si +where si.id not in (select distinct si.student_id from score_info si where si.course_id in (3,4)); + +-- 7:查询成绩表中有成绩的学生信息 +select * +from student_info si +where exists(SELECT si2.student_id from score_info si2 where si.id = si2.student_id); + +-- 8:查询成绩表中没有成绩的学生信息 +select * +from student_info si +where not exists(SELECT si2.student_id from score_info si2 where si.id = si2.student_id); \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" new file mode 100644 index 0000000000000000000000000000000000000000..c9f2a617cb9ec5cc04582d55424122e76c9492e3 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/23\347\272\247\350\275\257\344\273\266\346\212\200\346\234\2571\347\217\255_2314320207_\350\224\241\347\216\256\351\223\255.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/\345\255\220\346\237\245\350\257\242\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/\345\255\220\346\237\245\350\257\242\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..69d800efcfb9330694b6ddeae17640d64cacd6f3 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/\345\255\220\346\237\245\350\257\242\347\244\272\344\276\213.sql" @@ -0,0 +1,132 @@ +drop database if exists student; + +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null COMMENT '班级信息表主键', + class_name varchar(255) not null COMMENT '班级名称' +)COMMENT '班级信息表'; + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL COMMENT '学生信息表主键', + student_name varchar(255) COMMENT '姓名', + student_sex tinyint(1) NOT NULL COMMENT '性别', + student_age varchar(255) default 0 COMMENT '年龄', + student_time datetime(0) COMMENT '生日', + student_address varchar(255) COMMENT '学生家庭住址', + class_id int(11) COMMENT '班级ID' +)COMMENT '学生信息表'; + +-- 创建教师表 +create table teacher_info ( + id int(11) primary key auto_increment NOT NULL COMMENT '教师信息表主键', + teacher_name varchar(255) COMMENT '教师名称' +)COMMENT '教师信息表'; + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL COMMENT '课程信息表主键', + course_name varchar(255) COMMENT '课程名称', + course_credit int(10) NOT null COMMENT '课程学分', + teacher_id int(11) COMMENT '教师ID' +)COMMENT '课程信息表'; + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL COMMENT '班级课程信息表主键', + class_id int(11) COMMENT '班级ID', + course_id int(11) COMMENT '课程ID' +)COMMENT '班级课程信息表'; + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL COMMENT '成绩信息表主键', + student_id int(11) COMMENT '学生ID', + course_id int(11) COMMENT '课程ID', + score int(3) COMMENT '成绩' +)COMMENT '成绩信息表'; + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (4, '新媒体1班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + +-- 学院有两位老师 +INSERT INTO `teacher_info`(`id`, `teacher_name`) VALUES (1, '赖晓琳'); +INSERT INTO `teacher_info`(`id`, `teacher_name`) VALUES (2, '谢海峰'); + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`,`teacher_id`) VALUES (1, '数据库高级应用', 3,1); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`,`teacher_id`) VALUES (2, 'javascript编程基础', 3,2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`,`teacher_id`) VALUES (3, 'web前端程序设计基础', 4,2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`,`teacher_id`) VALUES (4, '动态网页设计.net基础', 6,2); + +-- 新增班级课程信息 +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); + + +-- 考试完成后,各学生各课程得分: + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `course_id`) VALUES (25,1); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (26,2); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/\345\255\220\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/\345\255\220\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..3d282926b120ba1afbf5d936a980a8a1a0188a24 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/13.SQL\346\226\271\345\274\217\345\255\220\346\237\245\350\257\242-\346\257\224\350\276\203\350\277\220\347\256\227\347\254\246\343\200\201in\343\200\201exists/\345\255\220\346\237\245\350\257\242\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,31 @@ +**注:作业以电脑屏幕截图为准,不得局部截图,如果以局部截图交上来,按照未按时完成作业来算。** + +## SQL子查询练习题 + +``` +子查询示例.sql +``` + + + +目标: + +掌握子查询中比较运算符(<、<=、=、>、>=、!=)、having、in、not in、exists、not exists使用 + +SQL题: + +1:查询成绩比平均成绩低的成绩信息 + +2:查询选修课程数量与学号为1的选修课程数量一样多的其他学生的学号和姓名、选课数量 + +3:查询平均成绩大于总平均成绩的学生编号、姓名、平均成绩 + +4:查询所有班级,并查询出这些班级的学生信息 + +5:查询选修了课程编号为3和4的学生信息 + +6:查询没有选修课程编号为3和4的学生信息 + +7:查询成绩表中有成绩的学生信息 + +8:查询成绩表中没有成绩的学生信息 \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/\345\255\220\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260\357\274\210\346\257\224\350\276\203\350\277\220\347\256\227\343\200\201in\343\200\201exists\357\274\211.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/\345\255\220\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260\357\274\210\346\257\224\350\276\203\350\277\220\347\256\227\343\200\201in\343\200\201exists\357\274\211.md" new file mode 100644 index 0000000000000000000000000000000000000000..2752106b01e7b26a7fe5715636005093a71db00f --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.26/\345\255\220\346\237\245\350\257\242\350\257\276\345\240\202\347\254\224\350\256\260\357\274\210\346\257\224\350\276\203\350\277\220\347\256\227\343\200\201in\343\200\201exists\357\274\211.md" @@ -0,0 +1,165 @@ +-- 1.查询每门课程的最高分,并展示对应课程ID、最高分和老师名称; + +SELECT ci.id,temp.maxScore,ti.teacher_name from course_info ci + +INNER JOIN teacher_info ti on ci.teacher_id = ti.id + +INNER JOIN + +(SELECT si.course_id,max(score) as maxScore from score_info si GROUP BY si.course_id) temp on ci.id = temp.course_id; + +-- +-- 2.查询每个学生的课程数量,并展示每位学生的学生的编号、姓名、所在班级名称、选课数量; + +-- 先拆题目 + +-- 每个学生的课程数量 这个是不是要分组查 + + +SELECT si.student_id,count(id) from score_info si GROUP BY si.student_id + +-- 编号、姓名 + +SELECT * from student_info si; + + +-- 班级名称 + +SELECT * from class_info ci + + +SELECT si.id,si.student_name,ci.class_name,temp.cnt from student_info si + +INNER JOIN class_info ci on si.class_id = ci.id + +INNER JOIN (SELECT si.student_id,count(id) as cnt from score_info si GROUP BY si.student_id) temp on si.id = temp.student_id; + + +-- +-- 3.查询班级编号、名称和每个班的学生人数; + +-- 每个班的学生人数 + +SELECT si.class_id,count(id) from student_info si GROUP BY si.class_id + + +SELECT ci.id,ci.class_name,temp.stuCnt from class_info ci + +INNER JOIN (SELECT si.class_id,count(id) as stuCnt from student_info si GROUP BY si.class_id) temp on + +ci.id = temp.class_id; + +-- +-- 4.查询成绩信息表,并展示每位学生的编号、姓名、课程成绩、课程名称、科任教师名称; + +SELECT +si.student_id, + +(SELECT soi.student_name from student_info soi where soi.id = si.student_id) as student_name, + +(SELECT ci.course_name from course_info ci where ci.id = si.course_id) as course_name, + +(SELECT ti.teacher_name from course_info ci inner join teacher_info ti on ci.teacher_id = ti.id where ci.id = si.course_id) as teacher_name, + +si.score + +from score_info si + + +-- +-- 5.查询班级课程信息,并展示班级编号、课程名称; + +SELECT ci.id,coi.course_name from class_info ci + +inner join class_course cc on ci.id = cc.class_id + +INNER JOIN course_info coi on cc.course_id = coi.id; + + + +SELECT +cc.class_id, +(SELECT ci.course_name from course_info ci where cc.course_id = ci.id) as course_name +from class_course cc; + + +-- #### 1.子查询作为表(虚拟表) +-- +-- 示例1:查询每门课程的最高分信息:课程编号、课程名称和最高分信息 +-- +-- #### 2.子查询作为列(只能使用一个列) +-- +-- 示例1:查询学生的成绩信息:学生id,姓名,课程名称,成绩 + + +-- +-- #### 3.带比较运算符的子查询(<、<=、=、>、>=、!=)(得出子查询只有一个值) + +-- 3.1带比较运算符的子查询 +-- +-- 示例1:查询成绩比平均成绩低的成绩信息 + +SELECT * from score_info where score < + +(select avg(score) from score_info si); + +-- +-- 示例2:查询选修课程数量与学号为1的选修课程数量一样多的其他学生的学号和姓名、选课数量 + +-- +-- 3.2带Having运算符的子查询 +-- +-- 示例1:查询平均成绩大于总平均成绩的学生编号、姓名、平均成绩 + +-- GROUP BY HAVING + +SELECT si.student_id,avg(score) from score_info si GROUP BY si.student_id + +HAVING avg(score) > (select avg(score) from score_info si); + + +-- +-- #### 4.带in、not in关键字的子查询 (得出的子查询是一个 某一个字段值的列表(可以是单个值,也可以是多个值)) +-- +-- in:在列表里面 +-- +-- 示例1:查询所有班级,并查询出这些班级的学生信息 + +SELECT * from student_info where class_id in (1,2,3); + + +SELECT * from student_info where class_id in (SELECT id from class_info); + +-- +-- 示例2:查询选修了课程编号为3和4的学生信息 + +SELECT * from student_info where id in ( + +SELECT DISTINCT si.student_id from score_info si where si.course_id in (3,4)); + +-- not in: +-- +-- 示例1: + +SELECT * from student_info where id not in ( + +SELECT DISTINCT si.student_id from score_info si where si.course_id in (3,4)); + + +-- +-- #### 5.带exists,not exists关键字的子查询 + +-- exists ,not EXISTS +-- +-- 示例1:查询成绩表中有成绩的学生信息 + +SELECT * from student_info si1 where exists(SELECT si2.student_id from score_info si2 where si1.id = si2.student_id); + + +SELECT * from student_info where id in( +SELECT DISTINCT student_id from score_info where score is not null); + +-- +-- 示例2:查询成绩表中没有成绩的学生信息 + +SELECT * from student_info si1 where not exists(SELECT si2.student_id from score_info si2 where si1.id = si2.student_id); \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/22\347\272\247MySQL\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\347\273\223\350\257\276\350\200\203\350\257\225.pdf" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/22\347\272\247MySQL\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\347\273\223\350\257\276\350\200\203\350\257\225.pdf" new file mode 100644 index 0000000000000000000000000000000000000000..31574b8c4cb0cee39d4bc8721ab5dd6f3ab539c8 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/22\347\272\247MySQL\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\347\273\223\350\257\276\350\200\203\350\257\225.pdf" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301.zip" new file mode 100644 index 0000000000000000000000000000000000000000..300466a25a13d91ab3a21e31b0efe27bd41ae46f Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\350\204\232\346\234\254.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\350\204\232\346\234\254.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b20a53be2c7741672e35f5fe1d90b39f595c423f --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\350\204\232\346\234\254.sql" @@ -0,0 +1,40 @@ +-- 删除数据库 +drop database if exists company; + +-- 创建公司数据库 +create database if not exists company; + +-- 使用该数据库 +use company; + +-- 创建员工表 +create table if not exists staff_info ( + id int(11) primary key, + staff_name varchar(255), + staff_age int(2), + staff_sex int(1), + staff_phone varchar(11), + staff_email varchar(255), + staff_address varchar(255), + staff_brtime datetime(0), + staff_time datetime(0), + dept_id int(11) +); + +-- 插入员工数据 +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_email,staff_address,staff_brtime,staff_time,dept_id) values +(1,'张三',23,1,'15103021550','12313@qq.com','福建省厦门市集美区','2001-01-02','2011-02-03 08:23:35',1), +(2,'李四',21,1,'15803021550','52353@qq.com','福建省泉州市泉港区','2003-03-04','2013-05-18 12:50:01',2), +(3,'王丽',43,2,'15105021500','17810@qq.com','福建省福州市马尾区','1981-07-13','2017-08-03 01:31:50',3), +(4,'徐艳',29,2,'18103021732','98003@qq.com','广东省广州市白云区','1995-08-08','2013-11-20 09:10:11',3), +(5,'欧阳琳',28,2,'19103022380','12213@qq.com','云南省丽江市古城区','1996-05-23','2009-11-10 17:32:35',2), +(6,'徐真',25,1,'15003227850','12388@qq.com','广西壮族自治区桂林市秀峰区','1999-01-02','2013-02-25 08:23:35',1), +(7,'王鑫路',36,1,'15903121600','52360@qq.com','河南省周口西华县','1988-03-04','2017-06-18 12:50:01',2), +(8,'劳拉',32,2,'17308821533','17819@qq.com','福建省龙岩市永定区','1992-07-13','2015-05-19 01:31:50',1), +(9,'田雨',32,2,'18013121755','98013@qq.com','浙江省杭州市西湖区','1992-08-08','2022-10-21 09:10:11',1) +; + +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_address,staff_brtime,staff_time,dept_id) values +(10,'爱新觉罗·吉吉',35,2,'13588025381','内蒙古自治区呼和浩特市新城区','1989-05-23','2008-09-11 17:32:35',2); \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\351\242\230\347\233\256.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\351\242\230\347\233\256.sql" new file mode 100644 index 0000000000000000000000000000000000000000..0f1de06b83948e562b5bce104a9001e904a696cd --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\351\242\230\347\233\256.sql" @@ -0,0 +1,26 @@ +-- 1.查询所有的员工信息 + +-- 2.查询所有员工的员工姓名、年龄、手机号码、地址信息 + +-- 3.查询所有员工的员工姓名、年龄、手机号码、地址信息,使用字段别名进行查询 + +-- 4.查询员工年龄等于25岁的员工信息 + +-- 5.查询员工部门不是1的员工信息 + +-- 6.查询员工年龄大于20岁的员工信息 + +-- 7.查询员工年龄在20岁和35岁之间的员工信息 + +-- 8.查询员工信息中,没有邮箱信息的员工 + +-- 9.查询员工信息中,有邮箱信息的员工的姓名、年龄、手机号码、邮箱 + +-- 10.查询不在部门1和2中的员工 + +-- 11.查询员工信息中,名字带有"王"的员工信息 + +-- 12.查询员工信息中,地址以"福建省"开头的员工信息 + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b20a53be2c7741672e35f5fe1d90b39f595c423f --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" @@ -0,0 +1,40 @@ +-- 删除数据库 +drop database if exists company; + +-- 创建公司数据库 +create database if not exists company; + +-- 使用该数据库 +use company; + +-- 创建员工表 +create table if not exists staff_info ( + id int(11) primary key, + staff_name varchar(255), + staff_age int(2), + staff_sex int(1), + staff_phone varchar(11), + staff_email varchar(255), + staff_address varchar(255), + staff_brtime datetime(0), + staff_time datetime(0), + dept_id int(11) +); + +-- 插入员工数据 +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_email,staff_address,staff_brtime,staff_time,dept_id) values +(1,'张三',23,1,'15103021550','12313@qq.com','福建省厦门市集美区','2001-01-02','2011-02-03 08:23:35',1), +(2,'李四',21,1,'15803021550','52353@qq.com','福建省泉州市泉港区','2003-03-04','2013-05-18 12:50:01',2), +(3,'王丽',43,2,'15105021500','17810@qq.com','福建省福州市马尾区','1981-07-13','2017-08-03 01:31:50',3), +(4,'徐艳',29,2,'18103021732','98003@qq.com','广东省广州市白云区','1995-08-08','2013-11-20 09:10:11',3), +(5,'欧阳琳',28,2,'19103022380','12213@qq.com','云南省丽江市古城区','1996-05-23','2009-11-10 17:32:35',2), +(6,'徐真',25,1,'15003227850','12388@qq.com','广西壮族自治区桂林市秀峰区','1999-01-02','2013-02-25 08:23:35',1), +(7,'王鑫路',36,1,'15903121600','52360@qq.com','河南省周口西华县','1988-03-04','2017-06-18 12:50:01',2), +(8,'劳拉',32,2,'17308821533','17819@qq.com','福建省龙岩市永定区','1992-07-13','2015-05-19 01:31:50',1), +(9,'田雨',32,2,'18013121755','98013@qq.com','浙江省杭州市西湖区','1992-08-08','2022-10-21 09:10:11',1) +; + +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_address,staff_brtime,staff_time,dept_id) values +(10,'爱新觉罗·吉吉',35,2,'13588025381','内蒙古自治区呼和浩特市新城区','1989-05-23','2008-09-11 17:32:35',2); \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" new file mode 100644 index 0000000000000000000000000000000000000000..acff1dbd043cbe5370d9092f4b520324191078da --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" @@ -0,0 +1,28 @@ +-- 1.查询所有员工姓名、年龄、手机号码信息 + +-- 2.查询所有员工信息,以年龄倒序排列 + +-- 3.查询一共有多少个员工 + +-- 4.查询员工的总年龄为多少 + +-- 5.查询员工的平均年龄是多少 + +-- 6.查询员工中最小的年龄是多少 + +-- 7.查询员工中最大的年龄是多少 + +-- 8.查询员工数量,按部门编号分组 + +-- 9.查询部门编号为1的员工数量和部门编号 + +-- 10.查询每个部门的部门编号和员工数量,同时按照员工数量倒序排列 + +-- 11.查询每个部门员工数量大于2个的部门编号和员工数量 + +-- 12.查询所有员工信息,并按年龄升序排列,且展示前3条数据 + +-- 13.查询员工表中,男性和女性的员工数量 + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" new file mode 100644 index 0000000000000000000000000000000000000000..2712b46603d6fa9be1e30538767b2fe973feb8a6 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" @@ -0,0 +1,51 @@ +-- 删除数据库 +drop database if exists company; + +-- 创建公司数据库 +create database if not exists company; + +-- 使用该数据库 +use company; + +-- 创建客户表 +create table if not exists staff_info ( + id int(11) primary key, + staff_name varchar(255), + staff_age int(2), + staff_sex int(1), + staff_phone varchar(11), + staff_email varchar(255), + staff_address varchar(255), + staff_brtime datetime(0), + staff_time datetime(0), + dept_id int(11) +); + +-- 创建部门表 +create table if not exists dept_info ( + id int(11) primary key, + dept_name varchar(255) +); + +-- 插入员工数据 +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_email,staff_address,staff_brtime,staff_time,dept_id) values +(1,'张三',23,1,'15103021550','12313@qq.com','福建省厦门市集美区','2001-01-02','2011-02-03 08:23:35',1), +(2,'李四',21,1,'15803021550','52353@qq.com','福建省泉州市泉港区','2003-03-04','2013-05-18 12:50:01',2), +(3,'王丽',43,2,'15105021500','17810@qq.com','福建省福州市马尾区','1981-07-13','2017-08-03 01:31:50',3), +(4,'徐艳',29,2,'18103021732','98003@qq.com','广东省广州市白云区','1995-08-08','2013-11-20 09:10:11',3), +(5,'欧阳琳',28,2,'19103022380','12213@qq.com','云南省丽江市古城区','1996-05-23','2009-11-10 17:32:35',2), +(6,'徐真',25,1,'15003227850','12388@qq.com','广西壮族自治区桂林市秀峰区','1999-01-02','2013-02-25 08:23:35',2), +(7,'王鑫路',36,1,'15903121600','52360@qq.com','河南省周口西华县','1988-03-04','2017-06-18 12:50:01',2), +(8,'劳拉',32,2,'17308821533','17819@qq.com','福建省龙岩市永定区','1992-07-13','2015-05-19 01:31:50',1), +(9,'田雨',32,2,'18013121755','98013@qq.com','浙江省杭州市西湖区','1992-08-08','2022-10-21 09:10:11',2) +; + +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_email,staff_address,staff_brtime,staff_time) values +(10,'爱新觉罗·吉吉',35,2,'13588025381','78610@qq.com','内蒙古自治区呼和浩特市新城区','1989-05-23','2008-09-11 17:32:35'); + +-- 插入部门数据 +insert into dept_info(id,dept_name) values(1,'软件部'),(2,'信息部'),(3,'人力部'); + +insert into dept_info(id,dept_name) values(4,'后勤部'); diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" new file mode 100644 index 0000000000000000000000000000000000000000..ab20fed35384c81aba4322391884989ab9e45355 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" @@ -0,0 +1,39 @@ +-- 1.查询员工表中,前5条的数据 + +-- 2.从第2条开始,查询5条数据 + +-- 3.查询第1页,每页3条员工信息 + +-- 4.查询第2页,每页3条员工信息 + +-- 5.查询第3页,每页3条员工信息 + +-- 6.查询不在部门1和2中的员工信息 + +-- 7.查询部门在1和2中的员工信息 + +-- 8.查询年龄比平均年龄大的员工信息 + +-- 9.查询出年龄比编号为1的员工的年龄都高的员工信息 + +-- 10.查询员工信息表中的员工姓名、年龄、部门名称 + +-- 11.查询部门中,没有员工的部门信息 + +-- 12.查询部门中,有员工的部门信息 + +-- 13.查询员工的姓名和部门信息 + +-- 14.使用左外连接查询员工的姓名和部门信息 + +-- 15.使用右外连接查询员工的姓名和部门信息 + +-- 16.查询软件部(编号为1)的员工姓名、年龄、手机号码及部门名称 + +-- 17.按照部门分组,查询每个部门的部门名称和员工数量,按员工数量倒序排列 + +-- 18.查询每个部门的最高年龄的员工部门信息和最大年龄 + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/\347\255\224\351\242\230.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/\347\255\224\351\242\230.sql" new file mode 100644 index 0000000000000000000000000000000000000000..1e7bfde0654a9b2a2458886b25765062576ee3a5 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/\347\255\224\351\242\230.sql" @@ -0,0 +1,106 @@ +drop database if not exists film; +create database if not exists film; + +use film; + +drop table if not exists movie; +drop table if not exists room; +drop table if not exists plan; + +create table if not exists movie( + movie_id int primary key auto_increment comment '影片编号', + movie_name varchar(30) unique not null comment '影片名称', + actor varchar(100) not null comment '主演', + director varchar(30) not null comment '导演', + type char(2) not null comment '影片类型', + lang varchar(30) not null comment '语种', + price decimal(5,2) not null comment '票价', + movie_time int not null comment '时长(以分钟为单位)' +) comment '影片信息表'; + +create table if not exists room( + room_id int primary key auto_increment comment '影厅编号', + room_name varchar(10) not null unique comment '影厅名称', + number int not null comment '座位数量' +) comment '放映厅信息表'; + +create table if not exists plan( + plan_id int comment '计划编号', + plan_time datetime not null comment '排片时间', + room_id int not null comment '影厅编号', + movie_id int not null comment '影片编号', + constraint fk_room_id foreign key (room_id) references room(room_id), + constraint fk_movie_id foreign key (movie_id) references movie(movie_id) +) comment '排片计划表'; + +insert into if not exists movie(movie_name,actor,director,type,lang,price,movie_time)values +('流浪地球','吴磊,刘德华,李雪健','郭帆','科幻','汉语',65.9,173), +('满江红','沈腾,易烊千玺,张译','张艺谋','喜剧','汉语',55.9,159), +('釜山行','孔刘,郑有美','延尚昊','惊悚','韩语',55.5,118), +('肖申克的救赎','蒂姆,摩根','弗兰克','犯罪','英语',98.8,142), +('千与千寻','柊瑠美,入野自由','宫崎骏','动画','日语',39.5,125), +('三傻大闹宝莱坞','阿米尔,卡琳娜 ','拉吉库马尔','喜剧','印地语',42.5,171), +('战狼','吴京,余男','吴磊','动作','汉语',67.5,90), +('盛夏未来','张子枫,吴磊','陈正道','剧情','汉语',30,115), +('这个杀手不太冷','雷诺,娜塔莉,波特曼,奥德曼','吕克贝松','动作','英语',66,110), +('泰坦尼克号','迪卡普里奥,温丝莱特','卡梅隆','爱情','英语',80,194); + +insert into if not exists room(room_name,number)values +('亲子迷你厅',100), +('巨幕VIP厅 ',400), +('自由人情侣厅 ',300), +('IMAX厅',600), +('大匠堂 ',2000); + +insert into if not exists plan(plan_time,room_id,movie_id)values +('2023-03-13 15:00:00',4,4), +('2023-03-13 15:00:00',2,3), +('2023-03-14 15:00:00',3,1), +('2023-03-14 21:00:00',2,2), +('2023-03-14 22:00:00',3,6), +('2023-03-15 23:00:00',4,2); + + +查询: +-- 4. 查询语种是汉语且票价大于50元的电影( 3分 ) +select * +from movie +where lang = '汉语' and price > 50; +-- 5. 电影信息表中的《战狼》的导演写成了吴磊,请更新为吴京( 3分 ) +update movie +set director = '吴京' +where director = '战狼'; +-- 6. 请删除放映厅中,名称为大匠堂的那条记录( 3分 ) +delete from room where room_name = '大匠堂'; +-- 7. 查询所有影片的名称、主演、导演、类型及票价, 并按票价降序排列 ( 6分 ) +select movie_name '名称', +actor '主演', +director '导演', +type '类型', +price '票价' +from movie +order by price desc; +-- 8. 查询名称中含有“VIP”的影厅,要求使用别名显示影厅名称和座位数量 ( 5分 ) +select room_name '影厅名称', +number '座位数量' +from room +where room_name like '%VIP%'; +-- 9. 查询座位数在300到500之间(含300和500)的放映厅信息( 5分 ) +select * +from room +where number between 300 and 500; +-- 10. 查询每种类型电影的数量,平均票价,最高票价,只显示平均票价大于50元的 ( 10分 ) +select type, +avg(price) '平均票价', +max(price) '最高票价' +from movie +group by type having avg(price) > 50; +-- 11. 查询在排片计划表中那些电影的排片时间,放映厅名称,电影名称,主演名称和时长 ( 15分 ) +select pl.plan_time '排片时间', +ro.room_name '放映厅名称', +mo.movie_name '电影名称', +mo.actor '主演名称', +mo.movie_time '时长' +from plan pl +inner join room ro on ro.room_id = pl.room_id +inner join movie mo on mo.movie_id = pl.movie_id; \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/\350\257\276\345\240\202\347\254\224\350\256\260.txt" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/\350\257\276\345\240\202\347\254\224\350\256\260.txt" new file mode 100644 index 0000000000000000000000000000000000000000..c934c2edea06f700e1153549c50c40893153aa1d --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.3.28/\350\257\276\345\240\202\347\254\224\350\256\260.txt" @@ -0,0 +1,84 @@ +-- 1:查询成绩比平均成绩低的成绩信息 +SELECT * from score_info si WHERE score<(SELECT avg(score) FROM score_info); + +-- +-- 2:查询选修课程数量与学号为1的选修课程数量一样多 的 其他学生 的学号和姓名、选课数量 + +-- 学号和姓名 + +SELECT * from student_info si; + +-- 学号为1的选课数量 + +SELECT count(id) from score_info si where si.student_id = 1 + +-- 学生选修课程数量 + +SELECT si.id,si.student_name,temp.cnt from student_info si +inner join +(SELECT si.student_id,count(id) as cnt from score_info si +GROUP BY si.student_id HAVING cnt = (SELECT count(id) from score_info si where si.student_id = 1)) temp on +si.id = temp.student_id +where si.id <> 1; + +-- +-- 3:查询平均成绩大于总平均成绩的学生编号、姓名、平均成绩 +SELECT * FROM student_info si INNER JOIN (SELECT student_id,AVG(score) as avg_score +FROM score_info GROUP BY student_id) temp1 on si.id = temp1.student_id WHERE temp1.avg_score > +(SELECT AVG(score) FROM score_info) + + +SELECT * FROM student_info si INNER JOIN (SELECT student_id,AVG(score) as avg_score +FROM score_info GROUP BY student_id HAVING avg_score > (SELECT AVG(score) FROM score_info) ) +temp1 on si.id = temp1.student_id + + +-- +-- 4:查询所有班级,并查询出这些班级的学生信息 + +select * from student_info where class_id in (select id from class_info); + +-- +-- 5:查询选修了课程编号为3和4的学生信息 + +-- +-- 6:查询没有选修课程编号为3和4的学生信息 +-- +-- 7:查询成绩表中有成绩的学生信息 +-- +-- 8:查询成绩表中没有成绩的学生信息 + + + +-- all()函数 + +-- 查询出成绩比课程编号1的所有成绩都高的成绩信息 + +-- 第一步:先查出课程编号为1的最高成绩 + +SELECT max(score) from score_info where course_id = 3; + +-- 第二步: 再查成绩表,条件 比课程编号为1的课程最高分还大 + +SELECT * from score_info where score > (SELECT max(score) from score_info where course_id = 1); + + +-- 语法:SELECT * from 表A where 字段 > all(SELECT * from 表B where 条件) + +SELECT * from score_info si1 where si1.score > all(SELECT si2.score from score_info si2 where si2.course_id = 3 ); + + +-- any、some + +-- 查询出成绩比课程编号1的任意一个成绩高的成绩信息 + +-- 任意一个成绩高 + +SELECT min(score) from score_info where course_id = 1; + +SELECT * from score_info where score > (SELECT min(score) from score_info where course_id = 1); + + +SELECT * from score_info si1 where si1.score > any(SELECT si2.score from score_info si2 where si2.course_id = 1 ); + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.01/\347\272\246\346\235\237\346\226\260\345\242\236.txt" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.01/\347\272\246\346\235\237\346\226\260\345\242\236.txt" new file mode 100644 index 0000000000000000000000000000000000000000..eaa59ed1c5714edc71f88f088a19eeab91a1aa4a --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.01/\347\272\246\346\235\237\346\226\260\345\242\236.txt" @@ -0,0 +1,172 @@ +-- 1.查询员工表中,前5条的数据 + +select * from staff_info limit 0,5; + +-- 2.从第2条开始,查询5条数据 + +select * from staff_info limit 1,5; + + +-- 3.查询第1页,每页3条员工信息 +select*from staff_info limit 0,3; -- (n-1)*条数,条数 +-- 4.查询第2页,每页3条员工信息 +select*from staff_info limit 3,3; +-- 5.查询第3页,每页3条员工信息 +select*from staff_info limit 6,3; + +-- 6.查询不在部门1和2中的员工信息 + +SELECT * FROM staff_info WHERE dept_id not in (1,2) + + -- 7.查询部门在1和2中的员工信息 + + SELECT * FROM staff_info WHERE dept_id in (1,2) + + +-- 8.查询年龄比平均年龄大的员工信息 + +SELECT * FROM staff_info WHERE staff_age>(SELECT AVG(staff_age) FROM staff_info ) + +-- 9.查询出年龄比编号为1的员工的年龄都高的员工信息 + +SELECT * FROM staff_info WHERE staff_age>(SELECT max(staff_age) FROM staff_info where id=1) + +-- 10.查询员工信息表中的员工姓名、年龄、部门名称(别名) +SELECT si.name , si.age, di.dept_name + from (SELECT staff_name as name , staff_age as age, dept_id from staff_info) si INNER JOIN dept_info di on + si.dept_id = di.id + + SELECT si.staff_name as '姓名',si.staff_age as '年龄',di.dept_name as '部门名称' from staff_info si + inner join dept_info di on si.dept_id = di.id; + + +-- 11.查询部门中,没有员工的部门信息 + +SELECT di.* from staff_info si RIGHT JOIN dept_info di on si.dept_id = di.id + +where si.dept_id is null; + + +SELECT * from dept_info di where not exists(select * from staff_info si where si.dept_id = di.id); + +-- 12.查询部门中,有员工的部门信息 + +SELECT di.* from staff_info si RIGHT JOIN dept_info di on si.dept_id = di.id + +where si.dept_id is not null; + + +SELECT * from dept_info di where exists(select * from staff_info si where si.dept_id = di.id); + +-- 10分钟 + +-- 13.查询员工的姓名和部门信息 +select s.staff_name,d.dept_name from dept_info d +inner join staff_info s on d.id= s.dept_id; +-- 14.使用左外连接查询员工的姓名和部门信息 +select s.staff_name,d.dept_name from dept_info d +left join staff_info s on d.id = s.dept_id; +-- 15.使用右外连接查询员工的姓名和部门信息 +select s.staff_name,d.dept_name from dept_info d +right join staff_info s on d.id = s.dept_id; + +-- 16.查询软件部(编号为1)的员工姓名、年龄、手机号码及部门名称 +SELECT st.staff_name,st.staff_age,st.staff_phone,de.dept_name FROM +dept_info de JOIN staff_info st on de.id = st.dept_id and de.id = 1 + +-- 17.按照部门分组,查询每个部门的部门名称和员工数量,按员工数量倒序排列 +SELECT de.dept_name,u.y FROM dept_info de JOIN +(SELECT dept_id,count(id) as y FROM staff_info GROUP BY dept_id) u on de.id = u.dept_id ORDER BY u.y DESC + +-- 18.查询每个部门的最高年龄的员工部门信息和最大年龄 +SELECT de.id,de.dept_name,u.m FROM dept_info de JOIN +(SELECT dept_id,max(staff_age) as m FROM staff_info GROUP BY dept_id) u on de.id = u.dept_id + + + + + + +-- 新增数据 +-- INSERT into 表名(字段1,字段2)VALUES(字段值1,字段值2); + +INSERT into dept_info(id,dept_name)VALUES(5,'djapoaijk'); + +-- 主键自增 约束 + +-- 新增主键约束语法:alter table 数据表名 add primary key(字段名); + +ALTER TABLE dept_info add PRIMARY key (id); + +-- CREATE TABLE 表名( +-- 字段1 数据类型(长度) primary key, +-- 字段2 数据类型(长度) +-- ); + +CREATE TABLE dept_info_id( + id int(11) primary key, + dept_name VARCHAR(255) +); + + +-- 删除主键约束语法:alter table 数据表名 drop primary key; + +ALTER TABLE dept_info_id drop PRIMARY key; + +-- 主键自增长 + +-- alter table 数据表名 modify 字段名 数据类型 primary key auto_increment; + +ALTER TABLE dept_info MODIFY id int primary key auto_increment; + +INSERT into dept_info(dept_name)VALUES('资源部'); + +select * from dept_info; + +-- 删除自增约束和主键约束 + +-- alter table 数据表名 modify 字段名 int not null; + +-- alter table 数据表名 drop primary key; + +alter table dept_info modify id int not null; + +alter table dept_info drop primary key; + + +CREATE TABLE dept_info_id( + id int(11) primary key auto_increment , + dept_name VARCHAR(255) +); + + +-- ALTER TABLE 表名 +-- ADD CONSTRAINT 外键约束名 +-- FOREIGN KEY (外键是哪个字段名) +-- REFERENCES 关联表名(关联列名) + + +alter table staff_info +add constraint fk_deptinfoid +foreign key (dept_id) +references dept_info(id); + + +ALTER TABLE staff_info add primary key(id); + +CREATE TABLE student_info ( + id int(11) primary key auto_increment NOT NULL, -- 主键、自增、非空 + student_name varchar(255) not null, -- 非空 + student_age varchar(255) default 0, -- 默认值 + student_sex varchar(255) , + student_time datetime(0) , + class_id int(11), + unique(class_id), -- 唯一 + constraint fk_classid foreign key (class_id) REFERENCES staff_info(id) -- 外键 +); + + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230.zip" new file mode 100644 index 0000000000000000000000000000000000000000..0a0b4bcdd3e4d5e563a4e354f1512968319f183e Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\346\225\260\346\215\256\350\241\250.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\346\225\260\346\215\256\350\241\250.sql" new file mode 100644 index 0000000000000000000000000000000000000000..013d699d7d5a63ad89be9af1827081cc5fc40ad3 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\346\225\260\346\215\256\350\241\250.sql" @@ -0,0 +1,88 @@ +CREATE DATABASE if not exists Student_Manager; + +use Student_Manager; + +drop table if exists Student; +drop table if exists Course; +drop table if exists Teacher; +drop table if exists Score; + +-- 创建学生表 +CREATE TABLE Student +( +s_id VARCHAR(20), +s_name VARCHAR(20) NOT NULL, +s_birth VARCHAR(20) NOT NULL, +s_sex VARCHAR(10) NOT NULL, +PRIMARY KEY(s_id) +); + + + +-- 创建课程表 +CREATE TABLE Course +( +c_id VARCHAR(20), +c_name VARCHAR(20) NOT NULL, +t_id VARCHAR(20) NOT NULL, +PRIMARY KEY(c_id) +); + +-- 创建教师表 +CREATE TABLE Teacher +( +t_id VARCHAR(20), +t_name VARCHAR(20) NOT NULL DEFAULT '', +PRIMARY KEY(t_id) +); + +-- 创建成绩表 (联合主键) +CREATE TABLE Score +( +s_id VARCHAR(20), +c_id VARCHAR(20), +s_score INT(3), +PRIMARY KEY(s_id, c_id) +); + +-- 插入学生表测试数据 +INSERT INTO Student VALUES('01', '赵雷', '1990-01-01', '男'); +INSERT INTO Student VALUES('02', '钱电', '1990-12-21', '男'); +INSERT INTO Student VALUES('03', '孙风', '1990-05-20', '男'); +INSERT INTO Student VALUES('04', '李云', '1990-08-06', '男'); +INSERT INTO Student VALUES('05', '周梅', '1991-12-01', '女'); +INSERT INTO Student VALUES('06', '吴兰', '1992-03-01', '女'); +INSERT INTO Student VALUES('07', '郑竹', '1989-07-01', '女'); +INSERT INTO Student VALUES('08', '王菊', '1990-01-20', '女'); + + +-- 课程表测试数据 +INSERT INTO Course VALUES('01', '语文', '02'); +INSERT INTO Course VALUES('02', '数学', '01'); +INSERT INTO Course VALUES('03', '英语', '03'); + +-- 教师表测试数据 +INSERT INTO Teacher VALUES('01', '张三'); +INSERT INTO Teacher VALUES('02', '李四'); +INSERT INTO Teacher VALUES('03', '王五'); + +-- 成绩表测试数据 +INSERT INTO Score VALUES('01', '01', 80); +INSERT INTO Score VALUES('01', '02', 90); +INSERT INTO Score VALUES('01', '03', 99); +INSERT INTO Score VALUES('02', '01', 70); +INSERT INTO Score VALUES('02', '02', 60); +INSERT INTO Score VALUES('02', '03', 80); +INSERT INTO Score VALUES('03', '01', 80); +INSERT INTO Score VALUES('03', '02', 80); +INSERT INTO Score VALUES('03', '03', 80); +INSERT INTO Score VALUES('04', '01', 50); +INSERT INTO Score VALUES('04', '02', 30); +INSERT INTO Score VALUES('04', '03', 20); +INSERT INTO Score VALUES('05', '01', 76); +INSERT INTO Score VALUES('05', '02', 87); +INSERT INTO Score VALUES('06', '01', 31); +INSERT INTO Score VALUES('06', '03', 34); +INSERT INTO Score VALUES('07', '02', 89); +INSERT INTO Score VALUES('07', '03', 98); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\351\242\230\347\233\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\351\242\230\347\233\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..82b2e35cfb7028f025b9fb56c846f247a0d1e144 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\351\242\230\347\233\256.md" @@ -0,0 +1,107 @@ +**练习题** + +1.查询课程编号为01的课程比02的课程成绩高的所有学生的学号和成绩; + +2.查询平均成绩大于60分的学生的学号和平均成绩; + +3.查询所有成绩小于60分的学生信息; + +4.查询平均成绩小于60分的学生的学号和平均成绩,考虑没参加考试的情况; + +5.查询所有学生的学号、姓名、选课数、总成绩; + +6.查询姓"猴"的老师的个数; + +7.查询没学过"张三"老师课的学生的学号、姓名; + +8.查询学过"张三"老师所教的所有课的同学的学号、姓名; + +9.查询学过编号为'01'的课程并且也学过编号为'02'的课程的学生的学号、姓名; + +10.查询学过编号为'01'的课程但没有学过编号为'02'的课程的学生的学号、姓名; + +11.查询课程编号为'02'的总成绩; + +12.查询所有课程成绩小于60分的学生的学号、姓名; + +13.查询没有学全所有课的学生的学号、姓名; + +14.查询至少有一门课与学号为'01'的学生所学课程相同的学生的学号、姓名; + +15.查询和'01'号同学所学课程完全相同的其他同学的学号; + +16.查询没学过'张三'老师讲授的任一门课程的学生姓名; + +17.查询两门及其以上不及格课程的同学的学号、姓名及其平均成绩; + +18.查询'01'课程分数小于60,按分数降序排列的学生信息; + +19.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩; + +20.查询各科成绩最高分、最低分和平均分:以如下形式显示: + +– 课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率 +– (及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90) (!!) + +; + +21.按各科成绩进行排序,并显示排名; + +22.查询学生的总成绩并进行排名; + +23.查询不同老师所教不同课程平均分从高到低显示; + +24.查询所有课程的成绩第2名到第3名的学生信息及该课程成绩; + +25.使用分段[100-85],[85-70],[70-60],[<60]来统计各科成绩,分别统计各分数段人数:课程ID和课程名称; + +26.查询学生平均成绩及其名次; + +27.查询各科成绩前三名的记录; + +28.查询每门课程被选修的记录数; + +29.查询出只有两门课程的全部学生的学号和姓名; + +30.查询男生、女生人数; + +31.查询1990年出生的学生名单; + +32.查询平均成绩大于等于85的所有学生的学号、姓名和平均成绩; + +33.查询每门课程的平均成绩,结果按平均成绩升序排序,平均成绩相同时,按课程号降序排序; + +34.查询课程名称为"数学",且分数低于60的学生姓名和分数; + +35.查询所有学生的课程及分数情况(存在学生没成绩,没选课的情况); + +36.查询任何一门课程成绩在70分以上的姓名、课程名称和分数; + +37.查询学生不及格的课程并按课程号从大到小排列; + +38.查询课程编号为03且课程成绩在80分以上的学生的学号和姓名; + +39.求每门课程的学生人数; + +40.查询选修"张三"老师所授课程的学生中成绩最高的学生姓名及其成绩; + +41.查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩; + +42.查询每门课程成绩最好的前两名学生信息; + +43.统计每门课程的学生选修人数(超过5人的课程才统计); + +44.检索至少选修两门课程的学生学号; + +45.查询选修了全部课程的学生信息; + +46.查询各学生的年龄(精确到月份); + +47.查询没学过“张三”老师讲授的任一门课程的学生姓名; + +48.查询两门以上不及格课程的同学; + +49.查询本月过生日的学生; + +50.查询本周过生日的学生; + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/\347\255\224\346\241\210.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/\347\255\224\346\241\210.sql" new file mode 100644 index 0000000000000000000000000000000000000000..d11a50aefd6de69fe8bc17a2fbfa9b8cb6d9b689 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/\347\255\224\346\241\210.sql" @@ -0,0 +1,225 @@ +**练习题** + +1.查询课程编号为01的课程比02的课程成绩高的所有学生的学号和成绩; +select sc.s_id '学号', +sc.s_score '01成绩', +sc2.s_score '02成绩' +from (select s_id,s_score from score where c_id = 1 group by s_id,s_score) sc +inner join (select s_id,s_score from score where c_id = 2 group by s_id,s_score) sc2 on sc.s_id = sc2.s_id +where sc.s_score > sc2.s_score +2.查询平均成绩大于60分的学生的学号和平均成绩; +select s_id '学号', +avg(s_score) '平均成绩' +from score +group by s_id having avg(s_score) > 60; +3.查询所有成绩小于60分的学生信息; +select distinct st.* +from score sc +inner join student st on st.s_id = sc.s_id +where sc.s_score < 60 +4.查询平均成绩小于60分的学生的学号和平均成绩,考虑没参加考试的情况; +select st.s_id '学号', +sc.avg_score '平均成绩' +from student st +left join (select s_id,avg(s_score) 'avg_score' from score group by s_id) sc on sc.s_id = st.s_id +where sc.avg_score < 60 or sc.avg_score is null; +5.查询所有学生的学号、姓名、选课数、总成绩; +select st.s_id '学号', +st.s_name '姓名', +count(sc.s_id) '选课数量', +sum(sc.s_score) '总成绩' +from student st +left join score sc on sc.s_id = st.s_id +group by sc.s_id,st.s_id +6.查询姓"猴"的老师的个数; +select count(t_id) +from teacher +where t_name like '猴%'; +7.查询没学过"张三"老师课的学生的学号、姓名; +select s_id '学号', +s_name '姓名' +from student +where s_id not in(select sc.s_id from student st inner join score sc on sc.s_id = st.s_id group by sc.s_id,sc.c_id having sc.c_id = (select co.c_id from course co where co.t_id = (select t_id from teacher where t_name = '张三'))); +8.查询学过"张三"老师所教的所有课的同学的学号、姓名; +select s_id '学号', +s_name '姓名' +from student +where s_id in(select sc.s_id from student st inner join score sc on sc.s_id = st.s_id group by sc.s_id,sc.c_id having sc.c_id = (select co.c_id from course co where co.t_id = (select t_id from teacher where t_name = '张三'))); +9.查询学过编号为'01'的课程并且也学过编号为'02'的课程的学生的学号、姓名; +select s_id '学号', +s_name '姓名' +from student +where s_id in(select sc.s_id from student st inner join score sc on sc.s_id = st.s_id group by sc.s_id,sc.c_id having sc.c_id = 1) +and s_id in(select sc.s_id from student st inner join score sc on sc.s_id = st.s_id group by sc.s_id,sc.c_id having sc.c_id = 2); +10.查询学过编号为'01'的课程但没有学过编号为'02'的课程的学生的学号、姓名; +select s_id '学号', +s_name '姓名' +from student +where s_id in(select sc.s_id from student st inner join score sc on sc.s_id = st.s_id group by sc.s_id,sc.c_id having sc.c_id = 1) +and s_id not in(select sc.s_id from student st inner join score sc on sc.s_id = st.s_id group by sc.s_id,sc.c_id having sc.c_id = 2); +11.查询课程编号为'02'的总成绩; +select sum(s_score) +from score +where c_id = 2; +12.查询所有课程成绩小于60分的学生的学号、姓名; +select distinct st.s_id '学号', +st.s_name '姓名' +from score sc +inner join student st on st.s_id = sc.s_id +group by sc.s_id,s_score having s_score < 60; +13.查询没有学全所有课的学生的学号、姓名; +select st.s_id '学号', +st.s_name '姓名' +from score sc +inner join student st on st.s_id = sc.s_id +group by sc.s_id having count(sc.c_id) <> (select count(c_id) from course); +14.查询至少有一门课与学号为'01'的学生所学课程相同的学生的学号、姓名; +select distinct s_id +from score +where s_id not in +(select s_id from score where c_id not in(select c_id from score where s_id = 1)) +group by s_id having count(c_id) >= 1 +and s_id <> 1; +15.查询和'01'号同学所学课程完全相同的其他同学的学号; +select distinct s_id +from score +where s_id not in +(select s_id from score where c_id not in(select c_id from score where s_id = 1)) +group by s_id having count(c_id) = +(select count(c_id) from score where s_id = 1) +and s_id <> 1; +16.查询没学过'张三'老师讲授的任一门课程的学生姓名; +select st.s_name '姓名' +from student st +where st.s_id not in (select sc.s_id from score sc group by sc.s_id,sc.c_id having sc.c_id = +(select co.c_id from teacher te inner join course co on co.t_id = te.t_id where te.t_name = '张三')); +17.查询两门及其以上不及格课程的同学的学号、姓名及其平均成绩; +select st.id,count(st.s_id) +from student st +inner join (select s_id,s_score from score group by s_id,s_score having s_score < 60) sc on sc.s_id = st.s_id +group by st.s_id +18.查询'01'课程分数小于60,按分数降序排列的学生信息; +select st.* +from score sc +inner join student st on st.s_id = sc.s_id +where sc.s_score < 60 and sc.c_id = 1 +order by sc.s_score desc; +19.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩; +select sc1.* , +avg_score +from score sc1 +inner join (select s_id,avg(s_score) as 'avg_score' from score group by s_id) sc2 on sc2.s_id = sc1.s_id +order by avg_score +20.查询各科成绩最高分、最低分和平均分:以如下形式显示: +select sc.c_id '课程ID', +co.c_name '课程名称', +max(sc.s_score) '最高分', +min(sc.s_score) '最低分', +avg(sc.s_score) '平均分', +sum(及格) / count(a.s_id) '及格率', +sum(中等) / count(a.s_id) '中等率', +sum(优良) / count(a.s_id) '优良率', +sum(优秀) / count(a.s_id) '优秀率' +from score sc +inner join course co on co.c_id = sc.c_id +inner join (select *, + case + when s_score >= 60 + then 1 + else 0 + end 及格, + + case + when s_score >= 70 and s_score < 80 + then 1 + else 0 + end 中等, + + case + when s_score >= 80 and s_score < 90 + then 1 + else 0 + end 优良, + + case + when s_score >= 90 + then 1 + else 0 + end 优秀 + from score) a on a.s_id = sc.s_id +group by sc.c_id; +-- 课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率 +-- (及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90) (!!) +21.按各科成绩进行排序,并显示排名; +select c_id,s_score +from score +group by c_id,s_score +order by s_score; +22.查询学生的总成绩并进行排名; +select s_id '学生ID', +sum(s_score) '总成绩' +from score +group by s_id +order by sum(s_score) desc; +23.查询不同老师所教不同课程平均分从高到低显示; + +24.查询所有课程的成绩第2名到第3名的学生信息及该课程成绩; + +25.使用分段[100-85],[85-70],[70-60],[<60]来统计各科成绩,分别统计各分数段人数:课程ID和课程名称; + +26.查询学生平均成绩及其名次; + +27.查询各科成绩前三名的记录; + +28.查询每门课程被选修的记录数; +select c_id, +count(c_id) +from score +group by c_id; +29.查询出只有两门课程的全部学生的学号和姓名; +select sc.s_id '学号', +st.s_name '姓名' +from score sc +inner join student st on st.s_id = sc.s_id +group by sc.s_id having count(sc.s_id) = 2; +30.查询男生、女生人数; + +31.查询1990年出生的学生名单; + +32.查询平均成绩大于等于85的所有学生的学号、姓名和平均成绩; + +33.查询每门课程的平均成绩,结果按平均成绩升序排序,平均成绩相同时,按课程号降序排序; + +34.查询课程名称为"数学",且分数低于60的学生姓名和分数; + +35.查询所有学生的课程及分数情况(存在学生没成绩,没选课的情况); + +36.查询任何一门课程成绩在70分以上的姓名、课程名称和分数; + +37.查询学生不及格的课程并按课程号从大到小排列; + +38.查询课程编号为03且课程成绩在80分以上的学生的学号和姓名; + +39.求每门课程的学生人数; + +40.查询选修"张三"老师所授课程的学生中成绩最高的学生姓名及其成绩; + +41.查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩; + +42.查询每门课程成绩最好的前两名学生信息; + +43.统计每门课程的学生选修人数(超过5人的课程才统计); + +44.检索至少选修两门课程的学生学号; + +45.查询选修了全部课程的学生信息; + +46.查询各学生的年龄(精确到月份); + +47.查询没学过“张三”老师讲授的任一门课程的学生姓名; + +48.查询两门以上不及格课程的同学; + +49.查询本月过生日的学生; + +50.查询本周过生日的学生; \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302.zip" new file mode 100644 index 0000000000000000000000000000000000000000..37899297806312c4ca00d6ef7f3de481edf26ad5 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\347\273\203\344\271\240.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..19a2f2ae44a162f5cbe223c6aa97f5f4280b45f0 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\347\273\203\344\271\240.md" @@ -0,0 +1,90 @@ +-- 1.查询所有客户 + +-- 2.查询所有商品 + +-- 3.查询所有订单 + +-- 4.查询所有的客户,按年龄降序排列 + +-- 5.查询所有的订单,按订单价格升序排列 + +-- 6.查询所有客户的订单 + +-- 7.查询姓名里面含有'王'的客户信息 + +-- 8.查询没有填写邮箱信息的客户信息 + +-- 9.查询家庭住址都是'龙岩'的客户信息 + +-- 10.查询订单类别,类别名称和订单总金额信息,按商品类别分类 + +-- 11.查询手机号码是'151'开头的客户信息 + +-- 12.查询订单中,商品编号为1的商品总订单价格 + +-- 13.查询1号客户的订单数量 + +-- 14.查询购买商品的订单价格最高的客户姓名、昵称、电话、订单价格、下单时间 + +-- 15.查询订单中,每种商品类型的订单数量 + +-- 16.查询所有商品分类,去除重复数据 + +-- 17.查询订单中金额大于1000的订单信息 + +-- 18.查询订单中金额不高于1000的订单信息 + +-- 19.查询平均订单金额大于2000的客户信息和平均订单金额 + +-- 20.查询所有客户的编号、姓名、订单数、总订单金额; + +-- 21.查询手机号码是'181'开头的客户数量 + +-- 22.查询客户的平均年龄 + +-- 23.查询邮箱中存在'3'的客户数量 + +-- 24.查询有购买过'洗发水'商品的客户的编号、姓名; + +-- 25.查询所有订单金额大于3000的客户的编号、姓名和订单金额; + +-- 26.查询没有买过'洗发水'商品的客户的编号、姓名; + +-- 27.查询商品金额在1000-9000之间的商品信息; + +-- 28.查询注册时间最久的客户编号和姓名; + +-- 29.查询姓名为'张三','王丽'的客户信息; + +-- 30.查询订单价格最低的客户编号、姓名和订单金额; + +-- 31.查询没有邮箱信息的客户编号、姓名和订单金额; + +-- 32.查询订单中,比3号商品的所有订单金额都高的订单信息; + +-- 33.查询每个商品的最高金额信息:商品名称和最高金额 + +-- 34.查询3条订单信息,按订单金额降序排列 + +-- 35.从第2条开始,查询3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; + +-- 36.查询第1页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; + +-- 37.查询第2页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; + +-- 38.查询第3页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; + +-- 39.查询性别为2(女性)的客户的订单数量 + +-- 40.查询客户1和客户2的所有订单信息,要求:组合数据 + + + + + + + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\350\257\255\345\217\245.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\350\257\255\345\217\245.sql" new file mode 100644 index 0000000000000000000000000000000000000000..a2604e0e606e9fecc929f171aed693eb596d4e96 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\350\257\255\345\217\245.sql" @@ -0,0 +1,90 @@ +-- 创建电商系统数据库 +create database if not exists commerce character set utf8mb4 collate utf8mb4_0900_ai_ci; + +-- 使用该数据库 +use commerce; + +-- 创建客户表 +create table if not exists customer ( + id int(11) primary key comment '客户编号', + customer_name varchar(255) comment '客户名称', + customer_nickname varchar(255) comment '客户昵称', + customer_age int(2) comment '客户年龄', + customer_sex int(1) comment '客户性别', + customer_phone varchar(11) comment '手机号码', + customer_email varchar(255) comment '客户邮箱', + customer_address varchar(255) comment '客户地址', + customer_time datetime(0) comment '客户注册时间' +) comment '客户信息表'; + +-- 创建商品表 +create table if not exists goods ( + id int(11) primary key comment '商品编号', + goods_name varchar(255) comment '商品名称', + goods_price decimal comment '商品价格', + goods_colour varchar(255) comment '商品颜色', + goods_weight int(11) comment '商品重量', + type_id int(11) comment '类型编号' +) comment '商品信息表'; + + +-- 商品分类表 +create table if not exists goods_type ( + id int(11) primary key comment '类别编号', + type_name varchar(255) comment '类别名称' +) comment '商品类别表'; + + +-- 创建订单表 +create table if not exists orders ( + id int(11) primary key comment '订单编号', + orders_num int(5) comment '订单数量', + orders_price decimal comment '订单价格', + orders_time datetime(0) comment '订单时间', + orders_address varchar(255) comment '订单地址', + goods_id int(11) comment '客户编号', + customer_id int(11) comment '客户编号' +) comment '订单信息表'; + +-- 插入客户数据 +insert into customer(id,customer_name,customer_nickname,customer_age,customer_sex, +customer_phone,customer_email,customer_address,customer_time) values +(1,'张三','电商1号',30,1,'15103021550','12313@qq.com','福建省龙岩市新罗区','2011-02-03 08:23:35'), +(2,'李四','电商5号',25,1,'15803021550','52353@qq.com','福建省龙岩市漳平市','2013-05-18 12:50:01'), +(3,'王丽','电商3号',29,2,'15105021500','17810@qq.com','福建省龙岩市永定区','2017-08-03 01:31:50'), +(4,'徐艳','电商4号',22,2,'18103021732','98003@qq.com','广东省广州市白云区','2013-11-20 09:10:11'), +(5,'欧阳琳','电商2号',31,2,'19103022380','12213@qq.com','云南省丽江市古城区','2009-11-10 17:32:35') +; + +insert into customer(id,customer_name,customer_nickname,customer_age,customer_sex, +customer_phone,customer_address,customer_time) values +(6,'谢云','电商6号',24,1,'18055123367','陕西省西安市雁塔区','2015-06-06 19:21:35'); + +-- 插入商品数据 +insert into goods(id,goods_name,goods_price,goods_colour,goods_weight,type_id) values +(1,'iPhone 15 Pro',9999.00,'白色',300,2), +(2,'联想拯救者 y9000p',8999.00,'灰色',2600,1), +(3,'洗发水',53.00,'蓝色',500,3) +; + +-- 插入商品分类表数据 +insert into goods_type(id,type_name) values +(1,'电脑办公'), +(2,'手机数码'), +(3,'日用产品'), +(4,'日用产品') +; + +-- 插入订单表 +insert into orders(id,orders_num,orders_price,orders_time,orders_address,goods_id,customer_id) values +(1,2,19998.00,'2023-09-13 19:21:35','陕西省西安市雁塔区秦皇小区1号',1,6), +(2,1,9999.00,'2024-01-15 11:28:01','云南省丽江市古城区古城小区15号',1,5), +(3,1,8999.00,'2024-01-01 08:35:38','云南省丽江市古城区古城小区15号',2,5), +(4,1,53.00,'2024-01-01 08:37:38','云南省丽江市古城区古城小区5号',3,5), +(5,1,8999.00,'2023-11-11 11:35:38','福建省龙岩市漳平市樟树小区3-3号',2,2), +(6,1,8999.00,'2023-11-11 20:37:38','福建省龙岩市永定区永富小区8号',2,3), +(7,3,29997.00,'2023-11-11 20:37:38','福建省龙岩市漳平市樟树小区3-3号',1,2), +(8,10,530.00,'2023-12-01 09:50:05','福建省龙岩市新罗区万达小区0-1号',3,1) +; + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/\347\255\224\346\241\210.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/\347\255\224\346\241\210.sql" new file mode 100644 index 0000000000000000000000000000000000000000..918d772c1d34e4c93d8a13f30e1843a15f6e770b --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.02/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/\347\255\224\346\241\210.sql" @@ -0,0 +1,228 @@ +-- 1.查询所有客户 +select * from customer; +-- 2.查询所有商品 +select * from goods; +-- 3.查询所有订单 +select * from orders; +-- 4.查询所有的客户,按年龄降序排列 +select * from customer order by customer_age desc; +-- 5.查询所有的订单,按订单价格升序排列 +select * from +-- 6.查询所有客户的订单 +select * +from customer c +inner join orders o on c.id = o.customer_id; +-- 7.查询姓名里面含有'王'的客户信息 +select * +from customer where customer_name like '%王%'; +-- 8.查询没有填写邮箱信息的客户信息 +select * +from customer where customer_email is null; +-- 9.查询家庭住址都是'龙岩'的客户信息 +select * +from customer where customer_address like '%龙岩%'; +-- 10.查询商品类别,类别名称和订单总金额信息,按商品类别分类 +select gt.type_name '类别名称',sum(ord.orders_price) '订单总金额' +from goods_type gt +inner join goods go on gt.id = go.type_id +inner join orders ord on go.id = ord.goods_id +group by go.type_id; +-- 11.查询手机号码是'151'开头的客户信息 +select * +from customer +where customer_phone like '151%'; +-- 12.查询订单中,商品编号为1的商品总订单价格 +select goods_id '编号', +sum(orders_price) '商品总订单价格' +from orders +group by goods_id +having goods_id = 1; +-- 13.查询1号客户的订单数量 +select count(customer_id) '订单数量' +from orders +group by customer_id +having customer_id = 1; +-- 14.查询购买商品的订单价格最高的客户姓名、昵称、电话、订单价格、下单时间 +select cus.customer_name '姓名', +cus.customer_phone '电话', +ord.orders_price '订单价格', +ord.orders_time '下单时间' +from orders ord +inner join customer cus on cus.id = ord.customer_id +where ord.orders_price = (select max(orders_price) from orders); +-- 15.查询订单中,每种商品类型的订单数量 +select gt.type_name '商品类型', +count(ord.goods_id) '订单数量' +from orders ord +inner join goods go on go.type_id = ord.goods_id +inner join goods_type gt on gt.id = go.type_id +group by ord.goods_id; +-- 16.查询所有商品分类,去除重复数据 +select distinct * +from goods go +inner join goods_type gt on gt.id = go.type_id; +-- 17.查询订单中金额大于1000的订单信息 +select * +from orders +where orders_price > 1000; +-- 18.查询订单中金额不高于1000的订单信息 +select * +from orders +where orders_price <= 1000; +-- 19.查询平均订单金额大于2000的客户信息和平均订单金额 +select cus.*, +avg(ord.orders_price) '平均订单金额' +from orders ord +inner join customer cus on cus.id = ord.customer_id +group by ord.customer_id having avg(ord.orders_price) > 2000; +-- 20.查询所有客户的编号、姓名、订单数、总订单金额; +select ord.customer_id '编号', +cus.customer_name '姓名', +count(ord.id) '订单数', +sum(ord.orders_price) '总订单金额' +from orders ord +inner join customer cus on cus.id = ord.customer_id +group by ord.customer_id; +-- 21.查询手机号码是'181'开头的客户数量 +select count(id) '客户数量' +from customer +where customer_phone like '181%' +order by id; +-- 22.查询客户的平均年龄 +select avg(customer_age) '平均年龄' +from customer; +-- 23.查询邮箱中存在'3'的客户数量 +select * +from customer +where customer_email like '%3%'; +-- 24.查询有购买过'洗发水'商品的客户的编号、姓名; +select cus.id '编号', +cus.customer_name '姓名' +from orders ord +inner join customer cus on cus.id = ord.customer_id +where ord.goods_id in +(select id from goods where goods_name = '洗发水'); +-- 25.查询所有订单金额大于3000的客户的编号、姓名和订单金额; +select cus.id '编号', +cus.customer_name '姓名', +ord.orders_price '订单金额' +from orders ord +inner join customer cus on cus.id = ord.customer_id +where ord.orders_price > 3000; +-- 26.查询没有买过'洗发水'商品的客户的编号、姓名; +select distinct cus.id '编号', +cus.customer_name '姓名' +from orders ord +inner join customer cus on cus.id = ord.customer_id +where ord.goods_id not in +(select id from goods where goods_name = '洗发水') +and cus.customer_name not in +(select cus.customer_name '姓名' +from orders ord +inner join customer cus on cus.id = ord.customer_id +where ord.goods_id in +(select id from goods where goods_name = '洗发水')); +-- 27.查询商品金额在1000-9000之间的商品信息; +select * +from goods +where goods_price between 1000 and 9000; +-- 28.查询注册时间最久的客户编号和姓名; +select id '客户编号',customer_name '客户姓名' +from customer +where customer_time = (select min(customer.customer_time) from customer); +-- 29.查询姓名为'张三','王丽'的客户信息; +select * +from customer +where customer_name in ('张三','王丽'); +-- 30.查询订单价格最低的客户编号、姓名和订单金额; +select cus.id '客户编号', +cus.customer_name '姓名', +ord.orders_price '订单金额' +from orders ord +inner join customer cus on cus.id = ord.customer_id +where ord.orders_price = (select min(orders_price) from orders); +-- 31.查询没有邮箱信息的客户编号、姓名和订单金额; +select ord.customer_id '客户编号', +cus.customer_name '姓名', +sum(ord.orders_price) '订单金额' +from orders ord +inner join customer cus on cus.id = ord.customer_id +group by ord.customer_id +having ord.customer_id = (select id from customer where customer_email is null); +-- 32.查询订单中,比3号商品的所有订单金额都高的订单信息; +select * +from orders ord1 +where ord1.orders_price > all(select ord2.orders_price from orders ord2 where ord2.goods_id = 3); +-- 33.查询每个商品的最高金额信息:商品名称和最高金额 +select goo.goods_name '商品名称', +max(ord.orders_price)'最高金额' +from orders ord +inner join goods goo on goo.id = ord.goods_id +group by ord.goods_id +-- 34.查询3条订单信息,按订单金额降序排列 +select * +from orders +order by orders_price desc +limit 3; +-- 35.从第2条开始,查询3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; +select cus.id '编号', +cus.customer_name '昵称', +cus.customer_phone '手机号码', +ord.orders_price '订单金额', +ord.orders_time '下单时间' +from orders ord +inner join customer cus on cus.id = ord.customer_id +limit 1,3; +-- 36.查询第1页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; +select cus.id '编号', +cus.customer_name '昵称', +cus.customer_phone '手机号码', +ord.orders_price '订单金额', +ord.orders_time '下单时间' +from orders ord +inner join customer cus on cus.id = ord.customer_id +limit 0,3; +-- 37.查询第2页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; +select cus.id '编号', +cus.customer_name '昵称', +cus.customer_phone '手机号码', +ord.orders_price '订单金额', +ord.orders_time '下单时间' +from orders ord +inner join customer cus on cus.id = ord.customer_id +limit 3,3; +-- 38.查询第3页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; +select cus.id '编号', +cus.customer_name '昵称', +cus.customer_phone '手机号码', +ord.orders_price '订单金额', +ord.orders_time '下单时间' +from orders ord +inner join customer cus on cus.id = ord.customer_id +limit 6,3; +-- 39.查询性别为2(女性)的客户的订单数量 +select ord.customer_id 'id', +cus.customer_name '客户', +count(ord.customer_id) '订单数量' +from orders ord +inner join customer cus on cus.id = ord.customer_id +where cus.customer_sex = 2 +group by ord.customer_id; +-- 40.查询客户1和客户2的所有订单信息,要求:组合数据 +select * +from orders +where customer_id = 1 +union all +select * +from orders +where customer_id = 2; + + + + + + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266.zip" new file mode 100644 index 0000000000000000000000000000000000000000..793f6d25dff39b820f26895285ed6d94d161108e Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266.zip" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/1.\346\225\260\346\215\256\345\272\223\347\233\270\345\205\263\346\246\202\345\277\265.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/1.\346\225\260\346\215\256\345\272\223\347\233\270\345\205\263\346\246\202\345\277\265.md" new file mode 100644 index 0000000000000000000000000000000000000000..cf6425c62248a6b029933d33484d07cc49066191 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/1.\346\225\260\346\215\256\345\272\223\347\233\270\345\205\263\346\246\202\345\277\265.md" @@ -0,0 +1,74 @@ +# 数据库相关概念 + +### 本节目标:了解数据库相关概念 + + + +什么是数据? + +数据有哪些记录方式呢? + +记录的数据会存在哪些问题? + + + +**1.数据库** + +存储数据的仓库,数据是有组织的进行存储,简称 DB(DataBase) + +##### 2.数据库的作用 + +存储大量数据 +能方便的访问和检索数据、查找速度快 +保持数据的完整性 +保护数据安全,控制哪些数据能由谁访问 + +**3.数据库管理系统** + +操纵和管理数据库的大型软件,简称 DBMS(DataBase Management System) + +**4.常见数据库管理系统** + +![](.\imgs\2.png) + +**5.数据库的分类** + +数据库主要是分为关系型和非关系型(市面上常用的) + +关系型:Oracle、MySQL、SqlServer + +非关系型:redis + +**6.Oracle、MySQL、SqlServer数据库的区别** + +![image-20240301091403448](.\imgs\39.png) + + + +**课外拓展:** + +**1.什么是关系型数据库**? + +**1)关系型数据库**是把复杂的[数据结构](https://www.zhihu.com/search?q=数据结构&search_source=Entity&hybrid_search_source=Entity&hybrid_search_extra={"sourceType"%3A"answer"%2C"sourceId"%3A1604375728})归结为简单的二元关系(即二维表格形式)。在[关系型数据库](https://www.zhihu.com/search?q=关系型数据库&search_source=Entity&hybrid_search_source=Entity&hybrid_search_extra={"sourceType"%3A"answer"%2C"sourceId"%3A1604375728})中,对数据的操作几乎全部建立在一个或多个关系表格上,通过这些关联的表格分类、合并、连接或选取等运算来实现数据的管理。 + +**2)非关系型数据库又称NoSQL**,由于数据类型多种多样,关系型数据库并不适用于所有的数据,因此针对不同的数据类型,出现了不同的 NoSQL,NoSQL的产生并不是要彻底否定关系型数据库,而是作为传统数据库的有效补充。 + +**2.E-R实体关系图**。 + +E-R 是两个单词的首字母,E表示Entity 实体 ,R表示Relationship 关系。 + +例: 客户、商品、订单之间的关系 + +![](.\imgs\4.png) + + + +实体:可以理解成我们Java程序中的一个对象。比如客户、商品等都是一个实体对象。在E-R图中使用 矩形(长方形) 表示。 + +属性:实体对象中是含有属性的,比如商品名、价格等。针对一个实体中的属性,我们称为这个实体的数据,在E-R图中使用椭圆表示。 + +关系:实体和实体之间的关系:在E-R图中使用菱形表示。 + +**备注:PowerDesigner软件** + +下载及安装教程链接:[PowerDesigner 安装+汉化+破解+使用过程 - 沦陷 - 博客园 (cnblogs.com)](https://www.cnblogs.com/huangting/p/12654057.html) diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/2.Mysql\344\273\213\347\273\215.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/2.Mysql\344\273\213\347\273\215.md" new file mode 100644 index 0000000000000000000000000000000000000000..8071337b34e3e12c42542bf636f84d5bb2727f99 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/2.Mysql\344\273\213\347\273\215.md" @@ -0,0 +1,43 @@ +# Mysql数据库介绍 + +### 本节目标:了解Mysql数据库 + + + +**1.简单认识Mysql** + +MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。 + +MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。 + +MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言。 + +MySQL软件采用了双授权政策(本词条“授权政策”),它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL作为网站数据库。 + + + +**2.Mysql数据库特点** + +1.使用C和C++编写,并使用了多种编译器进行测试,保证源代码的可移植性。 +2.支持Windows、Linux、Mac OS等多种操作系统。 +3.为多种编程语言提供了API。这些编程语言包括Java、C、C++、C#、Go等等。 +4.支持多线程,充分利用CPU资源。 +5.优化的SQL查询算法,有效地提高查询速度。 +6.提供多语言支持,常见的编码如中文的GB 2312、BIG5,日文的Shift_JIS等都可以用作数据表名和数据列名。 +7.提供TCP/IP、ODBC和JDBC等多种数据库连接途径。 +8.提供用于管理、检查、优化数据库操作的管理工具。 +9.支持多种存储引擎。 + +**3.常用的Mysql管理工具** + +Mysql客户端软件 + +Navicat + +Dbeaver + +**4.Mysql版本** + +Mysql主要有社区版、企业版和集群版,社区版是开源免费的,而企业版和集群版是有试用期的,所以一般的项目开发使用社区版就可以满足需求。 + +目前市场上主流的版本是5.7版本,较为新一点的版本就是8.0版本。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/3.Mysql\345\256\211\350\243\205\345\217\212\351\205\215\347\275\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/3.Mysql\345\256\211\350\243\205\345\217\212\351\205\215\347\275\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..9dad37f98f5bb6f21547905faae59576241761c2 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/3.Mysql\345\256\211\350\243\205\345\217\212\351\205\215\347\275\256.md" @@ -0,0 +1,129 @@ +# 数据库安装和配置 + +### 本节目标:掌握Mysql数据库安装和配置 + + + +**1.下载Mysql** + +前往Mysql官方网站下载Mysql 8.0.16 版本的 .msi文件 + +网址:https://downloads.mysql.com/archives/installer/ + + + +![image-20240221201751241](.\imgs\6.png) + +2.双击运行下载好的.msi安装文件,等待安装程序打开 + +![image-20240221201959125](.\imgs\7.png) + +![image-20240220194347697](.\imgs\8.png) + +3.选择安装类型,这里我们选择自定义安装,点击下一步 + +![img](.\imgs\9.png) + +![image-20240221202240070](.\imgs\31.png) + +在弹出的对话框中点击 yes + +![image-20240221202322051](.\imgs\32.png) + +到下一步,点击Execute,等待加载完成。加载完成后点击next + +![image-20240221202737778](.\imgs\33.png) + + + +4.接着点击Next,直到以下界面 + +选择安装类型,个人开发学习选择“Development Computer”; + +Development Computer个人开发学习使用; + +Server Computer用于FTP,email,web服务器等; + +Dedicated Computer 用作MySQL服务器; + +![image-20240221203041206](.\imgs\10.png) + +上面会显示安装类型和Mysql端口号,直接点击Next,直到第5步设置Mysql的密码 + +5.设置Mysql的密码,点击Next + +![image-20240220200331217](.\imgs\15.png) + +6.然后接着点击Next + +![image-20240221203312327](.\imgs\16.png) + +最后点击Execute 执行 + +![image-20240221203410126](.\imgs\18.png) + +执行完成后点击Finish,接着点击Next,最后再点击Finish,直到以下页面 + +![image-20240221203648191](.\imgs\34.png) + +输入我们设置的密码,点击check进行验证,出现以下提示说明安装成功 + +![image-20240221203753213](.\imgs\35.png) + +接着点击Next,然后点击Execute,执行完成后点击Finish,出现以下界面后点击Next + +![image-20240221203921891](.\imgs\36.png) + +取消勾选,点击Finish + +![image-20240221204009593](.\imgs\37.png) + +7.通过命令方式最终验证Mysql安装是否成功 + +1).打开 Windows+R 打开运行窗口,输入cmd + +输入以下命令 mysql -uroot -p ,点击回车,如果出现以下报错 + +'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件 + +![image-20240221204226162](.\imgs\20.png) + +解决方法: + +1.先找到Mysql安装目录下的bin文件夹,复制文件夹路径(默认安装在C盘) + +C:\Program Files\MySQL\MySQL Server 5.7\bin + +2.进入环境变量设置 + +右击**此电脑**,选择属性,点击高级系统设置,点击环境变量; + +在系统变量中选择Path,点击编辑 + +![image-20240220202111299](.\imgs\21.png) + +然后点击新建,将刚刚复制的Mysql的bin目录添加上去,点击确定 + +![image-20240221204430659](.\imgs\22.png) + +3.验证环境变量是否配置好 + +打开 Windows+R 打开运行窗口,输入cmd,再次输入 mysql -uroot -p + +如果出现以下界面,则输入安装数据库是设置的密码,然后回车 + +![image-20240220202714453](.\imgs\23.png) + +如果出现以下提示,则说明数据库安装完成 + +![image-20240221204515947](.\imgs\24.png) + + + +恭喜同学们,Mysql数据库安装成功! + + + +安装教程: + +https://blog.csdn.net/Sophia_0331/article/details/104891381 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/4.Mysql\345\267\245\345\205\267.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/4.Mysql\345\267\245\345\205\267.md" new file mode 100644 index 0000000000000000000000000000000000000000..15a0e93772ade62b8fd908f8ca646867933da4ba --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/4.Mysql\345\267\245\345\205\267.md" @@ -0,0 +1,29 @@ +# Mysql工具 + +### 本节目标:熟悉常用的数据库连接工具 + + + +**1.Mysql数据库客户端工具** + +点击开始菜单,选择所有程序,找到Mysql Workbench 6.3 应用程序并打开 + +![image-20240220203732817](.\imgs\25.png) + +点击连接,会弹出对话框 + +![image-20240220204010678](.\imgs\26.png) + +注:也可以勾选 Save password in vault 记住密码选择,如果是公共电脑则不建议勾选 + +点击OK后即登录成功,就可以开始使用Mysql数据库了 + +![image-20240220204441078](.\imgs\27.png) + +2.Navicat使用 + +![image-20240221102740755](.\imgs\30.png) + +3.Dbeaver使用 + +![image-20240220210044523](.\imgs\29.png) diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/1.PNG" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/1.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..3e3d8a9c2216bd06c520320b63d0142c88062551 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/1.PNG" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/10.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/10.png" new file mode 100644 index 0000000000000000000000000000000000000000..946f5524e01a9769d621211c4f4e53d41774de1f Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/10.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/15.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/15.png" new file mode 100644 index 0000000000000000000000000000000000000000..ee95d25bd0c7678cb42d9555c85922a1fc7e2bf3 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/15.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/16.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/16.png" new file mode 100644 index 0000000000000000000000000000000000000000..d1b84c5925ae21fa1790811ad12411fc06a735e2 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/16.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/18.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/18.png" new file mode 100644 index 0000000000000000000000000000000000000000..b95323e732d87e99d86534ebbc4edbe2fb4c1be0 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/18.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/19.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/19.png" new file mode 100644 index 0000000000000000000000000000000000000000..dffecdf604e8cb44cff15fbbf8c0ae69edfcb836 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/19.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/2.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..8bf9146443a767dd24779635e4131ed138830d13 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/2.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/20.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/20.png" new file mode 100644 index 0000000000000000000000000000000000000000..9e650843658ca5f93cb4604ac902abbbbaeed34f Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/20.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/21.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/21.png" new file mode 100644 index 0000000000000000000000000000000000000000..b58540d5465fdd63cf9e9b6b1d8a66989df1f529 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/21.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/22.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/22.png" new file mode 100644 index 0000000000000000000000000000000000000000..3a0ed4cfe350ed7fd13de6f46e98f7556811c58a Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/22.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/23.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/23.png" new file mode 100644 index 0000000000000000000000000000000000000000..048dd7d921833b64cfe232b90da7aa540167b326 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/23.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/24.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/24.png" new file mode 100644 index 0000000000000000000000000000000000000000..c990ff6dc1272b28a50b16ad73cf4bd55acb09bf Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/24.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/25.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/25.png" new file mode 100644 index 0000000000000000000000000000000000000000..c275941df4302608deaaf9f8523128fa976656ed Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/25.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/26.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/26.png" new file mode 100644 index 0000000000000000000000000000000000000000..1e39c55fa31b89326461e07f3d47404626304249 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/26.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/27.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/27.png" new file mode 100644 index 0000000000000000000000000000000000000000..5cc26af4f498437007b00f309a78d728fa60686e Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/27.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/29.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/29.png" new file mode 100644 index 0000000000000000000000000000000000000000..14959daccdeb411b53b701a9eb90ac4a364fba6c Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/29.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/3.PNG" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/3.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..dd47af88838a245c73095afe06a8da62259c940a Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/3.PNG" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/30.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/30.png" new file mode 100644 index 0000000000000000000000000000000000000000..0a70c182e0e64e1332ee1416063488fa53aff086 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/30.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/31.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/31.png" new file mode 100644 index 0000000000000000000000000000000000000000..b9d8f4297ac0c61b974e712d9b3bbb84ea4fa979 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/31.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/32.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/32.png" new file mode 100644 index 0000000000000000000000000000000000000000..c4b3b519335729c6b90f7f7935def983dd4905fe Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/32.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/33.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/33.png" new file mode 100644 index 0000000000000000000000000000000000000000..4b1ad0dfa01d4c9a00dd7365cab90275b3207f5d Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/33.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/34.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/34.png" new file mode 100644 index 0000000000000000000000000000000000000000..84d0db46c406e2ffde86de5854b78672ab918f54 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/34.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/35.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/35.png" new file mode 100644 index 0000000000000000000000000000000000000000..2b04814314b4d363396e275ad368420126229007 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/35.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/36.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/36.png" new file mode 100644 index 0000000000000000000000000000000000000000..d707dd14a21c3ace98568f6284f60761870b0511 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/36.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/37.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/37.png" new file mode 100644 index 0000000000000000000000000000000000000000..e556fff94ed8e5db0c5ceaacc01bac7d35f117b8 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/37.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/38.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/38.png" new file mode 100644 index 0000000000000000000000000000000000000000..89f080ebead1ebd6ac2db3032b4a12a05349b0d6 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/38.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/39.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/39.png" new file mode 100644 index 0000000000000000000000000000000000000000..7569eb0ac0a6e1d8febe87b2f3f13efefc4f8421 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/39.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/4.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..1b6d0fc5bf4cd47962be0123c6e845d3eeedcce9 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/4.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/5.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..f3e191ce9c6c82b8643883cc743a05631663fc5b Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/5.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/6.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/6.png" new file mode 100644 index 0000000000000000000000000000000000000000..d91aeee67bbe9a32fed7776ba8b8ac1527d7847b Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/6.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/7.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/7.png" new file mode 100644 index 0000000000000000000000000000000000000000..81621ed5dcc3d81f8a93d87a5761525f88210963 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/7.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/8.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/8.png" new file mode 100644 index 0000000000000000000000000000000000000000..4d8b231cd420592d3fd0fec9221ec09540f5f199 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/8.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/9.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/9.png" new file mode 100644 index 0000000000000000000000000000000000000000..da07c22a5042b2340e7ff3767a5a61173e00b88d Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/imgs/9.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/\350\265\204\346\226\231/Mysql\345\205\215\345\256\211\350\243\205\346\225\231\347\250\213.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/\350\265\204\346\226\231/Mysql\345\205\215\345\256\211\350\243\205\346\225\231\347\250\213.md" new file mode 100644 index 0000000000000000000000000000000000000000..0501e1101122bffa211f0af92c7310f2f5713713 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/1_\346\225\260\346\215\256\345\272\223\344\273\213\347\273\215/\350\265\204\346\226\231/Mysql\345\205\215\345\256\211\350\243\205\346\225\231\347\250\213.md" @@ -0,0 +1,74 @@ +## Mysql数据库免安装版本安装教程 + + + +1.下载Mysql8.0.16解压版程序 + + https://downloads.mysql.com/archives/community/ + +2.在mysql安装目录下,新建 my.txt 文件,将一下数据复制到文件中 + +``` +[mysqld] + +设置mysql的安装目录 + +basedir=D:\\mysql-8.0.21-winx64 + +设置mysql数据库的数据的存放目录 + +datadir=D:\\mysql-8.0.21-winx64\\data + +允许最大连接数 + +max_connections=200 + +允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统 + +max_connect_errors=10 + +服务端使用的字符集默认为UTF8 + +character-set-server=utf8 + +创建新表时将使用的默认存储引擎 + +default-storage-engine=INNODB + +默认使用“mysql_native_password”插件认证 + +default_authentication_plugin=mysql_native_password + +设置mysql客户端默认字符集 + +default-character-set=utf8 + +character_set_server=utf8 +[client] + +设置mysql客户端连接服务端时默认使用的端口 + +port=3306 +default-character-set=utf8 +``` + +3.将my.txt 文件后缀修改为ini,保存; + +4.配置mysql环境变量; + +5.打开命令提示符,以管理员身份运行; + +6.输入 mysqld --initialize --console 进行初始化; + +7.初始化后 记住 提示中 root@localhost:登录密码; + +8.在命令提示符中 输入 mysql --install mysql 安装mysql服务,提示Service successfully installed 则说明安装成功了; + +9.启动mysql服务:net start mysql; + +10.登录mysql 输入mysql -uroot -p ,输入登录密码登录mysql; + +11.修改mysql密码 输入ALTER USER USER() IDENTIFIED BY '新密码'; + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/SQL/1.SQL\346\223\215\344\275\234Mysql\346\225\260\346\215\256\345\272\223.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/SQL/1.SQL\346\223\215\344\275\234Mysql\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000000000000000000000000000000000000..d6ce04b24c1559be8f135caf80d18a0b0d707dcc --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/SQL/1.SQL\346\223\215\344\275\234Mysql\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,244 @@ +# SQL操作数据库 + +### 本节目标:使用SQL操作数据库(增删改) + +什么是数据库编程语言? + + + +**1.数据库编程语言** + +SQL 指结构化查询语言,全称是 Structured Query Language。 + +•SQL 让用户可以访问和处理数据库,包括数据插入、查询、更新和删除。 + +•SQL 在1986年成为 ANSI(American National Standards Institute 美国国家标准化组织)的一项标准,在 1987 年成为国际标准化组织(ISO)标准。 + +**2.SQL的分类** + +SQL语言通常分为五类: + + DDL(数据库定义语言):create、alter、drop等;针对数据库对象操作 + DQL(数据库查询语言):select等; + DML(数据操纵语言):insert 、delete 、update 等;对数据表的数据进行操作 + TCL(事务控制语言):commit、rollback等; + DCL(数据控制语言):grant、revoke等。 + +**DDL(数据定义语言)** + +数据定义语言(Data Definition Language)简称DDL。是 SQL 语言集中负责数据结构定义与数据库对象定义的语言。 + +DDL用来创建数据库中的各种对象,创建、删除、修改表的结构,比如表、视图、索引、同义词、聚簇等。其主要功能是定义数据库对象,核心指令为create、drop、alter。 + +和DML相比,DML是修改数据库表中的数据,而 DDL 是修改数据库中表的结构。 + +**DQL(数据查询语言)** + +数据查询语言(Data Query Language)简称DQL。是SQL语言中,负责进行数据查询而不会对数据本身进行修改的语句,这是最基本的SQL语句。 + +DQL的核心指令为select。通常与关键字from、where、group by、having、order by等一起使用,组成查询语句。 + +**DML(数据操纵语言)** + +数据操纵语言(Data Manipulation Language)简称DML。通过它可以实现对数据库的基本操作,对数据库其中的对象和数据运行访问工作的语言。 + +DML的主要功能是访问数据,因此其语法都是以读写数据库为主。 + +DML的核心指令为insert、update、delete。 + +**TCL(事务控制语言)** + +事务控制语言(Transaction Control Language)简称TCL。用于管理数据库中的事务。这些用于管理由 DML 语句所做的更改。它还允许将语句分组为逻辑事务。 + +TCL经常被用于快速原型开发、脚本编程、GUI和测试等方面。 + +TCL的核心指令为commit、rollback。 + +**DCL(数据控制语言)** + +数据控制语言 (Data Control Language)简称DCL。是一种可对数据访问权进行控制的指令,它可以控制特定用户账户对数据表、查看表、预存程序、用户自定义函数等数据库对象的控制权。 + +DCL用来授予或回收访问数据库的某种特权,并控制数据库操纵事务发生的时间及效果,对数据库实行监视等。 + +DCL的核心指令为grant、revoke。 + + + +**3.新建数据库** + +1)使用SQL语句创建数据库 + +在Mysql中,可以使用DDL语句来创建数据库,语法如下: + +```sql +create database <数据库名>; +``` + +语法说明: + +- 数据库名称必须是唯一的,不应与其他数据库重名。 +- 可以包含字母、数字、下划线以及英文字符,但不应该以数字开头。 +- 名称应当区分大小写。 + + + +示例1:创建一个名为student_01的数据库 + +连接到Navicat可视化工具,点击新建查询,输入一下命令 + +```sql +-- 创建名为 student_01的数据库 +create database student_01; +``` + +其中: + +-- 两个横杆表示这串文字或代码为注释,给人看得,不参与具体的代码执行 + +create 为创建数据库的 语法关键字 + +语句最后都必须加上英文的分号 ; 表示语句编写结束的意思; + + + +然后选中命令,点击运行已选择的,提示创建成功的信息,则说明创建成功。 + +![image-20240221162624490](..\imgs\5.png) + +注:创建数据库成功后,可以选择我们使用哪个数据库。(因为Mysql支持创建多个数据库) +语法 +```sql +use 数据库名称; +``` + +**创建重复的数据库** + +若再次输入 create database student_01; 语句,则系统会给出错误提示信息,如下所示: + + 1007 - Can't create database 'student_01'; database exists + +提示不能创建“student_01”数据库,数据库已存在。 + +Mysql 不允许在同一系统下创建两个相同名称的数据库。 + +可以通过 查询information_schema 数据库中的 SCHEMATA表数据或者用SHOW DATABASES 语句 来判断需要创建的数据名称是否存在,从而避免类似错误,如下所示: + +![image-20240221163418591](..\imgs\6.png) + +避免创建同名数据库的另一种方式: + +```sql +-- 在建表语句中加入判断是否存在的逻辑 +CREATE DATABASE IF NOT EXISTS student_01; +``` + +其中: + +1. if not exists 表示判断是否不存在的意思,就是不存在这个数据库就创建,否则不做任何操作,也不会报错。 + +![image-20240221164022605](..\imgs\7.png) + + + +由于创建数据库时可以选择字符集和排序规则,若不设置,Mysql会使用默认设置,固可在建表语句中加入 + +语法: + +```sql +create database 数据库名称 character set 字符集 collate 排序规则; +``` + +**4.修改和删除数据库** + +1)修改数据库字符集和排序规则 + +连接到Navicat可视化工具,点击新建查询,输入一下命令 + +语法: + +```sql +-- 使用alter关键字修改 +alter database 数据库名称 character + +set 字符集 collate 排序规则; + +``` + + + +2)删除数据库 + +连接到Navicat可视化工具,点击新建查询,输入一下命令 + +语法: + +```sql +drop database 数据库名称; +``` + +还有一种方式是,判断数据库存在时才删除,不存在就不执行 + +语法: + +```sql +drop database if exists 数据库名称; +``` + + + +**5.备份和恢复数据库** + +1)备份数据库 + +首先通过cmd命令,进入到Mysql安装路径的bin目录下,使用mysqldump命令,输入以下语法执行备份。 + +语法: + +```sql +mysqldump -u用户名 -p密码 数据库名称 > 保存文件路径\backup.sql +``` + +2)还原数据库 + +首先通过cmd命令,进入到Mysql安装路径的bin目录下,输入一下语法执行恢复数据库。 + +注意:此操作前,对应的数据库应该存在 + +语法: + +```sql +mysql -u root -p --default-character-set=utf8 -f 数据库名称 < 保存文件路径\backup.sql +``` + + + +**课堂拓展:如果导入导出出现乱码请使用下面方便备份还原试试(导出和导入都使用二进制方式)** + +例: + +导出 +```sql +mysqldump -u root -p --default-character-set=binary 数据库名称 > 保存文件路径\backup.sql +``` + +导入 + +```sql +mysql -u root -p --default-character-set=binary -f 数据库名称 < 保存文件路径\backup.sql +``` + + + +**增量备份** + +增量备份是备份数据库中自上次备份以来发生更改的数据的方法。这种备份方法比完整备份更快,因为它只备份发生更改的数据。以下是一个增量备份命令语法: + +```sql +mysqldump -u用户名 -p密码 --where='update_time > [last_backup_time]' 数据库名称 > 保存文件路径\backup.sql +``` + + + +总结: + +本节课重点讲SQL语言概念及分类,通过SQL语句来创建、修改、删除以及备份和恢复数据库。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/SQL/2.SQL\346\223\215\344\275\234Mysql\346\225\260\346\215\256\350\241\250.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/SQL/2.SQL\346\223\215\344\275\234Mysql\346\225\260\346\215\256\350\241\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..eadad2060d6736f215f8fda9508b60e6fe69ef59 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/SQL/2.SQL\346\223\215\344\275\234Mysql\346\225\260\346\215\256\350\241\250.md" @@ -0,0 +1,422 @@ + + +# SQL操作数据表和字段 + +### 本节目标:使用SQL操作数据表和字段 + + + +**1.创建数据表** + +| 学生ID | 姓名 | 年龄 | 性别 | 入学日期 | 班级ID | +| ------ | ---- | ---- | ---- | ------------------- | ------ | +| 1 | 张三 | 18 | 男 | 2024-02-22 08:00:00 | 1 | +| 2 | 李四 | 25 | 男 | 2024-02-22 16:31:46 | 1 | +| 3 | 王丽 | 23 | 女 | 2024-02-21 16:32:08 | 1 | +| 4 | 李红 | 20 | 女 | 2024-02-21 13:32:50 | 2 | +| 5 | 小军 | 22 | 男 | 2024-02-23 09:33:34 | 2 | + +一列 称为 字段,一行 称为 记录 + + + + + + + + + +语法: + +```sql +CREATE TABLE 数据表名称 ( + 字段 数据类型 , + 字段 数据类型 , + 字段 数据类型 , + ... + 字段 数据类型 +); +字段名不能使用关键字(中文):YEAR year,date,time +``` + +建表语句: + +```sql +CREATE TABLE if not exists student_info ( + id int(11) commont '主键', + student_name varchar(255) commont '主键', + student_age int(2) , + student_sex int(1) , + student_time datetime(0) , + class_id int(11) +); +``` + +语句执行后,便创建了一个名称为 student_info的数据表 + +![image-20240222214609187](..\imgs\24.png) + +重复创建表 + +如果说数据库中已经创建了 student_info 的表,那不允许再次创建; + +我们使用以下语法进行判断: + +```sql +create table if not exists student_info ( + student_id int(11), + student_name VARCHAR(255), + student_age int(2), + student_sex int(1), + student_time datetime(0), + class_id int(11) +); +``` + + + +**2.修改表名** + +语法: + +```sql +alter table 原表名 rename to 新表名; +``` + +修改表名语句: + +```sql +alter table student_info rename to student_info_01; +``` + +语句执行后,便将student_info的数据表名称改为student_info_01 + + + +**3.删除表** + +删除表有两种方式,一种是单表删除,还有一种是多表删除 + +语法: + +```sql +drop table 表名; +drop table 表1,表2,表3; +``` + +删除表语句: + +```sql +drop table student_info_01; +``` + +语句执行后,便将student_info_01的数据表删除 + + + +**4.表字段操作** + +1)添加字段 + +\#添加字段(默认添加到最后) + +```sql +alter table 表名 add 字段名 数据类型(长度); +``` + +\# 添加字段到指定的字段后面 + +```sql +alter table 表名 add 字段名 数据类型(长度) after 指定字段名; +``` + +\# 添加字段到首位 + +```sql +alter table 表名 add 字段名 数据类型(长度) first; +``` + + + +2)修改字段 + +\# 修改字段,可以修改字段名称及属性 + +```sql +alter table 表名 change 原字段名 修改字段名 数据类型(长度); +``` + +\# 修改字段属性 + +```sql +alter table 表名 modify 字段名 数据类型(数据长度); +``` + +\# 修改字段注释 + +```sql +alter table 表名 modify 字段名 数据类型(数据长度) comment '注释'; +``` + + + +3)删除字段 + +```sql +alter table 表名 drop 字段名; +``` + + + +**课堂拓展: ** + + + +**约束条件**: + +完整性约束、主键约束、非空约束、唯一性约束、默认约束 + +##### 完整性约束的分类 + +- **实体完整性:记录之间不能重复。** + - **主键约束(primary key)**:唯一并且不能为空 + - **唯一约束(unique)**:唯一可以为空 + - **主键自增(auto_increment)** +- **域完整性:数据库表的字段,必须符合某种特定的数据类型或约束。** + - **类型约束**:在创建表的时候,已经给每个字段添加类型了 + - **非空约束**:not null + - **默认值**:default +- **引用完整性(参照完整性):一张表中字段的值,需要参考另外一张表中的值。** + - 添加外键约束:foreign key + - 引用完整性会降低sql的执行效率,有时候能不用就不用。 + + + +1)主键约束 + +添加主键约束语法: + +```sql +alter table 数据表名 add primary key(字段名); +``` + +删除主键约束语法: + +```sql +alter table 数据表名 drop primary key; +``` + +在建表语句中加入主键约束语法: + +```sql +CREATE TABLE student_info ( + id int(11) primary key NOT NULL, + student_name varchar(255) , + student_age varchar(255) , + student_sex varchar(255) , + student_time datetime(0) , + class_id int(11) +); +``` + + + +注:主键字段的挑选原则 + +1. 通常选择无意义的字段作为主键字段,比如说表中记录每一行行号的id字段,就是无意义的字段,很适合作为主键 + +2. 主键字段一般不会对其进行修改(像字段名、字段类型等) + +3. 经常变化的字段,有意义的字段,不适合作为主键 + + + +2)主键自增 + +添加主键和自增语法: + +```sql +alter table 数据表名 modify 字段名 int primary key auto_increment; +``` + +删除主键和自增语法: + +先删除自增 + +```sql +alter table 数据表名 modify 字段名 int not null; +``` + +再删除主键 + +```sql +alter table 数据表名 drop primary key; +``` + + + +在建表语句中给id字段加入主键自增约束语法: + +```sql +CREATE TABLE student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_age varchar(255) , + student_sex varchar(255) , + student_time datetime(0) , + class_id int(11) +); +``` + + + +3)唯一约束(unique) + +添加唯一约束语法: + +```sql +alter table 数据表名 add unique(字段名); +``` + +删除唯一约束语法: + +```sql +alter table 数据表名 drop key 字段名; +``` + +在建表语句中给class_id字段加入唯一约束语法: + +```sql +CREATE TABLE student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_age varchar(255) , + student_sex varchar(255) , + student_time datetime(0) , + class_id int(11) , + unique(class_id) +); +``` + + + + + +4)非空约束(NOT NULL) + +添加非空约束语法: + +```sql +alter table 数据表名 modify 字段名 数据类型 not null; +``` + +删除非空约束语法: + +```sql +alter table 数据表名 modify 字段名 数据类型 null; +``` + + + +在建表语句中给student_sex字段加入非空约束语法: + +```sql +CREATE TABLE student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_age varchar(255) , + student_sex varchar(255) NOT NULL, + student_time datetime(0) , + class_id int(11) , + unique(class_id) +); +``` + + + + + +5)默认值约束(default) + +添加默认值约束语法: + +```sql +alter table 数据表名 alter 字段名 set default 0; +``` + +删除默认值约束语法: + +```sql +alter table 数据表名 alter column 字段名 drop default; +``` + +在建表语句中给student_age字段加入非空约束语法: + +```sql +CREATE TABLE student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_age varchar(255) default 0, + student_sex varchar(255) NOT NULL, + student_time datetime(0) , + class_id int(11) , + unique(class_id) +); +``` + + + +6)添加外键约束(FOREIGN KEY (列名) REFERENCES 关联表名(关联列名)) + +比如说,现在有张学生表和班级表,学生表中有个班级字段,这个字段数据就是班级表中的数据,所以,在学生表中的班级字段就是属于班级表的外键,所以 这样就是引用完整性(参照完整性)中讲的,一张表中字段的值,需要参考另外一张表中的值。 + +添加外键约束语法: + +```sql +ALTER TABLE 表名 +ADD CONSTRAINT 外键约束名 +FOREIGN KEY (外键是哪个字段名) +REFERENCES 关联表名(关联列名) +``` + + + +在建表语句中加入外键约束语法: + +```sql + +CREATE TABLE 表名 ( + 列名 数据类型, + ... + CONSTRAINT 外键约束名 FOREIGN KEY (列名) REFERENCES 关联表名(关联列名) +); +``` + +```sql +CREATE TABLE class_info ( + id int(11) primary key auto_increment NOT NULL, + class_name varchar(255) not null +); + +CREATE TABLE student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_age varchar(255) default 0, + student_sex varchar(255) NOT NULL, + student_time datetime(0) , + class_id int(11) , + unique(class_id), + CONSTRAINT fk_classid FOREIGN KEY (class_id) REFERENCES class_info(id) +); + + +``` + + + +删除外键约束语法: + +```sql +ALTER TABLE 表名 DROP FOREIGN KEY 外键约束名; +``` + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/UI/1.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256\345\272\223.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/UI/1.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000000000000000000000000000000000000..e6a70337e255d50c8dd458890a41badd0879b8fa --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/UI/1.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,67 @@ +# 可视化客户端操作数据库 + +### 本节目标:熟悉使用可视化客户端操作数据库 + + + +**1.新建数据库** + +使用Navicat可视化工具创建数据库 + +第一步:打开Navicat软件,连接Mysql; + +第二步:右击连接,点击新建数据库; + +第三步:输入数据库名称,并选择数据库字符集和排序规则; + + + +示例:我们要做一个学生管理系统,需要保存学生、班级、课程、分数等信息,那么可以创建一个学生的数据库 + +![image-20240221161140311](..\imgs\1.png) + +![image-20240221161226072](..\imgs\2.png) + +输入数据库名称:student,点击确定,我们可以看到数据库创建成功了。 + +注:选择字符集和排序规则,如果不选则使用默认字符集和排序规则 + +![image-20240221161544642](..\imgs\3.png) + + 右击数据库,点击打开,我们可以看到一排菜单,这些菜单我们后面再进行讲解 + +![image-20240221161816666](..\imgs\4.png) + + + +**2.修改和删除数据库** + +1)修改数据库 + +右击数据库名称,点击编辑数据库,修改Mysql数据库的字符集和排序规则 + + + +2)删除数据库 + +右击数据库名称,点击删除数据库 + + + +**3.备份与恢复** + +1)备份数据库 + +打开数据库,点击新建备份,点击下一步,选择数据库的表、视图等数据进行备份 + +![image-20240221215146420](..\imgs\15.png) + +2)恢复数据库 + +选择备份好的数据库数据,点击还原备份,以恢复数据 + +![image-20240221215310861](..\imgs\16.png) + +总结: + +本节课重点通过可视化工具创建、修改、删除以及备份还原数据库。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/UI/2.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256\350\241\250.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/UI/2.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256\350\241\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..06928f8152df790c79fe9008d7d21cc69e35cc34 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/UI/2.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256\350\241\250.md" @@ -0,0 +1,122 @@ +# 可视化客户端操作数据表 + +### 本节目标:熟悉使用可视化客户端操作数据表 + +什么是数据表? + +| 学生ID | 姓名 | 年龄 | 性别 | 入学日期 | 班级ID | +| ------ | ---- | ---- | ---- | ------------------- | ------ | +| 1 | 张三 | 18 | 男 | 2024-02-22 08:00:00 | 1 | +| 2 | 李四 | 25 | 男 | 2024-02-22 16:31:46 | 1 | +| 3 | 王丽 | 23 | 女 | 2024-02-21 16:32:08 | 1 | +| 4 | 李红 | 20 | 女 | 2024-02-21 13:32:50 | 2 | +| 5 | 小军 | 22 | 男 | 2024-02-23 09:33:34 | 2 | + +其中 + +学生ID、 姓名、 年龄、 性别、 入学日期、班级ID 这些叫做列名,或者字段名。 +下面每一行都是一条数据记录。student_info id student_name + + + + + + + + + +**1.新建数据表** + +使用Navicat可视化工具创建数据表 + +第一步:打开Navicat软件,连接Mysql; + +第二步:右击数据库名称,打开数据库; + +第三步:选中表,右击新建表或者点击菜单上的新建表,进入建表界面; + +![image-20240222200808350](..\imgs\18.png) + + + +建表界面: + +![image-20240222200934908](..\imgs\19.png) + +注:在建表之前,需要根据业务确定这张表有哪些字段,且这些字段是什么类型的数据,还有哪些属性; + + + +示例:我们通过使用可视化界面,创建名为 student_info的数据表,表中字段参考如下表格 + +| 学生ID | 姓名 | 年龄 | 性别 | 入学日期 | 班级ID | +| ------ | ---- | ---- | ---- | ------------------- | ------ | +| 1 | 张三 | 18 | 男 | 2024-02-22 08:00:00 | 1 | +| 2 | 李四 | 25 | 男 | 2024-02-22 16:31:46 | 1 | +| 3 | 王丽 | 23 | 女 | 2024-02-21 16:32:08 | 1 | +| 4 | 李红 | 20 | 女 | 2024-02-21 13:32:50 | 2 | +| 5 | 小军 | 22 | 男 | 2024-02-23 09:33:34 | 2 | + +在数据表中添加字段: + +![image-20240222202909777](..\imgs\20.png) + +添加字段完成后点击保存,输入数据表名称; + +注:数据表名称应该遵循规范进行创建 + +![image-20240222203127084](..\imgs\21.png) + + + +**2.字段属性** + +字段名称:表的列名 + +数据类型:指字段的数据类型,包括整型、浮点型、文本、日期。可以参照教材98~102页。 + +长度:指字段允许保存的数据长度大小 + +小数点:指当前字段允许存储浮点型数据 + +是否为空:指当前字段数据在保存的时候是否允许为空数据 + +是否为主键:指当前字段为主键,即每行记录的唯一标识 + +是否自动递增:指当前字段是否按照一定顺序自动填充数据 + +是否无符号:指当前字段是否允许存储负数数据 + +是否填充0:指当前数据是否允许填充默认值0 + +外键:指当前字段用户外链其它数据表的数据 + + + +选中数据表,右击点击设计表,进入表设计界面,可以进行一下操作: + +**添加字段** + +**修改字段** + +**删除字段** + +**设置主键** + + + +**3.修改表名** + +选择数据表,右击,选择重命名菜单进行表名修改 + + + +**4.删除表** + +选择数据表,右击,选择删除表菜单进行删除 + + + +总结: + +本节课重点通过可视化工具创建、修改、删除以及备份还原数据表,同时根据对需求的分析来对表的字段进行创建。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/1.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..81a3701a5a14eb99ffc7487d524b0c0a1f67b661 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/1.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/10.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/10.png" new file mode 100644 index 0000000000000000000000000000000000000000..64ed11137aaa260c708dcbb63ba98c2fc7a728c1 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/10.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/11.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/11.png" new file mode 100644 index 0000000000000000000000000000000000000000..22ab28397d11e41c33ed9d63220c28168d5e0322 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/11.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/12.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/12.png" new file mode 100644 index 0000000000000000000000000000000000000000..282f7cd15a45ae481b4ca13db86dfaa3c8ccfe9c Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/12.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/13.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/13.png" new file mode 100644 index 0000000000000000000000000000000000000000..8fac4d7986a31e9ba7f3d897fa4d745e74686bac Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/13.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/14.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/14.png" new file mode 100644 index 0000000000000000000000000000000000000000..8fac4d7986a31e9ba7f3d897fa4d745e74686bac Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/14.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/15.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/15.png" new file mode 100644 index 0000000000000000000000000000000000000000..8dd17d31cbad9b3cbf22967a2b52cf87829ed979 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/15.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/16.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/16.png" new file mode 100644 index 0000000000000000000000000000000000000000..084ffeb38a8b856102c3e7aa1dfd69cb3192fd17 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/16.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/17.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/17.png" new file mode 100644 index 0000000000000000000000000000000000000000..5c7bf6da0dc9ea725ab6fc5a65998418715e39cc Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/17.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/18.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/18.png" new file mode 100644 index 0000000000000000000000000000000000000000..d84eefaa89ef8fad8aedd7b7ef164feef8799441 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/18.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/19.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/19.png" new file mode 100644 index 0000000000000000000000000000000000000000..bdf290005fe3997dcbbf989b57e8dc8e91b5181a Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/19.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/2.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..6902bd9aea29b6bda58baa09958eadda7db7f1c4 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/2.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/20.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/20.png" new file mode 100644 index 0000000000000000000000000000000000000000..3f6cf385a681a3c4fa1ff83574a1b269e9136aa9 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/20.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/21.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/21.png" new file mode 100644 index 0000000000000000000000000000000000000000..7444a0ebe817e772156f044b20049fdc428e8638 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/21.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/22.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/22.png" new file mode 100644 index 0000000000000000000000000000000000000000..99c4c1834dcc1d2d1ae0539aa6520572985543a7 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/22.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/23.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/23.png" new file mode 100644 index 0000000000000000000000000000000000000000..13cc83bedefa626aa1cae3529458d6fd19a5bac2 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/23.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/24.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/24.png" new file mode 100644 index 0000000000000000000000000000000000000000..4be6cf284e5dec6f2c95439b444172a7e404e611 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/24.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/3.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..77678f80554578899c8b27e960fdf9ced21f0bf8 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/3.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/4.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..3b2ba6cdb680307f597e2ea3eeacad8143fd845b Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/4.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/5.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..b517b5e3510f2f792a477becd4e591ebf6be4e86 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/5.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/6.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/6.png" new file mode 100644 index 0000000000000000000000000000000000000000..be7daa9305cf9887e1f35d7ac9590ebacab31e93 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/6.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/7.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/7.png" new file mode 100644 index 0000000000000000000000000000000000000000..005e2cd0ed1baa66be079bcd85ba3adb885cced0 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/7.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/8.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/8.png" new file mode 100644 index 0000000000000000000000000000000000000000..0aa3f7392187446a44f5e3d13181857cb2b08b50 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/8.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/9.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/9.png" new file mode 100644 index 0000000000000000000000000000000000000000..7cb14ba37ea1739e29a08d5762adb2248ecc5c80 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/2_\346\225\260\346\215\256\345\272\223\344\270\216\346\225\260\346\215\256\350\241\250\346\223\215\344\275\234/imgs/9.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/1.\346\226\260\345\242\236\346\225\260\346\215\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/1.\346\226\260\345\242\236\346\225\260\346\215\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..bfd72f5641a4e4399c77ce898afbde3a7d89cff7 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/1.\346\226\260\345\242\236\346\225\260\346\215\256.md" @@ -0,0 +1,144 @@ +# 新增数据 + +### 本节目标:熟悉Mysql新增和批量新增数据 + + + +**1.数据准备** + +首先,我们需要准备数据,这边先建好学生数据库,然后新建学生信息表、班级信息表 + +```sql +-- 建库部分 + +-- 新建student数据库 +CREATE DATABASE IF NOT EXISTS student character set utf8mb4 collate utf8mb4_0900_ai_ci; + +-- 使用student数据库 +use student; + +-- 建表部分 + +-- 创建学生信息表,表中包含,学生ID,姓名,性别,年龄,生日,家庭住址,所属班级id字段 + +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11) +); + +-- 创建班级信息表,表中包含, + +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +``` + +**2.插入数据** + +插入数据语法: + +```sql +insert into 数据表名称(列名1,列名2,列名3,...)values(数据1,数据2,数据3,...); +``` + +其中: + +1. insert 是我们DML语言分类中的 新增数据关键字 +2. 表名 表示插入哪个表。 +3. 列名1,列名2,列名3,... 表示字段的名称,后面...表示可以有多个的意思。 +4. values 是关键词,表示要插入的值。 +5. 数据1,数据2,数据3,... 表示插入数据的值,要和前面列名一一对应。 + + + +示例1:在学生表中,新增以下数据 + +需求:新增8个同学数据,如下 + +- 刘小东、男(1)、24、2000-01-01、广西省桂林市七星区空明西路10号鸾东小区、2 +- 黄龙辉、男(1)、25、1999-03-20、江西省南昌市青山湖区艾溪湖南路南150米广阳小区、1 +- 陈丽、女(2)、24、2000-07-08、福建省龙岩市新罗区曹溪街道万达小区、1 +- 林小松、男(1)、22、2002-03-09、云南省昆明市五华区华山街道华山小区、1 +- 舒燕、女(2)、22、2002-07-09、福建省龙岩市新罗区万宝社区、2 +- 王海欣、女(2)、22、2002-09-09、福建省龙岩市新罗区东肖社区、1 +- 吴韦林、男(1)、24、2000-06-09、福建省厦门市湖里区禾山街道围里社、3 +- 欧阳武、男(1)、20、2004-07-15、陕西省西安市雁塔区雁塔社区、3 + +插入这些数据: + +```sql +INSERT INTO student_info(student_name, student_sex, student_age, student_time, student_address, class_id) VALUES ('刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO student_info(student_name, student_sex, student_age, student_time, student_address, class_id) VALUES ('黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO student_info(student_name, student_sex, student_age, student_time, student_address, class_id) VALUES ('陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO student_info(student_name, student_sex, student_age, student_time, student_address, class_id) VALUES ('林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO student_info(student_name, student_sex, student_age, student_time, student_address, class_id) VALUES ('舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO student_info(student_name, student_sex, student_age, student_time, student_address, class_id) VALUES ('王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 1); +INSERT INTO student_info(student_name, student_sex, student_age, student_time, student_address, class_id) VALUES ('吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO student_info(student_name, student_sex, student_age, student_time, student_address, class_id) VALUES ('欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + +``` + + + +示例2:在班级表中,新增以下数据 + +需求:3个班级数据,如下: + +```sql +insert into class_info (class_name) values ('软件技术1班'); +insert into class_info (class_name) values ('软件技术2班'); +insert into class_info (class_name) values ('软件技术3班'); +``` + +**3.批量插入数据** + +上面插入数据,大家可以看到是一条条插入,Mysql也支持批量进行插入,批量插入语法: + +```sql +insert into 数据表名称 (列名1,列名2,列名3,...) + values + (数据1,数据2,数据3,...), + (数据1,数据2,数据3,...), + (数据1,数据2,数据3,...),...; +``` + +和单条插入数据一样,只是在values后面罗列多个数据项,然后用英文逗号 , 分隔即可。 + +示例1:以批量插入的方式新增学生信息表数据: + +```sql +insert into student_info (student_name, student_sex, student_age, student_time, student_address, class_id) + values + ('刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2), + ('黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1), + ('陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1), + ('林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1), + ('舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2), + ('王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 1), + ('吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3), + ('欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3) + ; +``` + +示例2:以批量插入的方式新增班级信息表数据: + +```sql +insert into class_info (class_name) + values + ('软件技术1班'), + ('软件技术2班'), + ('软件技术3班'); +``` + + + +总结: + +本节课重点讲使用SQL语句新增和批量新增数据至对应数据表中。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/2.\345\210\240\351\231\244\346\225\260\346\215\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/2.\345\210\240\351\231\244\346\225\260\346\215\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..50adca8929d5720e9882d7696f228632c765aed3 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/2.\345\210\240\351\231\244\346\225\260\346\215\256.md" @@ -0,0 +1,138 @@ +# 删除数据 + +### 本节目标:熟悉Mysql删除数据 + + + +**1.数据准备** + +首先,我们先插入测试数据,参考: + +``` +删除数据示例.sql +``` + + + +**2.删除数据** + +在MySQL数据库中,删除数据是一个常见的操作,它允许从表中移除不再需要的数据。在执行删除操作时,需要谨慎,以免误删重要数据。 + + + +方法介绍: + +- DELETE 语句 +- DROP TABLE 语句 +- TRUNCATE TABLE 语句 +- 使用外键约束 + +删除数据语法: + +```sql +DELETE FROM 数据表名称 WHERE 条件; +``` + +其中: + +1. 关键字:DELETE FROM +2. 表名:即需要删除数据所在的表 +3. 条件:是一个可选的,用于指定要删除的行。如果不提供条件,将删除表中的所有数据。 + + + +示例1:删除score_info表中学生欧阳武 数据库高级应用 课程成绩插入重复了,请删除其中一条数据 + +插入这些数据: + +```sql +delete from score_info where id = 33; +``` + +示例2:后面不再开设新媒体班了,请删除这个班级 + +```sql +delete from class_info where id = 4; +``` + +执行删除语句后,会报一个错误: + +![image-20240226130710575](..\imgs\1.png) + + + +1451 - Cannot delete or update a parent row: a foreign key constraint fails (`student`.`student_info`, CONSTRAINT `student_info_ibfk_1` FOREIGN KEY (`class_id`) REFERENCES `class_info` (`id`)) + + + +实际上这个问题是由于,我们在建表或者后面有相关需求的时候,往表中加入了外键约束,所以导致我们想删除是数据的时候会出现错误。 + +所以如果说有使用外键的,需删除,使用该外键的数据,然后再删除原始数据。 + +但是我们一般在开发过程中不这样做,正常都是会做个逻辑删除的操作,而不做物理删除。 + + + +示例3:删除student_info表中的所有数据 + +```sql +delete from 数据表名; +``` + +不加条件的删除,表示删除表所有数据。一般要慎重使用。 + + + +**3.清空数据** + +在MySQL 中除了用delete删除数据外,还可以使用truncate进行。 + +truncate 关键字用于完全清空一个表。其语法格式如下: + +```sql +truncate table 数据表名称; +``` + +其中: + +truncate table 为关键字,这个语法中,table是可以省略的。 + + + +示例:请使用truncate 语句清空student_info表中的数据 + +```sql +truncate table student_info; +``` + + + +**4.truncate和delete的区别** + +从逻辑上说,truncate 语句与 delete 语句作用相同,但是在某些情况下,两者在使用上有所区别。 + +1.delete 是 DML 类型的语句;truncate 是 DDL 类型的语句。它们都用来清空表中的数据。 + +2.delete 是逐行一条一条删除记录的;truncate 则是直接删除原来的表,再重新创建一个一模一样的新表,而不是逐行删除表中的数据,执行数据比 delete 快。因此需要删除表中全部的数据行时,尽量使用 truncate 语句, 可以缩短执行时间。 + +3.delete 删除数据后,配合事件回滚可以找回数据;truncate 不支持事务的回滚,数据删除后无法找回。 + +4.delete 删除数据后,系统不会重新设置自增字段的计数器;truncate 清空表记录后,系统会重新设置自增字段的计数器。 + +5.delete 的使用范围更广,因为它可以通过 where 子句指定条件来删除部分数据;而 truncate 不支持 where 子句,只能删除整体。 + +6.delete 会返回删除数据的行数,但是 truncate 只会返回 0,没有任何意义。 + + + + + +总结: + +本节课重点讲使用SQL语句删除数据表数据,还有truncate和delete两个关键字的区别和使用。 + +相关删除操作: + +1. 当不需要该表时,用 drop; +2. 当仍要保留该表,但要删除所有记录时,用 truncate; +3. 当要删除部分记录时,用 delete。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/3.\344\277\256\346\224\271\346\225\260\346\215\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/3.\344\277\256\346\224\271\346\225\260\346\215\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..99e6c9e42677b53385e128d5aba43026fd256944 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/3.\344\277\256\346\224\271\346\225\260\346\215\256.md" @@ -0,0 +1,78 @@ +# 修改数据 + +### 本节目标:熟悉Mysql修改数据 + + + +**1.数据准备** + +首先,我们先插入测试数据,参考: + +``` +修改数据示例.sql +``` + + + +**2.修改数据** + +在MySQL数据库中,修改数据是一个常见的操作,它允许从表中修改数据。语法如下: + +```sql +update 数据表名称 set 列1 = '值1',列2 = '值2',列3 = '值3',... WHERE 条件; +``` + +其中: + +1. update 是关键词,表示修改的意思。 +2. 表名 表示修改哪个表。 +3. set 是关键词,表示设置的意思。 +4. 列1='值1',表示将 列1 的值修改为 值1。 + + + +示例1:学生信息表中,刘小东同学的年龄写错了,正确年龄是 24,请使用sql修改: + +```sql +update student_info set student_age = 24 where id = 1; +``` + +示例2:学生信息表中,黄龙辉同学的生日写错了,正确生日是 1999-03-20,请使用sql修改: + +```sql +update student_info set student_time = '1999-03-20' where id = 2; +``` + +示例3:学生信息表中,林小松同学的性别(1:男生,2:女生)和班级写错了,他是男生,而且是软件技术1班的,请使用sql修改: + +```sql +update student_info set student_sex = 1,class_id = 1 where id = 4; +``` + +示例4:陈丽和王海欣同学 转到软件技术1班了,请使用sql修改: + +```sql +update student_info set class_id = 1 where id in (3,6) +``` + +或者 + +```sql +update student_info set class_id = 1 where id = 3 or id =6; +``` + + + +思考:如果修改语句中没有加where条件会出现什么情况呢? + +示例5:学校对课程学分进行了调整,每门课程学分都增加1分,请使用sql修改 + +```sql +update course_info set course_credit = course_credit+1; +``` + + + +总结: + +本节课重点讲使用SQL语句修改数据表数据 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/4.\346\237\245\350\257\242\346\225\260\346\215\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/4.\346\237\245\350\257\242\346\225\260\346\215\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..7f2b81a3face3026ba788eb1b279a8b971b72a83 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/4.\346\237\245\350\257\242\346\225\260\346\215\256.md" @@ -0,0 +1,661 @@ +# 查询数据 + +### 本节目标:熟悉Mysql查询数据 + + + +**数据准备** + +``` +查询数据示例.sql +``` + + + +查询所有数据 + +查询指定列名 字段 as 别名 + +查询数据排序 order by + +查询条件筛选 + + + + + +**条件筛选** + +假如我们只想查询出某个班级的学生,在SQL Sql中允许对查询进行筛选,查询语法: + +```sql +select * from 表名 where 条件; +``` + +其中: + +where 是关键词。 +条件 表示筛选的条件,比如 ClassId=1, + + + +多条件: + +多个条件都要满足用 and 关键词连接。 +多个条件满足1个用 or 关键词连接。 + +条件中可以有如下符号: + +| 操作符 | 描述 | +| --------------------------------- | ------------ | +| = | 等于 | +| <> != | 不等于 | +| > | 大于 | +| < | 小于 | +| >= | 大于等于 | +| <= | 小于等于 | +| between and,not between and | 在某个范围内 | +| is null | 为空 | +| is not null | 不非空 | +| in | 包含在内 | +| not in | 不包含在内 | +| like | 模糊查询 | + + + +**示例1**,查询软件技术1班所有的学生: + +**示例2**,查询不是软件技术1班所有的学生: + +**示例3**,查询所有的女生: + +**示例4**,查询2000年出生的所有学生: + +**示例5**,查询软件技术1班和软件技术2班所有的学生: + +**示例6**,查询生日没有录入的学生: + +**示例7**,查询家庭住址不为空的学生: + +**示例8**,查询刘小东和黄龙辉的考试成绩: + +**示例9**,查询姓名为 刘小东、黄龙辉 、王海欣的学生信息: + +**示例10**,查询不为软件1班和软件2班的学生信息: + + + +**模糊查询** + +假如我们想查找出龙岩市的所有学生,就不能用 = 号了,因为学生家庭住址是地址的字符串,包含了省份、市、区、街道等信息。 + +在Mysql中允许进行模糊查询,查询语法: + +```sql +select * from 表名 where 字段 like '%查找的词%' +``` + +其中: + + 1. 字段 表示在哪个字段里进行模糊查找。 + 2. like 是关键词。 + 3. '%查找的词%' 表示查找对应列内容包含 查找的词 的记录。 + +其中%含义: + + 1. 查找的词 前面没有%,那么表示这个词要在字符串的开始。 + 2. 查找的词 后面没有%,那么表示这个词要在字符串的结尾。 + 3. 查找的词 前后都有%,那么表示这个词在字符串的任意位置都可以。 + +示例1,查询地址是龙岩市的学生: + +```sql +select * from student_info where student_address like '%龙岩市%'; +``` + +示例2,查询地址是福建省的学生: + +```sql +select * from student_info where student_address like '%福建省%'; +``` + +示例3,查询姓是刘的学生: + +```sql +select * from student_info where student_name like '%刘%'; +``` + +**模糊查询下划线** + +模糊查询还有一种方式,用下划线 _ 来表示单独的一个字。 + +示例4,查询姓王的学生,并且是三个字的: + +```sql +select * from student_info where student_name like '王__'; +``` + + + + + + + + + +查询当前表中若干条数据 limit offest--偏移量,rows--行数; + +查询结果不重复 distinct + +聚合函数查询 + +分组查询 group by + +分组后筛选 group by having + + + + + + + + + + + + + + + + + + + + + + + + + + + +**1.数据准备** + +首先,我们先插入测试数据,参考: + +``` +查询数据示例.sql +``` + + + +**2.查询所有数据** + +在MySQL数据库中,查询数据是一个常见的操作,语法如下: + +```sql +select * from 数据表名称; +``` + +其中: + +1. select 和from 是固定关键词,* 表示查询全部列的意思。 +2. 表名 表示从哪个表查询 + + + +示例1:查询所有的班级信息: + +```sql +select * from class_info; +``` + +示例2:查询所有的学生信息: + +```sql +select * from student_info; +``` + +示例3:查询所有的课程信息: + +```sql +select * from course_info; +``` + +示例4:查询所有的班级课程信息: + +```sql +select * from class_course; +``` + +示例5:查询所有的分数信息: + +```sql +select * from score_info; +``` + +**3.查询指定列名** + +上面所学习的语句都是查出全部列名的,如果说某一张表有几十个甚至更多的字段,那查询所有列数据的话就变慢了,所以我们查询的时候应该按需查询,尽量避免使用 (select * from)进行查询。 + +指定列查询语法: + +```sql +select 列名1,列名2,列名3,... from 数据表名称; +``` + +示例1:查询学生信息表中的学生姓名、年龄和生日数据 + +```sql +select student_name,student_age,student_time from student_info; +``` + + + +查询列指定别名: + +由于我们的字段名都是英文,不太容易看,所以可以在查询的时候给列名指定一个别名: + +语法: + +```sql +select 列名1 as 别名1, 列名2 as 别名1, 列名3 as 别名3, ... from 表名 +``` + +示例2: + +```sql +select student_name as 姓名,student_age as 年龄,student_time as 生日 from student_info; +``` + +**4.数据排序** + +在日常生活中,我们会经常按照某个属性进行数据排序,比如: + +在京东、天猫等平台进行购物时,我们会按照价格、销量进行排序; + +学生管理系统中按照成绩进行排序; + + + +在数据库进行数据查找时,也可以使用sql对数据进行排序 + +查询语法: + +```sql +select * from 表名 order by 字段 [desc|asc]; +``` + +其中: + +order by 是关键词。 +字段 表示需要排序的字段。 +desc表示降序排列,asc表示升序排列。 + +注:mysql数据库中,如果不使用order by关键词,则数据默认升序排列; + +如果使用了order by关键词,没有指定排列规则,则数据库默认升序排列; + +**5.条件筛选** + +假如我们只想查询出某个班级的学生,在SQL Sql中允许对查询进行筛选,查询语法: + +```sql +select * from 表名 where 条件; +``` + +其中: + +where 是关键词。 +条件 表示筛选的条件,比如 ClassId=1, + + + +多条件: + +多个条件都要满足用 and 关键词连接。 +多个条件满足1个用 or 关键词连接。 + +条件中可以有如下符号: + +| 操作符 | 描述 | +| --------------------------------- | ------------ | +| = | 等于 | +| <> | 不等于 | +| > | 大于 | +| < | 小于 | +| >= | 大于等于 | +| <= | 小于等于 | +| between and,not between and | 在某个范围内 | +| is null | 为空 | +| is not null | 不非空 | +| in | 包含在内 | +| not in | 不包含在内 | +| like | 模糊查询 | + + + +**示例1**,查询软件技术1班所有的学生: + +```sql +select * from student_info where class_id = 1; +``` + +**示例2**,查询不是软件技术1班所有的学生: + +```sql +select * from student_info where class_id <> 1; +``` + +**示例3**,查询所有的女生: + +```sql +select * from student_info where student_sex = 2; +``` + +**示例4**,查询2000年出生的所有学生: + +```sql +select * from student_info where student_time >= '2000-01-01' and student_time < '2001-01-01'; +``` + +也可以使用between关键词: + +```sql +select * from student_info where student_time between '2000-01-01' and '2000-12-31'; +``` + +**示例5**,查询软件技术1班和软件技术2班所有的学生: + +```sql +select * from student_info where class_id = 1 or class_id = 2; +``` + +```sql +select * from Student where class_id in (1, 2); +``` + +**示例6**,查询生日没有录入的学生: + +```sql +select * from student_info where student_time is null; +``` + +**示例7**,查询家庭住址不为空的学生: + +```sql +select * from student_info where student_address is not null; +``` + +**示例8**,查询刘小东和黄龙辉的考试成绩: + +```sql +select * from score_info where student_id in (1, 2); +``` + +**示例9**,查询姓名为 刘小东、黄龙辉 、王海欣的学生信息: + +```sql +select * from student_info where student_name in ('刘小东', '黄龙辉', '王海欣'); +``` + +**示例10**,查询不为软件1班和软件2班的学生信息: + +```sql +select * from student_info where class_id not in ('1', '2'); +``` + + + +**6.查询当前表中若干条数据** + +上面每个sql语句都查询了相应表的所有记录,试想如果一个表的数据记录很多,有上千万条,那么一次查询出来就很慢了。 + +在MySQL中允许查询若干条记录。查询语法: + +```sql +select * from 表名 limit [offset,] rows; +``` + +其中: + +offset:指定第一个返回记录行的偏移量(即从哪一行开始返回)。 +rows:返回具体行数。 + + + +注意:初始行的偏移量为0。 + +示例1,查询3条学生信息: + +```sql +select * from student_info limit 3; +``` + +注:语句中只有一个参数rows,表示从第一条数据开始,查询3条数据 + + + +示例2,从第2行数据开始,查询3条学生信息: + +```sql +select * from student_info limit 2,3; +``` + +注:语句中存在参数limit和rows,则说明语句中offset偏移量是从offset+1开始,所以是从第几条记录开始查询,查询多少条记录。(从第(2+1)条记录开始,共查询3条记录) + + + + + +**7.查询结果不重复** + +查询指定列时,可能会出现结果多行重复,可以使用distinct关键字去除重复项; + +例如:查询学生表中的班级编号信息 + +```sql +select class_id from student_info; +``` + +查询结果班级编号很多重复,可以采用 distinct 关键字去除重复 + +```sql +select distinct class_id from student_info; +``` + + + + + +**8.模糊查询** + +假如我们想查找出龙岩市的所有学生,就不能用 = 号了,因为学生家庭住址是地址的字符串,包含了省份、市、区、街道等信息。 + +在Mysql中允许进行模糊查询,查询语法: + +```sql +select * from 表名 where 字段 like '%查找的词%' +``` + +其中: + + 1. 字段 表示在哪个字段里进行模糊查找。 + 2. like 是关键词。 + 3. '%查找的词%' 表示查找对应列内容包含 查找的词 的记录。 + +其中%含义: + + 1. 查找的词 前面没有%,那么表示这个词要在字符串的开始。 + 2. 查找的词 后面没有%,那么表示这个词要在字符串的结尾。 + 3. 查找的词 前后都有%,那么表示这个词在字符串的任意位置都可以。 + +示例1,查询地址是龙岩市的学生: + +```sql +select * from student_info where student_address like '%龙岩市%'; +``` + +示例2,查询地址是福建省的学生: + +```sql +select * from student_info where student_address like '%福建省%'; +``` + +示例3,查询姓是刘的学生: + +```sql +select * from student_info where student_name like '%刘%'; +``` + +**模糊查询下划线** + +模糊查询还有一种方式,用下划线 _ 来表示单独的一个字。 + +示例4,查询姓王的学生,并且是三个字的: + +```sql +select * from student_info where student_name like '王__'; +``` + + + +**9.聚合函数查询** + +在excel中,我们也会经常使用excel的求总记录数、和、平均、最小值、最大值等函数。Mysql也支持这样的函数,这些叫聚合函数。 + +相关语法: + +```sql +-- 求总记录数 +select count(主键) from 表名; + +select count(1) from 表名; + +select count(*) from 表名; + +select count(字段名) from 表名; + +-- 如果没有主键,则count(1)比count(*)快; +-- 如果有主键,则count(主键)比count(1)快; +-- 如果只有一个字段,则count(*)是最快的; +-- count(1)和count(*)都包含对null的统计,而count(字段)不包含对null的统计; + +-- 求和 +select sum(字段) from 表名; + +-- 求平均 +select avg(字段) from 表名; + +-- 求最小值 +select min(字段) from 表名; + +-- 求最大值 +select max(字段) from 表名; +``` + +示例1,查询 软件技术1班 有几个学生: + +```sql +select count(id) from student_info where class_id = 1; +``` + +示例2,查询 软件技术1班 有几门课程: + +```sql +select count(id) from class_course where class_id = 1; +``` + +示例3,查询 刘小东(学生编号为1) 的总分: + +```sql +select sum(score) from score_info where student_id = 1; +``` + +示例4,查询所有学生 数据库高级应用 的平均分: + +```sql +select * from score_info where course_id = 1; +select sum(score) as 总分,count(0) as 学生总数 from score_info where course_id = 1; +select avg(score) from score_info where course_id = 1; +``` + + + +**10.分组查询** + +假如我们现在查询每个学生的总分,按照前面学过的知识,我们可以逐个学生进行聚合sum查询。 + +```sql +select sum(score) as TotalScore from score_info where student_id = 1; +select sum(score) as TotalScore from score_info where student_id = 2; +``` + +只是这样有点麻烦,在Mysql中可以通过分组查询的功能进行实现。相关语法: + +```sql +select 字段1, 聚合函数(字段2) from 表名 group by 字段1; +``` + +其中 + +1. 字段1 表示需要分组的字段。 +2. 字段2 表示聚合函数需要的字段。 + + + +示例1,查询 每个学生 的总分: + +```sql +select student_id, sum(score) as TotalScore from score_info group by student_id; +``` + +示例2,查询 每个学生 的平均分(聚合查询 + 分组) + +```sql +select student_id, avg(score) as TotalScore from score_info group by student_id; +``` + +示例3,查询出学生的平均分后,还希望按照平均分从高到低排列: + +```sql +select student_id, avg(score) as AvgScore from score_info group by student_id order by AvgScore desc; +``` + +**分组后筛选** + +上面的例子查询出了每个学生的平均分,如果需要筛选出平均分大于80分的,可以使用having语法: + + select 字段1, 聚合函数(字段2) from 表名 group by 字段1 having 条件 + +示例4,查询 所有学生中 平均分 大于80分的学生: + +```sql +select student_id, avg(score) as AvgScore from score_info group by student_id having AvgScore > 80 ; +``` + +## 总结 + +上面只是单独针对每个场景进行讲解,这些场景可以混合进行查询,在Mysql中查询的整体语法: + +select [列1,列2,...|*] from 表名 + +​ [where 条件] + +​ [group by 字段] + +​ [having 条件] + +​ [order by 字段] + +​ [limit ] + + + + + + + +总结: + +本节课重点讲使用SQL语句查询数据表数据 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\344\277\256\346\224\271\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\344\277\256\346\224\271\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..7456992817cf3bd9ceaf98877246cb6b15f06c42 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\344\277\256\346\224\271\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,192 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '22', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '2001-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 2, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (1, '数据库高级应用', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (2, 'javascript编程基础', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (3, 'web前端程序设计基础', 4); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (4, '动态网页设计.net基础', 6); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (31, 8, 3, 82); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (33, 8, 4, 67); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\345\210\240\351\231\244\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\345\210\240\351\231\244\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..9eb523a5a9d7108a3c06abfe0cc281e98a21791a --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\345\210\240\351\231\244\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,193 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (4, '新媒体1班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (1, '数据库高级应用', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (2, 'javascript编程基础', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (3, 'web前端程序设计基础', 4); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (4, '动态网页设计.net基础', 6); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (31, 8, 3, 82); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (33, 8, 4, 67); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..0b5d1863f3f20edd1807e6e4f683090197f97c5f --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,194 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (1, '数据库高级应用', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (2, 'javascript编程基础', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (3, 'web前端程序设计基础', 4); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (4, '动态网页设计.net基础', 6); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (31, 8, 3, 82); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (33, 8, 4, 67); + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\346\237\245\350\257\242\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\346\237\245\350\257\242\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..ab638ab20cbd92ebcf73ffeef9f41fd0504e77c7 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\346\225\260\346\215\256\347\244\272\344\276\213/\346\237\245\350\257\242\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,192 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有4个同学,软件技术2班有2个同学,软件技术3班有2个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区', 3); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (1, '数据库高级应用', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (2, 'javascript编程基础', 3); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (3, 'web前端程序设计基础', 4); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`) VALUES (4, '动态网页设计.net基础', 6); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (15, 4, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (16, 4, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (23, 6, 3, 66); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (24, 6, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (29, 8, 1, 90); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (30, 8, 2, 56); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (31, 8, 3, 82); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (32, 8, 4, 67); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (33, 8, 4, 67); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..2a8b0f8a380e05cff52a337086b926671fd4ddca --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/SQL/\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,103 @@ +## 课堂练习 + +### 增加数据 + +1. 学校开设了3个班级:软件技术1班、软件技术3班、软件技术3班。请插入班级表相关数据。 + +2. 一共有8个同学,其中,软件技术1班有3个同学,软件技术2班有3个同学,软件技术3班有2个同学,请插入这些同学的 姓名、性别、年龄、生日、家庭住址 、所属班级 数据: + + - 刘小东、男(1)、24、2000-01-01、广西省桂林市七星区空明西路10号鸾东小区、2 + - 黄龙辉、男(1)、25、1999-03-20、江西省南昌市青山湖区艾溪湖南路南150米广阳小区、1 + - 陈丽、女(2)、24、2000-07-08、福建省龙岩市新罗区曹溪街道万达小区、1 + - 林小松、男(1)、22、2002-03-09、云南省昆明市五华区华山街道华山小区、1 + - 舒燕、女(2)、22、2002-07-09、福建省龙岩市新罗区万宝社区、2 + - 王海欣、女(2)、22、2002-09-09、福建省龙岩市新罗区东肖社区、1 + - 吴韦林、男(1)、24、2000-06-09、福建省厦门市湖里区禾山街道围里社、3 + - 欧阳武、男(1)、20、2004-07-15、陕西省西安市雁塔区雁塔社区、3 + +6. 软件技术1班、软件技术3班、软件技术3班 开设课程,课程名称和学分分别为: + + - 数据库高级应用、3 + - javascript编程基础、3 + - web前端程序设计基础、4 + - 动态网页设计.net基础、6 + +9. 考试完成后,各学生各课程得分: + + 刘小东、数据库高级应用、80 + 刘小东、javascript编程基础、78 + 刘小东、web前端程序设计基础、65 + 刘小东、动态网页设计.net基础、90 + + 黄龙辉、数据库高级应用、60 + 黄龙辉、javascript编程基础、77 + 黄龙辉、web前端程序设计基础、68 + 黄龙辉、动态网页设计.net基础、88 + + 陈丽、数据库高级应用、88 + 陈丽、javascript编程基础、45 + 陈丽、web前端程序设计基础、61 + 陈丽、动态网页设计.net基础、75 + + 林小松、数据库高级应用、80 + 林小松、javascript编程基础、78 + 林小松、web前端程序设计基础、65 + 林小松、动态网页设计.net基础、90 + + 舒燕、数据库高级应用、60 + 舒燕、javascript编程基础、77 + 舒燕、web前端程序设计基础、68 + 舒燕、动态网页设计.net基础、88 + + 王海欣、数据库高级应用、88 + 王海欣、javascript编程基础、45 + 王海欣、web前端程序设计基础、66 + 王海欣、动态网页设计.net基础、75 + + 吴韦林、数据库高级应用、88 + 吴韦林、javascript编程基础、48 + 吴韦林、web前端程序设计基础、69 + 吴韦林、动态网页设计.net基础、51 + + 欧阳武、数据库高级应用、90 + 欧阳武、javascript编程基础、56 + 欧阳武、web前端程序设计基础、82 + 欧阳武、动态网页设计.net基础、67 + +### 修改和删除数据 + +1. 学生信息表中,刘小东同学的年龄写错了,正确年龄是 24,请使用sql修改。 +2. 学生信息表中,黄龙辉同学的生日写错了,正确生日是 1999-03-20,请使用sql修改。 +3. 学生信息表中,林小松同学的性别(1:男生,2:女生)和班级写错了,他是男生,而且是软件技术1班的,请使用sql修改 +4. 陈丽和王海欣同学 转到软件技术1班了,请使用sql修改 +5. 学校对课程学分进行了调整,每门课程学分都增加1分,请使用sql修改 +6. 分数表这边 欧阳武 数据库高级应用 成绩 插入重复了,请帮忙删除其中一条数据; + +### 查询数据 + +1. 查询所有的班级信息。 +2. 查询所有的学生信息。 +3. 查询所有的课程信息。 +4. 查询所有的班级课程信息。 +5. 查询所有的分数信息。 +6. 只查询学生的姓名和地址信息。 +7. 查询获取学生信息表中3个学生信息。 +8. 查询学生信息表中的班级编号有哪些(去除重复值)。 +9. 查询分数表中有成绩的学生编号; +10. 查询所有的课程 信息,并且按照学分从大到小排列。 +11. 查询所有的分数 信息,并且按照分数从小到大排列。 +12. 查询所有的学生 信息,并且按照年龄从小到大排列。 +13. 查询软件技术1班所有的学生信息,显示学生id,姓名、性别、生日、住址。 +14. 查询所有的女生,显示学生id,姓名、性别、生日、住址。 +15. 查询2000年出生的所有学生,显示学生id,姓名、性别、生日、住址。 +16. 查询姓是欧阳的学生。 +17. 查询地址是龙岩市的学生。 +18. 查询姓王的学生,并且是三个字的。 +19. 查询 软件技术1班 有几个学生。 +20. 查询 软件技术1班 有几门课程。 +21. 查询 刘小东(学生编号为1) 的总分。 +22. 查询所有学生 数据库高级应用 的平均分。 +23. 查询 所有学生 的总分。 +24. 查询 所有学生 的平均分。 +25. 查询 所有学生 的平均分,并且按照平均分从高到低排列。 +22. 查询 所有学生中 平均分 大于80分的学生。(聚合查询 + 分组 + having) diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/UI/1.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/UI/1.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..dd3239d5239b9774168bdb8fcf3ffb209438c3dc --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/UI/1.\345\217\257\350\247\206\345\214\226\345\256\242\346\210\267\347\253\257\346\223\215\344\275\234\346\225\260\346\215\256.md" @@ -0,0 +1,103 @@ +# 可视化客户端操作数据 + +### 本节目标:熟悉使用可视化客户端操作数据 + + + +**1.新增数据** + +使用Navicat可视化工具创建数据库 + +第一步:打开Navicat软件,连接Mysql; + +第二步:右击连接,打开测试数据库; + +第三步:打开测试数据表; + + + +示例:打开测试表,新增数据 + +![image-20240305110036674](..\imgs\2.png) + + + +在表中输入需要新增的数据,点击下面的 √ 号保存 + +![image-20240305110220358](..\imgs\3.png) + + + +新增数据成功 + +![image-20240305110351285](..\imgs\4.png) + + + + + +注意: 新增数据的时候,数据不能随便填,必须按照数据类型填写 + + + +**2.修改数据** + +使用Navicat可视化工具创建数据库 + +第一步:打开Navicat软件,连接Mysql; + +第二步:右击连接,打开测试数据库; + +第三步:打开测试数据表; + + + +示例:打开测试表,修改 course_name 数据 + +修改数据可以直接在表中修改,注意修改数据也是需要跟新增数据一样,必须按照数据类型数据填写 + +![image-20240305110710501](..\imgs\5.png) + + + +![image-20240305110756293](..\imgs\6.png) + +![image-20240305110846652](..\imgs\7.png) + +修改完后,点击 √ 进行数据提交,修改成功 + + + +**3.删除数据** + +使用Navicat可视化工具创建数据库 + +第一步:打开Navicat软件,连接Mysql; + +第二步:右击连接,打开测试数据库; + +第三步:打开测试数据表; + + + +示例:删除表中 id为1的数据 + +![image-20240305111115476](..\imgs\8.png) + + + +![image-20240305111204981](..\imgs\9.png) + + + +选中数据后,点击 下面的 - 号: + +![image-20240305111319507](..\imgs\10.png) + + + +![image-20240305111400178](..\imgs\11.png) + + + +点击 “删除一条记录” 执行数据删除,删除成功。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/1.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..d4af4544c6926bac668fd4afd30d1305a1faa8d1 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/1.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/10.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/10.png" new file mode 100644 index 0000000000000000000000000000000000000000..d0f911d6c1c03f3414dd18c228383571cc878bfb Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/10.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/11.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/11.png" new file mode 100644 index 0000000000000000000000000000000000000000..aff330585770b1c07e2c6322798cfa2f5010413f Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/11.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/2.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..bc9b53f4b8e7a4e6c48bea01bd7b85f705fa2dff Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/2.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/3.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..0010ac87839531e59c5ac287d707ced5c28c4db8 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/3.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/4.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..ca1eb2f93a9de3a61cd1dea1bed778fd2aa44a70 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/4.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/5.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..d24aff836d20f2e00c3fb0361fb72bd086e9e2c9 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/5.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/6.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/6.png" new file mode 100644 index 0000000000000000000000000000000000000000..54db86365f15a99ab90ac860cb01a02cd91d4083 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/6.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/7.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/7.png" new file mode 100644 index 0000000000000000000000000000000000000000..244955a6218a8e3ce04a90a37c77cb07ecec58dc Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/7.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/8.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/8.png" new file mode 100644 index 0000000000000000000000000000000000000000..3f3751008320662a66952d52242b0f7ab714cf99 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/8.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/9.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/9.png" new file mode 100644 index 0000000000000000000000000000000000000000..993bb21023f88e6e56cc8f013b2a1dce42af7a1c Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/3_\346\225\260\346\215\256\347\232\204\345\242\236\345\210\240\346\224\271\346\237\245/imgs/9.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/1.\350\277\236\346\216\245\346\237\245\350\257\242.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/1.\350\277\236\346\216\245\346\237\245\350\257\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..02757ccd84869db22ce2571cc3e1a3ce3a80094a --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/1.\350\277\236\346\216\245\346\237\245\350\257\242.md" @@ -0,0 +1,324 @@ +# 连接查询数据 + +### 本节目标: + +#### 笛卡尔积 + +#### 内连接 + +#### 左连接查询数据 + +#### 右连接查询数据 + + + + + + + + + + + + + +**1.笛卡尔积** + + 笛卡尔积也称交叉连接,交叉连接是内连接的一种。 + + 假设集合A={a,b},集合B={0,1,2},则两个集合的笛卡尔积为{(a,0),(a,1),(a,2),(b,0),(b,1), (b,2)}。 + + 如果A表示学生的集合,B表示该班级的集合,则A与B的笛卡尔积表示学生与班级所有可能的情况。 + + **笛卡尔积特点**:它不使用任何匹配或者选取条件,而是直接将一个数据源中的每个行与另一个数据源的每个行 一 一 匹配。 + + + +示例:查询对应的学生和班级信息 + +```sql +select * from student_info,class_info; +``` + +该查询结果集有什么问题? + +因为没有任何条件现在,所以结果集中的数据是两张表记录的乘积,那这个现象就称作**笛卡尔积现象** + + + +如何处理呢? + +需要在该语句基础上增加限制条件,来消除笛卡尔积现象 + +```sql +select * from student_info si,class_info ci where si.class_id = ci.id; +``` + + + +**结果:** + +笛卡尔积:一个表的每条数据都和另一个表的所有数据匹配一次,用的比较少,因为存在重复数据。 + +结 果:两张表记录的乘积 + +处理:添加限制条件 + + + +**2.内连接查询数据** + +内连接(inner join on)查询可以帮助我们查找出两张表中有关联的数据,比如 学生表与班级表的联系 + +其实就是取两张表的交集。 + +![image-20240227155625868](.\imgs\1.png) + +内连接又分为:隐式【无join】和显式【有join】、等值连接和非等值连接、自连接。 + + + +**2.1.隐式【无join】和显示【有join】连接** + +1).隐式(无join)连接 + +隐式(无join)连接语法:select 字段/* from 表A, 表B where 消除笛卡尔积的连接条件; + +示例:查询对应的学生和班级信息 + +```sql +select * from student_info si,class_info ci where si.class_id = ci.id; +``` + +2.)显式(有join)连接: + + 显式(有join)连接语法:select 字段/* from 表A 别名 INNER(可以省略) JOIN 表B 别名 ON 消除笛卡尔积的连接条件; + +示例:查询对应的学生和班级信息 + +```sql +select * from student_info si INNER join class_info ci on si.class_id = ci.id; +``` + +```sql +select * from student_info si join class_info ci on si.class_id = ci.id; +``` + +注:inner 可省略 + + + +**2.2.等值连接与非等值连接** + +1).等值连接的最大的特点就是:条件是等量关系 + +等值连接语法:select 字段/* from 表1 **INNER(可以省略) JOIN** 表2 **ON** 消除笛卡尔积的连接条件A=B + +示例:查询对应的学生和班级信息 + +```sql +select * from student_info si,class_info ci where si.class_id = ci.id; +``` + + + +2).非等值连接的最大特点是:条件不是等量关系 + +非等值连接语法:select 字段/* from 表1 **INNER(可以省略) JOIN** 表2 **ON** 消除笛卡尔积的连接条件 **and 条件1** + +示例:根据班级ID在1-2之间对应的学生和班级信息 + +```sql +select * from student_info si,class_info ci where si.class_id = ci.id and si.class_id between 1 and 2; +``` + + + +**2.3.自连接** + +自连接的最大的特点:就是一张表看做两张表,自己连接自己 + +实质就是等值连接,只不过是连接表本身。 + +示例:查询学生id和班级id相同的学生 + +```sql +select si1.*,si2.class_id from student_info si1,student_info si2 where si1.id = si2.class_id; +``` + + + +**2.4.内连接语法** + +语法1: + +```sql +select * from 数据表1,数据表2 where +数据表1.关联字段 = 数据表2.关联字段 +数据表N.关联字段 = 数据表N.关联字段; +``` + +语法2: + +```sql +select * from 数据表1 inner join 数据表2 on +数据表1.关联字段 = 数据表2.关联字段 +... +[where 条件] + [group by 字段] + [having 条件] + [order by 字段] +``` + +其中: + +1. select 和from 是固定关键词,* 表示查询全部列的意思; + +2. 表名 表示从哪个表查询,还有 si 和 ci分别表示 student_info和class_info 两张表的缩写; + +3. inner join 是内连接查询的关键字,on 后面带 连接字段,**而inner 可以省略**; + + + +示例1:查出所有学生信息和对应的班级信息 + +```sql +select * from student_info si,class_info ci where si.class_id = ci.id; +``` + +```sql +select * from student_info si INNER JOIN class_info ci on si.class_id = ci.id; +``` + + + +示例2:查出学生编号为1的学生ID、姓名、年龄、班级名称和所学的课程名称、学分信息 + +```sql +select si.id,si.student_name,si.student_age,ci.class_name,ui.course_name,ui.course_credit from student_info si +inner JOIN class_info ci on si.class_id = ci.id +inner join class_course cc on ci.id = cc.class_id +inner join course_info ui on cc.course_id = ui.id where si.id = 1; +``` + + + +总结,内连接除了可以关联表查询,也可以加入条件查询,分组查询,排序查询。 + + + + + +**2.外连接查询数据** + +外连接查询其实就是查出有关联的数据,也查出不相关联的数据。 + +外连接包含 左外连接(Left join ... on)和右外连接(Right join ... on)。 + +**左外连接(Left join ... on)**:左表的数据在右表中没有匹配的,则在相关联的查询结果中,右表的所有选择列均为空值; + +![image-20240227155710642](.\imgs\2.png) + +语法: + +```sql +select * from 数据表1 left join 数据表2 on +数据表1.关联字段 = 数据表2.关联字段; +``` + + + +**右外连接(Right join ... on)**:右外连接是左外连接的反向连接,将返回右表中的所有行。如果右表的某行在左表中没有匹配数据,左表将返回空值。 + +![image-20240227155738940](.\imgs\3.png) + +```sql +select * from 数据表1 right join 数据表2 on +数据表1.关联字段 = 数据表2.关联字段; +``` + + + +示例1:查出所有学生,包括没有分配班级的学生及对应的班级信息 + +```sql +select * from student_info si left join class_info ci on si.class_id = ci.id; +``` + +![image-20240227155826625](.\imgs\4.png) + +示例2:查出所有学生,包括没有学生的班级信息 + +```sql +select * from student_info si right join class_info ci on si.class_id = ci.id; +``` + +![image-20240227155902593](.\imgs\5.png) + +8号学生没有数据 + +**3.复合条件连接查询** + +复合条件连接查询是在连接查询过程中,通过添加过滤条件,限制查询结果,使查询结果更加准确 + +语法: + +```sql +select * from 数据表1 inner join 数据表2 on +数据表1.关联字段名 = 数据表2.关联字段名 +inner join 数据表3 on +数据表2.关联字段名 = 数据表3.关联字段名 +inner join 数据表4 on +数据表1.关联字段名 = 数据表4.关联字段名 + +[where 条件] + [group by 字段] + [having 条件] + [order by 字段]; +``` + +```sql +select * from 数据表1 left join 数据表2 on +数据表1.关联字段名 = 数据表2.关联字段名 +... +[where 条件] + [group by 字段] + [having 条件] + [order by 字段]; +``` + +```sql +select * from 数据表1 right join 数据表2 on +数据表1.关联字段名 = 数据表2.关联字段名 +[where 条件] + [group by 字段] + [having 条件] + [order by 字段] + [limit 分页]; +``` + + + +示例1:使用inner join 查询学生班级信息中,学生id为1的数据 + +```sql +select * from student_info si inner JOIN class_info ci on si.class_id = ci.id where si.id = 1; +``` + +示例2:使用left join 查询学生班级信息中,学生id为1的数据 + +```sql +select * from student_info si left JOIN class_info ci on si.class_id = ci.id where si.id = 1; +``` + +示例3:使用right join 查询学生班级信息中,学生id为1的数据 + +```sql +select * from student_info si right JOIN class_info ci on si.class_id = ci.id where si.id = 1; +``` + + + +总结: + +从内连接->左(右)连接->外连接,数据范围逐步变大,实际开发中内连接和左连接使用的频率较多。 diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/2.\345\255\220\346\237\245\350\257\242.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/2.\345\255\220\346\237\245\350\257\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..ddd98f69905c85ef2125eb655c6a24d43195506f --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/2.\345\255\220\346\237\245\350\257\242.md" @@ -0,0 +1,304 @@ +# 子查询数据 + +### 本节目标: + +#### 1.子查询作为表 + +示例1:查询每门课程的最高分信息:课程编号、课程名称和最高分信息 + +#### 2.子查询作为列 + +示例1:查询学生的成绩信息:学生id,姓名,课程名称,成绩 + +#### 3.带比较运算符的子查询(<、<=、=、>、>=、!=) + +3.1带比较运算符的子查询 + +示例1:查询成绩比平均成绩低的成绩信息 + +示例2:查询选修课程数量与学号为1的选修课程数量一样多的其他学生的学号和姓名、选课数量 + +3.2带Having运算符的子查询 + +示例1:查询平均成绩大于总平均成绩的学生编号、姓名、平均成绩 + +#### 4.带in、not in关键字的子查询 + +in: + +示例1:查询所有班级,并查询出这些班级的学生信息 + +示例2:查询选修了课程编号为3和4的学生信息 + +not in: + +示例1:查询没有选修课程编号为3和4的学生信息 + +#### 5.带exists,not exists关键字的子查询 + +示例1:查询成绩表中有成绩的学生信息 + +示例2:查询成绩表中没有成绩的学生信息 + +#### 6.带all关键字的子查询 + +示例:查询出成绩比课程编号1的所有成绩都高的成绩信息 + +#### 7.带any、some关键字的子查询 + +示例:查询出成绩比课程编号1的任意一个成绩高的成绩信息 + + + + + + + + + + + + + + + + + + + + + + + +**相关概念** + +子查询是一个嵌套在 select、insert、update 或 delete 语句或其他子查询中的查询。任何允许使用表达式的地方都可以使用子查询。 + +一般子查询在select中使用的多,其他insert、update、detele用法类似。 + + + +**数据准备** + +首先,我们先插入测试数据,参考: + +``` +数据示例.sql +``` + + + +**1.子查询作为虚拟表** + +语法: + +```sql +select .. from (select .. from ..) '别名' +``` + +所有可以放表的位置,都可以使用子查询作为虚拟表 + +示例1:查询每门课程的最高分信息:课程名称和最高分信息 + +```sql +select ci.course_name,st.score from course_info ci +inner join (select +si.course_id as cid, +MAX(si.score) as score +from score_info si group by si.course_id) +st on ci.id = st.cid +; +``` + + + +**2.子查询作为列** + +语法: + +```sql +select 列1,(select...from...),列3 from ..... +``` + +示例1:查询学生的成绩信息:学生id,姓名,课程名称,成绩 + +语法1: + +```sql +select +si.id as '学生id', +si.student_name as '姓名', +ci.course_name as '课程名称', +ri.score '成绩' +from score_info ri +inner join student_info si on si.id = ri.student_id +inner join course_info ci on ci.id=ri.course_id; +``` + +语法2: + +```sql +SELECT +ri.student_id as '学生id', +(select si.student_name from student_info si where si.id = ri.student_id) as '姓名', +(select ci.course_name from course_info ci where ci.id = ri.course_id) as '课程名称', +score as '成绩' +from score_info ri; +``` + + + +**3.带比较运算符的子查询(<、<=、=、>、>=、<>)** + +3.1比较运算符连接条件 <、<=、=、>、>=、<> 子查询必须返回一行一列的值 + +示例1:查询成绩比平均成绩低的成绩信息 + +```sql +select * from score_info where score < (select avg(score) from score_info); +``` + +示例2:查询选修课程数量与学号为1的选修课程数量一样多的其他学生的学号和姓名、选课数量 + +```sql +select si.id,si.student_name,temp.cnt from student_info si INNER JOIN ( + +select student_id,count(course_id) cnt from score_info where student_id is not null group by student_id + +HAVING count(course_id) = (select count(course_id) from score_info where student_id = 1) ) temp + +on si.id = temp.student_id and si.id <> 1 +``` + +3.2:带Having运算符的子查询 + +示例1:查询平均成绩大于总平均成绩的学生编号、姓名、平均成绩 + +```sql +select si.id,si.student_name,temp.score from student_info si inner join ( +select student_id,avg(score) as score from score_info +where student_id is not null group by student_id HAVING score > (select avg(score) from score_info)) temp + +on si.id = temp.student_id; +``` + + + +**4.带in 、not in关键字的子查询** + +1)用in、not in关键字进行子查询时,内层查询语句只返回一个数据列,这个数据列里的值将提供给外层查询语句进行比较操作,in其实表示在这个结果集内的,not in表示不在这个结果集内的 + +语法: + +```sql +select * from 数据表1 where +数据表1.字段名 in / not in (select 字段名 from 数据表2 where 条件); +``` + +其中: + +1. in关键词,表示在什么值内的意思。not in 表示不在什么值内 +2. in、not in后面的select语句只能有一个数据列。 + + + +示例1:查询所有班级,并查询出这些班级的学生信息 + +第一步:可以先查询出所有的班级 + +```sql +select id from class_info; +``` + +第二步:直接in 结果集数据 + +```sql +select * from student_info si where si.class_id in (1,2,3,4); +``` + +其实也还可以这样查询: + +```sql +select * from student_info si where si.class_id in (select id from class_info); +``` + + + +示例2:查询选修了课程编号为3和4的学生信息 + +```sql +select * from student_info where id in +(select DISTINCT student_id from score_info where course_id in (3,4) and student_id is not null) +``` + +2)用not in关键字查询时,其实就是表示不在所查出来的结果集里的数据 + +示例:查询没有选修课程编号为3和4的学生信息 + +```sql +select * from student_info where id not in +(select DISTINCT student_id from score_info where course_id in (3,4) and student_id is not null) +``` + +思考:为什么in、not in后面的select语句只能有一列。 + +这个是因为in和not in关键字使用时,是把查询出来的数据提供给上层做为条件使用,条件只能是一种,不能有多个条件集。 + + + +**5.带exists,not exists关键字的子查询** + +示例1:查询成绩表中有成绩的学生信息 + +```sql +select * from student_info si where exists (select ri.student_id from score_info ri where ri.student_id = si.id); +``` + +示例2:查询成绩表中没有成绩的学生信息 + +```sql +select * from student_info si where not exists (select ri.student_id from score_info ri where ri.student_id = si.id); +``` + + + +**6.带all关键字的子查询** + +all关键字的子查询是和返回的所有值进行比较,若为true,则返回数据 + + + +示例:查询出成绩比课程编号1的所有成绩都高的成绩信息 + +```sql +select * from score_info where score > all(select score from score_info where course_id = 1); +``` + +注:子查询出来的数据中不能包含空的数据,如果说存在空数据,则不能使用 all这个关键字,可以使用以下语法进行查询 + +```sql +select * from score_info where score > (select max(score) from score_info where course_id = 1); +``` + + + +**7.带any、some关键字的子查询** + +any、some关键字含义一样,就是和子查询返回的某个值比较,若为true,则返回数据 + +示例:查询出成绩比课程编号1的任意一个成绩高的成绩信息 + +```sql +select * from score_info where score > any(select score from score_info where course_id = 1); +``` + +```sql +select * from score_info where score > some(select score from score_info where course_id = 1); +``` + +或者 + +```sql +select * from score_info where score > (select min(score) from score_info where course_id = 1); +``` + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/3.\345\210\206\351\241\265\346\237\245\350\257\242.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/3.\345\210\206\351\241\265\346\237\245\350\257\242.md" new file mode 100644 index 0000000000000000000000000000000000000000..ca30e42e8e0c190fc53e171cae3723135d2a1955 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/3.\345\210\206\351\241\265\346\237\245\350\257\242.md" @@ -0,0 +1,79 @@ +# 分页查询数据 + +### 本节目标: + +熟悉limit关键字分页查询 + + + +**相关概念** + +Mysql 数据库中limit子句可以被用于强制select语句返回指定的记录数。limit接受一个或两个数字参数。参数必须是一个整数常量。如果给定两个参数,第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最大数目;若果给定一个参数,则表示返回记录行的最大数目。 + + + +**1.数据准备** + +首先,我们先插入测试数据,参考: + +``` +数据示例.sql +``` + + + +**2.分页查询** + +关键字:limit + +语法: + +```sql +select * from 数据表名 limit [offset,] rows; +``` + +其中: + +```sql +offset:指定第一个返回记录行的偏移量(即从哪一行开始返回)(offset偏移量是从offset+1开始)。 +rows:返回具体行数。 +注意:初始行的偏移量为0。 +``` + +示例1:从第3条开始,查询3条学生数据(offset偏移量是从offset+1开始) + +```sql +select * from student_info limit 2,3; +``` + +示例2:从第一条开始取5条数据(只有一个参数rows) + +```sql +select * from student_info limit 5; +``` + +**3.实现分页功能** + +示例:查询第1页,每页设置2条 + +```sql +select * from student_info limit 0, 2; +``` + +示例:查询第2页,每页设置2条 + +```sql +select * from student_info limit 2, 2; +``` + +总结规律: + +查询第1页数据,这个offset的值为0,第二页值为2,那第三页值就为4,... + +所以offset这个值根据规律可以得出:(当前页-1)*每页显示条数; + +分页语法: + +```sql +select * from student_info limit (当前页-1)*每页显示条数, 每页显示条数; +``` diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/4.\347\273\203\344\271\240\351\242\230.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/4.\347\273\203\344\271\240\351\242\230.md" new file mode 100644 index 0000000000000000000000000000000000000000..421bce90ed14062fe6959ed3f99a9b5cfd99fb78 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/4.\347\273\203\344\271\240\351\242\230.md" @@ -0,0 +1,46 @@ +# 练习题 + +1.查询所有学生和对应的班级信息; + +2.查询学生ID为1的班级课程信息,展示学生ID、学生姓名、班级名称、课程名称、课程学分; + +3.使用左连接,查询学生及对应的班级信息; + +4.使用右连接,查询学生及对应的班级信息; + +5.查询课程和课程类别信息; + +6.查询学生信息及对应的成绩信息; + +7.查询班级信息及班级对应的课程信息,包含班级id、班级名称、课程名称、课程学分; + +8.使用in 查询所有班级,并查询出这些班级的学生信息; + +9.使用not in 查询所有班级,并查询出这些不在 1,2,3班的学生信息; + +10.使用 exists 查询成绩表中有成绩的学生信息; + +11.使用 not exists 查询成绩表中有成绩的学生信息; + +12.查询成绩比平均成绩低的成绩信息; + +13.查询成绩不等于60分的成绩信息; + +14.查询成绩大于等于60分的成绩信息; + +15.查询成绩大于60分的成绩信息; + +16.查询成绩等于60分的成绩信息; + +17.查询成绩小于等于60分的成绩信息; + +18.查询成绩小于60分的成绩信息; + +19.使用all关键字查询出成绩比课程编号1的所有成绩都高的成绩信息; + +20.使用any或some关键字查询出成绩比课程编号1的任意一个成绩高的成绩信息; + +21.查询学生的成绩信息:成绩编号,姓名,课程名称,成绩; + +22.查询每门课程的最高分信息:课程名称和最高分信息; + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/1.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..4cd83811f715ce23dc4990f02c6f42cf7ad46257 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/1.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/2.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..85ff081da2a094efa095453301f35298fd8b2714 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/2.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/3.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..f9f736b7d2ee072503a4a412357c369f1849e5cf Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/3.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/4.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..06e6fd334902a22d55821fdd3896d1d64dcb1b1e Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/4.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/5.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..5a5c1417fff8912d66551469dd9e2a0961deec4c Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/imgs/5.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/\346\225\260\346\215\256\347\244\272\344\276\213/\346\225\260\346\215\256\347\244\272\344\276\213.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/\346\225\260\346\215\256\347\244\272\344\276\213/\346\225\260\346\215\256\347\244\272\344\276\213.sql" new file mode 100644 index 0000000000000000000000000000000000000000..747c1e3a7018a828c46c5c6fc2c5de2f257e25fc --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/4_\350\277\233\351\230\266\346\237\245\350\257\242/\346\225\260\346\215\256\347\244\272\344\276\213/\346\225\260\346\215\256\347\244\272\344\276\213.sql" @@ -0,0 +1,209 @@ +create database if not exists student; + +use student; + +drop table if exists student_info; +drop table if exists class_info; +drop table if exists course_info; +drop table if exists class_course; +drop table if exists score_info; +drop table if exists course_type; + + +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table if not exists class_info ( + id int(11) primary key auto_increment not null, + class_name varchar(255) not null +); + +-- 创建学生表,存储学生信息,其中字段包括:学生id、姓名、性别、年龄、生日、家庭住址,所属班级id +create table if not exists student_info ( + id int(11) primary key auto_increment NOT NULL, + student_name varchar(255) , + student_sex tinyint(1) NOT NULL, + student_age varchar(255) default 0, + student_time datetime(0) , + student_address varchar(255) , + class_id int(11), + FOREIGN KEY (class_id) REFERENCES class_info(id) +); + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table if not exists course_info ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) , + course_credit int(10) NOT NULL, + ctype_id int(11) +); + +-- 创建课程类型表,存储课程类型信息,其中字段包含:课程id、课程名称、课程类型 +create table if not exists course_type ( + id int(11) primary key auto_increment NOT NULL, + course_name varchar(255) +); + +-- 创建班级课程表,存储班级课程信息,其中字段包含:id、班级id、课程id +create table if not exists class_course ( + id int(11) primary key auto_increment NOT NULL, + class_id int(11) , + course_id int(11) +); + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table if not exists score_info ( + id int(11) primary key auto_increment NOT NULL, + student_id int(11) , + course_id int(11) , + score int(3) +); + +-- 一共有三个班级 +INSERT INTO `class_info`(`id`, `class_name`) VALUES (1, '软件技术1班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (2, '软件技术2班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (3, '软件技术3班'); +INSERT INTO `class_info`(`id`, `class_name`) VALUES (4, '软件技术4班'); + +-- 一共有8个同学 +-- 其中,软件技术1班有3个同学,软件技术2班有2个同学,软件技术3班、4班各有1个同学 + +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (1, '刘小东', 1, '24', '2000-01-01 00:00:00', '广西省桂林市七星区空明西路10号鸾东小区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (2, '黄龙辉', 1, '25', '1999-03-20 00:00:00', '江西省南昌市青山湖区艾溪湖南路南150米广阳小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (3, '陈丽', 2, '24', '2000-07-08 00:00:00', '福建省龙岩市新罗区曹溪街道万达小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (4, '林小松', 1, '22', '2002-03-09 00:00:00', '云南省昆明市五华区华山街道华山小区', 1); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (5, '舒燕', 2, '22', '2002-07-09 00:00:00', '福建省龙岩市新罗区万宝社区', 2); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (6, '王海欣', 2, '22', '2002-09-09 00:00:00', '福建省龙岩市新罗区东肖社区', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (7, '吴韦林', 1, '24', '2000-06-09 00:00:00', '福建省厦门市湖里区禾山街道围里社', 3); +INSERT INTO `student_info`(`id`, `student_name`, `student_sex`, `student_age`, `student_time`, `student_address`, `class_id`) VALUES (8, '欧阳武', 1, '20', '2004-07-15 00:00:00', '陕西省西安市雁塔区雁塔社区',2); + + + +-- 学院开设4门课程 +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (1, '数据库高级应用', 3, 1); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (2, 'javascript编程基础', 3, 2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (3, 'web前端程序设计基础', 4, 2); +INSERT INTO `course_info`(`id`, `course_name`, `course_credit`, `ctype_id`) VALUES (4, '动态网页设计.net基础', 6, 2); + +-- 新增课程类别数据 +INSERT INTO `course_type`(`id`, `course_name`) VALUES (1, '数据库'); +INSERT INTO `course_type`(`id`, `course_name`) VALUES (2, '计算机语言'); + +-- 软件技术1班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术2班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + + +-- 软件技术3班开设课程,课程名称和学分分别为 +-- 数据库高级应用、3 +-- javascript编程基础、3 +-- web前端程序设计基础、4 +-- 动态网页设计.net基础、6 + +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (1, 1, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (2, 1, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (3, 1, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (4, 1, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (5, 2, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (6, 2, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (7, 2, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (8, 2, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (9, 3, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (10, 3, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (11, 3, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (12, 3, 4); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (13, 4, 1); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (14, 4, 2); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (15, 4, 3); +INSERT INTO `class_course`(`id`, `class_id`, `course_id`) VALUES (16, 4, 4); + + +-- 考试完成后,各学生各课程得分: +-- 刘小东、数据库高级应用、80 +-- 刘小东、javascript编程基础、78 +-- 刘小东、web前端程序设计基础、65 +-- 刘小东、动态网页设计.net基础、90 + +-- 黄龙辉、数据库高级应用、60 +-- 黄龙辉、javascript编程基础、77 +-- 黄龙辉、web前端程序设计基础、68 +-- 黄龙辉、动态网页设计.net基础、88 + +-- 陈丽、数据库高级应用、88 +-- 陈丽、javascript编程基础、45 +-- 陈丽、web前端程序设计基础、61 +-- 陈丽、动态网页设计.net基础、75 + +-- 林小松、数据库高级应用、80 +-- 林小松、javascript编程基础、78 +-- 林小松、web前端程序设计基础、65 +-- 林小松、动态网页设计.net基础、90 + +-- 舒燕、数据库高级应用、60 +-- 舒燕、javascript编程基础、77 +-- 舒燕、web前端程序设计基础、68 +-- 舒燕、动态网页设计.net基础、88 + +-- 王海欣、数据库高级应用、88 +-- 王海欣、javascript编程基础、45 +-- 王海欣、web前端程序设计基础、66 +-- 王海欣、动态网页设计.net基础、75 + +-- 吴韦林、数据库高级应用、88 +-- 吴韦林、javascript编程基础、48 +-- 吴韦林、web前端程序设计基础、69 +-- 吴韦林、动态网页设计.net基础、51 + +-- 欧阳武、数据库高级应用、90 +-- 欧阳武、javascript编程基础、56 +-- 欧阳武、web前端程序设计基础、82 +-- 欧阳武、动态网页设计.net基础、67 + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (1, 1, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (2, 1, 2, 78); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (3, 1, 3, 65); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (4, 1, 4, 90); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (5, 2, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (6, 2, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (7, 2, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (8, 2, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (9, 3, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (10, 3, 2, 45); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (11, 3, 3, 61); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (12, 3, 4, 75); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (13, 4, 1, 80); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (14, 4, 2, 78); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (17, 5, 1, 60); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (18, 5, 2, 77); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (19, 5, 3, 68); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (20, 5, 4, 88); + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (21, 6, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (22, 6, 2, 45); + + +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (25, 7, 1, 88); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (26, 7, 2, 48); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (27, 7, 3, 69); +INSERT INTO `score_info`(`id`, `student_id`, `course_id`, `score`) VALUES (28, 7, 4, 51); + +INSERT INTO `score_info`(`id`, `course_id`) VALUES (29, 1); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (30, 2); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (31, 3); +INSERT INTO `score_info`(`id`, `course_id`) VALUES (32, 4); + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/1.\351\233\206\345\220\210\345\207\275\346\225\260.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/1.\351\233\206\345\220\210\345\207\275\346\225\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..8c779444dfd10fd0479e3be6fac65f71042e449d --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/1.\351\233\206\345\220\210\345\207\275\346\225\260.md" @@ -0,0 +1,62 @@ +# 集合函数 + +### 本节目标: + +了解集合函数union和union all + + + +**1.集合函数使用** + +1)union函数 + +MySQL Union 允许我们将来自多个 SELECT 查询的两个或多个结果组合成一个结果集。它带有一个默认功能,可以从结果集中**删除重复行**。MySQL 总是使用第一个 SELECT 语句中的列名将作为结果集(输出)的列名。 + +语法: + +```sql +select 字段1,字段2,字段3 from 表1 +union +select 字段1,字段2,字段3 from 表2 +where 条件; +``` + +2)union all函数 + +MySQL Union all 函数对两个结果集进行并集操作,**包括重复行**,不进行排序; 如果返回的两个结果集中有重复的数据,那么返回的结果集就会包含重复的数据了。 + +语法: + +```sql +select 字段1,字段2,字段3 from 表1 +union all +select 字段1,字段2,字段3 from 表2 +where 条件; +``` + + + +union 和 union all 函数必须遵循以下基本规则: + +- 在您要使用的所有表中,列的数量和顺序应该相同。 +- 数据类型必须与每个选择查询的相应位置兼容。 +- 在不同的 SELECT 查询中选择的列名必须具有相同的顺序。 + + + +示例:使用union 函数查询课程类型表和课程表的集合数据 + +```sql +select ct.id,ct.course_name from course_type ct +union +select cf.id,cf.course_name from course_info cf; +``` + +示例2:使用union all函数查询课程类型表和课程表的集合数据 + +```sql +select ct.id,ct.course_name from course_type ct +union all +select cf.id,cf.course_name from course_info cf; +``` + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/2.\346\227\245\346\234\237\345\207\275\346\225\260.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/2.\346\227\245\346\234\237\345\207\275\346\225\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..42562c6765f4e9aa6afadf5ba0f4b5660ea7b7c0 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/2.\346\227\245\346\234\237\345\207\275\346\225\260.md" @@ -0,0 +1,89 @@ +# 日期函数 + +### 本节目标: + +了解日期函数 + + + +**1.获取时间** + +1)获取当前日期时间 + +select NOW(); + +2)获取当前日期 + +SELECT CURDATE(); + +3)获取当前时间 + +SELECT CURTIME(); + +4)获取日期的时间戳 + +SELECT unix_timestamp(now()); + +5)根据时间戳(10位)返回日期 + +SELECT FROM_UNIXTIME(1712026448); + +带日期格式化: + +SELECT FROM_UNIXTIME(1712026448,'%Y-%m-%d') + +5)对于时间2024-02-27 09:25:29,分别获取其年、月、日、时、分、秒 + +SELECT EXTRACT(YEAR FROM NOW()); +SELECT EXTRACT(MONTH FROM NOW()); +SELECT EXTRACT(DAY FROM NOW()); +SELECT EXTRACT(HOUR FROM NOW()); +SELECT EXTRACT(MINUTE FROM NOW()); +SELECT EXTRACT(SECOND FROM NOW()); + +或者从日期格式字符串中获取 + +SELECT EXTRACT(SECOND FROM '2024-02-27 09:25:29'); + + + +**2.日期增加、减少** + +1)时间减少1小时(前一小时) + +select date_sub(now(), INTERVAL 1 hour); + +2)日期增加1天 + +select date_add(now(), INTERVAL 1 day); + +3)其他间隔 + +INTERVAL 1 YEAR +INTERVAL 1 MONTH +INTERVAL 1 DAY +INTERVAL 1 HOUR +INTERVAL 1 MINUTE +INTERVAL 1 SECOND + + + +**3.日期格式化、字符串转日期** + +1)格式化参考: + +select DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s'); +select DATE_FORMAT(now(),'%Y-%m-%d %H:00:00'); + +2)字符串转日期 +select str_to_date('2024-02-27 10:37:14', '%Y-%m-%d %H:%i:%s'); + + + +**4.其它日期函数** + +![image-20240402105651293](.\imgs\1.png) + + + +[MySQL日期函数_mysql 日期函数-CSDN博客](https://blog.csdn.net/qq_43501821/article/details/123963305) diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/imgs/1.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/imgs/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..159b221ae79f7711df2be233e4ce66949906dc64 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/imgs/1.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/\351\233\206\345\220\210\345\207\275\346\225\260.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/\351\233\206\345\220\210\345\207\275\346\225\260.sql" new file mode 100644 index 0000000000000000000000000000000000000000..c2281bc4c2eef1d87146b9fce6ec628823ea8b41 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/5_\346\211\251\345\261\225/\351\233\206\345\220\210\345\207\275\346\225\260.sql" @@ -0,0 +1,21 @@ +create database if not exists classdb; + +use classdb; + +drop table if exists student1; + +drop table if exists student2; + +create table if not exists student1( + id int(11) primary key auto_increment NOT NULL, + st_name varchar(255) +); + +create table if not exists student2( + id int(11) primary key auto_increment NOT NULL, + st_name varchar(255) + +); + +insert into student1(id,st_name)values(1,'张三'),(2,'李四'); +insert into student2(id,st_name)values(1,'张三'),(2,'王五'); \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/1.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..ac76cd6c7b5a17d4dda0b63478d4614e2981f63a Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/1.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/2.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..97ad330ac51323948800f8249eaee79aba182cf7 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/2.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/3.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..74085601ac2ce0691a33563e153edc5b04e3c6d5 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/3.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/4.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..328f04e68b6c6a88245c7bb4c8a74410b9c5e1de Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/4.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/5.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..689f9f92d3076fcbecd721710888fec3da09294c Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/5.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/6.png" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/6.png" new file mode 100644 index 0000000000000000000000000000000000000000..9b2f014195e8e326798e6c6838acf4c4bcb29e4a Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/imgs/6.png" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262.md" new file mode 100644 index 0000000000000000000000000000000000000000..d455916ba879bc99730eb47525f7483acc9420fe --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/6_\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262/\346\225\260\346\215\256\345\272\223\347\232\204\345\217\221\345\261\225\345\217\262.md" @@ -0,0 +1,123 @@ +## 数据库的发展史 + +**数据库的发展史** + +1. 文件系统:使用磁盘文件来存储数据 +2. 第一代数据库:出现了网状模型、层次模型的数据库 +3. 第二代数据库:关系型数据库 +4. 现在关系数据库为主流,各种不同数据库不断发展 + +目前市面最常的数据库分为关系型数据库和非关系型数据库。 + +**1.穿孔纸袋和文件系统** + +在现代意义的数据库出现之前(20世纪60年代),人们通过人工和文件系统的方式来存储、管理数据。在人工管理时期,人们常使用穿孔纸带来管理数据(图2),虽然穿孔纸带因不具备电子化特征、不能被称为数据库,但其代表着人们在数据存储结构上思考和实践的结果,有必要单独提及。 + +![image-20240312085119910](.\imgs\1.png) + +​ 穿孔纸带 + +随着数据量的增多以及计算机技术、存储技术的快速发展,穿孔纸带这一纸质存储媒介很快就被磁盘、磁鼓(图3)等磁性存储设备所取代。在软件方面,操作系统中也出现了专门管理数据的软件,被称为文件系统(例如我们电脑里的C,D,E盘)。 + +文件系统可以说是最早的数据库了,操作系统提供的文件管理方法使得程序可以通过文件名来访问文件中的数据,不必再寻找数据的物理位置。相比较手工处理的方式,文件系统使得管理数据变得简单一些,使用者不需要再翻来覆去的查找文件位置,但是文件内的数据仍然没有组织起来,程序员需要在脑海中尝试构造出数据与数据的关系,再编写代码才能从文件中提取关键数据。除过数据结构和数据关系不完整的问题外,此时的数据只面向某个应用或者某个程序,数据的共享性也有着一定的问题。 + +![image-20240312085259034](.\imgs\2.png) + +​ 磁鼓(长12英寸,每节可存储不到10k数据) + +随着数据量的增长以及企业对数据共享的要求越来越高,人们开始提出数据库管理系统(Database Management System, DBMS)的概念,对数据模型展开了更深层次的思考。 + + + +**2.数据模型** + +之前主要是分为:层次模型与网状模型、关系型模型 + +层次模型: + +层次数据模型是用树状<层次>结构来组织数据的数据模型 + +![image-20240312091941516](.\imgs\4.png) + +网状模型: + +用有向图表示实体和实体之间的联系的数据结构模型称为网状数据模型 + + + +![image-20240312091755893](.\imgs\3.png) + +关系模型: + +使用表格表示实体和实体之间关系的数据模型称之为关系数据模型。 + + + +![image-20240312092846466](.\imgs\5.png) + +**3.数据库技术的发展** + +随着互联网的普及,数据库使用环境也随之发生变化,这种变化主要体现为XML和Java技术的大量使用、要求支持各种互联网环境下的应用服务器、极容易出现大量用户同时访问数据库、要求支持7x24小时不间断运行和高安全性等。[2] + +为解决由于这些变化所带来的新问题,数据库管理系统也逐渐产生变化,包括: + +(一)网络化的大型通用数据库管理系统的出现 + +由于互联网应用的用户数量无法预测,这就要求数据库相比以前拥有能处理更大量的数据以及为更多的用户提供服务的能力,即更好的可伸缩性及高可用性。 + +因此,能够支持Internet的数据库应用已经成为数据库系统的重要方面,学术界及各主流数据库公司都将大型通用数据管理系统作为主要发展方向。 + +例如Oracle公司从 8 版起全面支持互联网应用,微软公司更是将 SQL Server 作为 其整个 .NET计划中的一个重要的成分。 + +(二)数据库安全系统及技术的提升 + +由于数据库系统在现代计算机系统中的地位越来越趋于核心的地位,数据库系统的安全问题自然受到越来越多的关注。 + +在目前各国所引用或制定的 一系列安全标准中,最重要的两个是由美国国防部制定的《可信计算机系统的评估标准》(简称TCSEC)和《可信计算机系统的评估标准关于可信数据库系统的解释》(简称 TDI)。 + +目前,所有数据库的开发必须遵从相应的安全标准。 + +(三)XML及Web数据管理技术的普及 + +随着越来越多的Web应用,如电子商务、数字图书馆、信息服务等采用XML作为数据表现形式、越来越多网站采用XML作为信息发布的语言,以XML格式数据为主的半结构化数据逐步成为网上数据交换和数据表示的标准。 + +而XML具有如下的一些特征: + + + 1. 面向显示 + 2. 半结构化和无结构 + 3. 不同形式的数据源 + 4. 动态变化以及数据海量等。 + +因此,支持这种结构松散、形式多样、动态变化的海量数据的存储、共享、管理、检索,成了数据库技术的大势所趋。 + +Web数据管理是一个很松散的概念,大体上它是指在Web环境下对各种复杂信息的有效组织与集成,进行方便而准确的信息查询和发布。 + +当前Web数据管理的研究开发方向主要包括:半结构化数据管理、Web数据查询、Web信息集成、XML数据管理等。 + +到目前为止,XML 与 Web 数据管理的研究工作中主要集中在如下的一些方面: + +1. 半结构化数据 +2. Web 数据查询 +3. XML 相关标准 +4. XML 数据管理 + +(四)嵌入式移动数据库技术 + +随着移动通信技术的迅速发展和投入使用,加上移动智能电话、移动计算机的大量普及,国内外许多研究机构都展开了对移动数据库的研究,并获取了许多有价值的成果。 + +移动数据库技术涉及数据库技术、分布式计算技术以及移动通信技术等多个学科领域,具有较高的学术起点。 + +![v2-985097694a5ba60b5adedb3be321ca8a_r](.\imgs\6.png) + +**4.未来展望** + +大数据时代,数据量不断爆炸式增长,数据存储结构也越来越灵活多样,日益变革的新兴业务需求催生数据库及应用系统的存在形式愈发丰富,这些变化均对数据库的各类能力不断提出挑战,推动数据库的不断演进。总的来说可能会有四个方向: + +第一个方向是垂直领域的数据库,例如工业数据库、财经数据库等。截止目前为止,数据库都是“通才“,企图囊括所有领域,而并非深耕某一垂直领域。 + +第二个方向是分布式数据库,通过“分布式”解决水平扩展性与容灾高可用两个问题,并且有融合OLAP的潜力。 + +第三个方向是云原生数据库,云原生数据库能够随时随地从多前端访问,提供云服务的计算节点,并且能够灵活及时调动资源进行扩缩容,助力企业降本增效。以亚马逊AWS、阿里云、Snowflake等为代表的企业,开创了云原生数据库时代。 + +第四个方向是数据安全领域,在如今这样一个什么都可以量化的年代,数据是很多企业的生命线,而第三方服务商并非真正中立,谁愿意自己的命根被掌握在别人手里呢?在未来,隐私计算和区块链技术可能会帮助数据库发展的更好,共同解决数据安全的问题。 \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\346\225\260\346\215\256\350\241\250.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\346\225\260\346\215\256\350\241\250.sql" new file mode 100644 index 0000000000000000000000000000000000000000..013d699d7d5a63ad89be9af1827081cc5fc40ad3 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\346\225\260\346\215\256\350\241\250.sql" @@ -0,0 +1,88 @@ +CREATE DATABASE if not exists Student_Manager; + +use Student_Manager; + +drop table if exists Student; +drop table if exists Course; +drop table if exists Teacher; +drop table if exists Score; + +-- 创建学生表 +CREATE TABLE Student +( +s_id VARCHAR(20), +s_name VARCHAR(20) NOT NULL, +s_birth VARCHAR(20) NOT NULL, +s_sex VARCHAR(10) NOT NULL, +PRIMARY KEY(s_id) +); + + + +-- 创建课程表 +CREATE TABLE Course +( +c_id VARCHAR(20), +c_name VARCHAR(20) NOT NULL, +t_id VARCHAR(20) NOT NULL, +PRIMARY KEY(c_id) +); + +-- 创建教师表 +CREATE TABLE Teacher +( +t_id VARCHAR(20), +t_name VARCHAR(20) NOT NULL DEFAULT '', +PRIMARY KEY(t_id) +); + +-- 创建成绩表 (联合主键) +CREATE TABLE Score +( +s_id VARCHAR(20), +c_id VARCHAR(20), +s_score INT(3), +PRIMARY KEY(s_id, c_id) +); + +-- 插入学生表测试数据 +INSERT INTO Student VALUES('01', '赵雷', '1990-01-01', '男'); +INSERT INTO Student VALUES('02', '钱电', '1990-12-21', '男'); +INSERT INTO Student VALUES('03', '孙风', '1990-05-20', '男'); +INSERT INTO Student VALUES('04', '李云', '1990-08-06', '男'); +INSERT INTO Student VALUES('05', '周梅', '1991-12-01', '女'); +INSERT INTO Student VALUES('06', '吴兰', '1992-03-01', '女'); +INSERT INTO Student VALUES('07', '郑竹', '1989-07-01', '女'); +INSERT INTO Student VALUES('08', '王菊', '1990-01-20', '女'); + + +-- 课程表测试数据 +INSERT INTO Course VALUES('01', '语文', '02'); +INSERT INTO Course VALUES('02', '数学', '01'); +INSERT INTO Course VALUES('03', '英语', '03'); + +-- 教师表测试数据 +INSERT INTO Teacher VALUES('01', '张三'); +INSERT INTO Teacher VALUES('02', '李四'); +INSERT INTO Teacher VALUES('03', '王五'); + +-- 成绩表测试数据 +INSERT INTO Score VALUES('01', '01', 80); +INSERT INTO Score VALUES('01', '02', 90); +INSERT INTO Score VALUES('01', '03', 99); +INSERT INTO Score VALUES('02', '01', 70); +INSERT INTO Score VALUES('02', '02', 60); +INSERT INTO Score VALUES('02', '03', 80); +INSERT INTO Score VALUES('03', '01', 80); +INSERT INTO Score VALUES('03', '02', 80); +INSERT INTO Score VALUES('03', '03', 80); +INSERT INTO Score VALUES('04', '01', 50); +INSERT INTO Score VALUES('04', '02', 30); +INSERT INTO Score VALUES('04', '03', 20); +INSERT INTO Score VALUES('05', '01', 76); +INSERT INTO Score VALUES('05', '02', 87); +INSERT INTO Score VALUES('06', '01', 31); +INSERT INTO Score VALUES('06', '03', 34); +INSERT INTO Score VALUES('07', '02', 89); +INSERT INTO Score VALUES('07', '03', 98); + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\351\242\230\347\233\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\351\242\230\347\233\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..82b2e35cfb7028f025b9fb56c846f247a0d1e144 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/50\351\242\230SQL\347\273\203\344\271\240\351\242\230/50\351\242\230\351\242\230\347\233\256.md" @@ -0,0 +1,107 @@ +**练习题** + +1.查询课程编号为01的课程比02的课程成绩高的所有学生的学号和成绩; + +2.查询平均成绩大于60分的学生的学号和平均成绩; + +3.查询所有成绩小于60分的学生信息; + +4.查询平均成绩小于60分的学生的学号和平均成绩,考虑没参加考试的情况; + +5.查询所有学生的学号、姓名、选课数、总成绩; + +6.查询姓"猴"的老师的个数; + +7.查询没学过"张三"老师课的学生的学号、姓名; + +8.查询学过"张三"老师所教的所有课的同学的学号、姓名; + +9.查询学过编号为'01'的课程并且也学过编号为'02'的课程的学生的学号、姓名; + +10.查询学过编号为'01'的课程但没有学过编号为'02'的课程的学生的学号、姓名; + +11.查询课程编号为'02'的总成绩; + +12.查询所有课程成绩小于60分的学生的学号、姓名; + +13.查询没有学全所有课的学生的学号、姓名; + +14.查询至少有一门课与学号为'01'的学生所学课程相同的学生的学号、姓名; + +15.查询和'01'号同学所学课程完全相同的其他同学的学号; + +16.查询没学过'张三'老师讲授的任一门课程的学生姓名; + +17.查询两门及其以上不及格课程的同学的学号、姓名及其平均成绩; + +18.查询'01'课程分数小于60,按分数降序排列的学生信息; + +19.按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩; + +20.查询各科成绩最高分、最低分和平均分:以如下形式显示: + +– 课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率 +– (及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90) (!!) + +; + +21.按各科成绩进行排序,并显示排名; + +22.查询学生的总成绩并进行排名; + +23.查询不同老师所教不同课程平均分从高到低显示; + +24.查询所有课程的成绩第2名到第3名的学生信息及该课程成绩; + +25.使用分段[100-85],[85-70],[70-60],[<60]来统计各科成绩,分别统计各分数段人数:课程ID和课程名称; + +26.查询学生平均成绩及其名次; + +27.查询各科成绩前三名的记录; + +28.查询每门课程被选修的记录数; + +29.查询出只有两门课程的全部学生的学号和姓名; + +30.查询男生、女生人数; + +31.查询1990年出生的学生名单; + +32.查询平均成绩大于等于85的所有学生的学号、姓名和平均成绩; + +33.查询每门课程的平均成绩,结果按平均成绩升序排序,平均成绩相同时,按课程号降序排序; + +34.查询课程名称为"数学",且分数低于60的学生姓名和分数; + +35.查询所有学生的课程及分数情况(存在学生没成绩,没选课的情况); + +36.查询任何一门课程成绩在70分以上的姓名、课程名称和分数; + +37.查询学生不及格的课程并按课程号从大到小排列; + +38.查询课程编号为03且课程成绩在80分以上的学生的学号和姓名; + +39.求每门课程的学生人数; + +40.查询选修"张三"老师所授课程的学生中成绩最高的学生姓名及其成绩; + +41.查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩; + +42.查询每门课程成绩最好的前两名学生信息; + +43.统计每门课程的学生选修人数(超过5人的课程才统计); + +44.检索至少选修两门课程的学生学号; + +45.查询选修了全部课程的学生信息; + +46.查询各学生的年龄(精确到月份); + +47.查询没学过“张三”老师讲授的任一门课程的学生姓名; + +48.查询两门以上不及格课程的同学; + +49.查询本月过生日的学生; + +50.查询本周过生日的学生; + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\350\204\232\346\234\254.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\350\204\232\346\234\254.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b20a53be2c7741672e35f5fe1d90b39f595c423f --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\350\204\232\346\234\254.sql" @@ -0,0 +1,40 @@ +-- 删除数据库 +drop database if exists company; + +-- 创建公司数据库 +create database if not exists company; + +-- 使用该数据库 +use company; + +-- 创建员工表 +create table if not exists staff_info ( + id int(11) primary key, + staff_name varchar(255), + staff_age int(2), + staff_sex int(1), + staff_phone varchar(11), + staff_email varchar(255), + staff_address varchar(255), + staff_brtime datetime(0), + staff_time datetime(0), + dept_id int(11) +); + +-- 插入员工数据 +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_email,staff_address,staff_brtime,staff_time,dept_id) values +(1,'张三',23,1,'15103021550','12313@qq.com','福建省厦门市集美区','2001-01-02','2011-02-03 08:23:35',1), +(2,'李四',21,1,'15803021550','52353@qq.com','福建省泉州市泉港区','2003-03-04','2013-05-18 12:50:01',2), +(3,'王丽',43,2,'15105021500','17810@qq.com','福建省福州市马尾区','1981-07-13','2017-08-03 01:31:50',3), +(4,'徐艳',29,2,'18103021732','98003@qq.com','广东省广州市白云区','1995-08-08','2013-11-20 09:10:11',3), +(5,'欧阳琳',28,2,'19103022380','12213@qq.com','云南省丽江市古城区','1996-05-23','2009-11-10 17:32:35',2), +(6,'徐真',25,1,'15003227850','12388@qq.com','广西壮族自治区桂林市秀峰区','1999-01-02','2013-02-25 08:23:35',1), +(7,'王鑫路',36,1,'15903121600','52360@qq.com','河南省周口西华县','1988-03-04','2017-06-18 12:50:01',2), +(8,'劳拉',32,2,'17308821533','17819@qq.com','福建省龙岩市永定区','1992-07-13','2015-05-19 01:31:50',1), +(9,'田雨',32,2,'18013121755','98013@qq.com','浙江省杭州市西湖区','1992-08-08','2022-10-21 09:10:11',1) +; + +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_address,staff_brtime,staff_time,dept_id) values +(10,'爱新觉罗·吉吉',35,2,'13588025381','内蒙古自治区呼和浩特市新城区','1989-05-23','2008-09-11 17:32:35',2); \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\351\242\230\347\233\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\351\242\230\347\233\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..0f1de06b83948e562b5bce104a9001e904a696cd --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/12\351\242\230\347\256\200\345\215\225SQL\347\273\203\344\271\240\351\242\230/12\351\242\230SQL\347\273\203\344\271\240\351\242\230\347\233\256.md" @@ -0,0 +1,26 @@ +-- 1.查询所有的员工信息 + +-- 2.查询所有员工的员工姓名、年龄、手机号码、地址信息 + +-- 3.查询所有员工的员工姓名、年龄、手机号码、地址信息,使用字段别名进行查询 + +-- 4.查询员工年龄等于25岁的员工信息 + +-- 5.查询员工部门不是1的员工信息 + +-- 6.查询员工年龄大于20岁的员工信息 + +-- 7.查询员工年龄在20岁和35岁之间的员工信息 + +-- 8.查询员工信息中,没有邮箱信息的员工 + +-- 9.查询员工信息中,有邮箱信息的员工的姓名、年龄、手机号码、邮箱 + +-- 10.查询不在部门1和2中的员工 + +-- 11.查询员工信息中,名字带有"王"的员工信息 + +-- 12.查询员工信息中,地址以"福建省"开头的员工信息 + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b20a53be2c7741672e35f5fe1d90b39f595c423f --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" @@ -0,0 +1,40 @@ +-- 删除数据库 +drop database if exists company; + +-- 创建公司数据库 +create database if not exists company; + +-- 使用该数据库 +use company; + +-- 创建员工表 +create table if not exists staff_info ( + id int(11) primary key, + staff_name varchar(255), + staff_age int(2), + staff_sex int(1), + staff_phone varchar(11), + staff_email varchar(255), + staff_address varchar(255), + staff_brtime datetime(0), + staff_time datetime(0), + dept_id int(11) +); + +-- 插入员工数据 +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_email,staff_address,staff_brtime,staff_time,dept_id) values +(1,'张三',23,1,'15103021550','12313@qq.com','福建省厦门市集美区','2001-01-02','2011-02-03 08:23:35',1), +(2,'李四',21,1,'15803021550','52353@qq.com','福建省泉州市泉港区','2003-03-04','2013-05-18 12:50:01',2), +(3,'王丽',43,2,'15105021500','17810@qq.com','福建省福州市马尾区','1981-07-13','2017-08-03 01:31:50',3), +(4,'徐艳',29,2,'18103021732','98003@qq.com','广东省广州市白云区','1995-08-08','2013-11-20 09:10:11',3), +(5,'欧阳琳',28,2,'19103022380','12213@qq.com','云南省丽江市古城区','1996-05-23','2009-11-10 17:32:35',2), +(6,'徐真',25,1,'15003227850','12388@qq.com','广西壮族自治区桂林市秀峰区','1999-01-02','2013-02-25 08:23:35',1), +(7,'王鑫路',36,1,'15903121600','52360@qq.com','河南省周口西华县','1988-03-04','2017-06-18 12:50:01',2), +(8,'劳拉',32,2,'17308821533','17819@qq.com','福建省龙岩市永定区','1992-07-13','2015-05-19 01:31:50',1), +(9,'田雨',32,2,'18013121755','98013@qq.com','浙江省杭州市西湖区','1992-08-08','2022-10-21 09:10:11',1) +; + +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_address,staff_brtime,staff_time,dept_id) values +(10,'爱新觉罗·吉吉',35,2,'13588025381','内蒙古自治区呼和浩特市新城区','1989-05-23','2008-09-11 17:32:35',2); \ No newline at end of file diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..acff1dbd043cbe5370d9092f4b520324191078da --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/13\351\242\230\346\235\241\344\273\266SQL\347\273\203\344\271\240\351\242\230/13\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.md" @@ -0,0 +1,28 @@ +-- 1.查询所有员工姓名、年龄、手机号码信息 + +-- 2.查询所有员工信息,以年龄倒序排列 + +-- 3.查询一共有多少个员工 + +-- 4.查询员工的总年龄为多少 + +-- 5.查询员工的平均年龄是多少 + +-- 6.查询员工中最小的年龄是多少 + +-- 7.查询员工中最大的年龄是多少 + +-- 8.查询员工数量,按部门编号分组 + +-- 9.查询部门编号为1的员工数量和部门编号 + +-- 10.查询每个部门的部门编号和员工数量,同时按照员工数量倒序排列 + +-- 11.查询每个部门员工数量大于2个的部门编号和员工数量 + +-- 12.查询所有员工信息,并按年龄升序排列,且展示前3条数据 + +-- 13.查询员工表中,男性和女性的员工数量 + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" new file mode 100644 index 0000000000000000000000000000000000000000..2712b46603d6fa9be1e30538767b2fe973feb8a6 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\350\204\232\346\234\254.sql" @@ -0,0 +1,51 @@ +-- 删除数据库 +drop database if exists company; + +-- 创建公司数据库 +create database if not exists company; + +-- 使用该数据库 +use company; + +-- 创建客户表 +create table if not exists staff_info ( + id int(11) primary key, + staff_name varchar(255), + staff_age int(2), + staff_sex int(1), + staff_phone varchar(11), + staff_email varchar(255), + staff_address varchar(255), + staff_brtime datetime(0), + staff_time datetime(0), + dept_id int(11) +); + +-- 创建部门表 +create table if not exists dept_info ( + id int(11) primary key, + dept_name varchar(255) +); + +-- 插入员工数据 +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_email,staff_address,staff_brtime,staff_time,dept_id) values +(1,'张三',23,1,'15103021550','12313@qq.com','福建省厦门市集美区','2001-01-02','2011-02-03 08:23:35',1), +(2,'李四',21,1,'15803021550','52353@qq.com','福建省泉州市泉港区','2003-03-04','2013-05-18 12:50:01',2), +(3,'王丽',43,2,'15105021500','17810@qq.com','福建省福州市马尾区','1981-07-13','2017-08-03 01:31:50',3), +(4,'徐艳',29,2,'18103021732','98003@qq.com','广东省广州市白云区','1995-08-08','2013-11-20 09:10:11',3), +(5,'欧阳琳',28,2,'19103022380','12213@qq.com','云南省丽江市古城区','1996-05-23','2009-11-10 17:32:35',2), +(6,'徐真',25,1,'15003227850','12388@qq.com','广西壮族自治区桂林市秀峰区','1999-01-02','2013-02-25 08:23:35',2), +(7,'王鑫路',36,1,'15903121600','52360@qq.com','河南省周口西华县','1988-03-04','2017-06-18 12:50:01',2), +(8,'劳拉',32,2,'17308821533','17819@qq.com','福建省龙岩市永定区','1992-07-13','2015-05-19 01:31:50',1), +(9,'田雨',32,2,'18013121755','98013@qq.com','浙江省杭州市西湖区','1992-08-08','2022-10-21 09:10:11',2) +; + +insert into staff_info(id,staff_name,staff_age,staff_sex,staff_phone, +staff_email,staff_address,staff_brtime,staff_time) values +(10,'爱新觉罗·吉吉',35,2,'13588025381','78610@qq.com','内蒙古自治区呼和浩特市新城区','1989-05-23','2008-09-11 17:32:35'); + +-- 插入部门数据 +insert into dept_info(id,dept_name) values(1,'软件部'),(2,'信息部'),(3,'人力部'); + +insert into dept_info(id,dept_name) values(4,'后勤部'); diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" new file mode 100644 index 0000000000000000000000000000000000000000..ab20fed35384c81aba4322391884989ab9e45355 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2301/18\351\242\230\350\277\236\346\216\245SQL\347\273\203\344\271\240\351\242\230/18\351\242\230SQL\347\273\203\344\271\240\351\242\230\351\242\230\347\233\256.sql" @@ -0,0 +1,39 @@ +-- 1.查询员工表中,前5条的数据 + +-- 2.从第2条开始,查询5条数据 + +-- 3.查询第1页,每页3条员工信息 + +-- 4.查询第2页,每页3条员工信息 + +-- 5.查询第3页,每页3条员工信息 + +-- 6.查询不在部门1和2中的员工信息 + +-- 7.查询部门在1和2中的员工信息 + +-- 8.查询年龄比平均年龄大的员工信息 + +-- 9.查询出年龄比编号为1的员工的年龄都高的员工信息 + +-- 10.查询员工信息表中的员工姓名、年龄、部门名称 + +-- 11.查询部门中,没有员工的部门信息 + +-- 12.查询部门中,有员工的部门信息 + +-- 13.查询员工的姓名和部门信息 + +-- 14.使用左外连接查询员工的姓名和部门信息 + +-- 15.使用右外连接查询员工的姓名和部门信息 + +-- 16.查询软件部(编号为1)的员工姓名、年龄、手机号码及部门名称 + +-- 17.按照部门分组,查询每个部门的部门名称和员工数量,按员工数量倒序排列 + +-- 18.查询每个部门的最高年龄的员工部门信息和最大年龄 + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\347\273\203\344\271\240.md" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..8afcd1c87f51402f9678c048c7adf085a03c906d --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\347\273\203\344\271\240.md" @@ -0,0 +1,90 @@ +-- 1.查询所有客户 + +-- 2.查询所有商品 + +-- 3.查询所有订单 + +-- 4.查询所有的客户,按年龄降序排列 + +-- 5.查询所有的订单,按订单价格升序排列 + +-- 6.查询所有客户的订单 + +-- 7.查询姓名里面含有'王'的客户信息 + +-- 8.查询没有填写邮箱信息的客户信息 + +-- 9.查询家庭住址都是'龙岩'的客户信息 + +-- 10.查询商品类别,类别名称和订单总金额信息,按商品类别分类 + +-- 11.查询手机号码是'151'开头的客户信息 + +-- 12.查询订单中,商品编号为1的商品总订单价格 + +-- 13.查询1号客户的订单数量 + +-- 14.查询购买商品的订单价格最高的客户姓名、昵称、电话、订单价格、下单时间 + +-- 15.查询订单中,每种商品类型的订单数量 + +-- 16.查询所有商品分类,去除重复数据 + +-- 17.查询订单中金额大于1000的订单信息 + +-- 18.查询订单中金额不高于1000的订单信息 + +-- 19.查询平均订单金额大于2000的客户信息和平均订单金额 + +-- 20.查询所有客户的编号、姓名、订单数、总订单金额; + +-- 21.查询手机号码是'181'开头的客户数量 + +-- 22.查询客户的平均年龄 + +-- 23.查询邮箱中存在'3'的客户数量 + +-- 24.查询有购买过'洗发水'商品的客户的编号、姓名; + +-- 25.查询所有订单金额大于3000的客户的编号、姓名和订单金额; + +-- 26.查询没有买过'洗发水'商品的客户的编号、姓名; + +-- 27.查询商品金额在1000-9000之间的商品信息; + +-- 28.查询注册时间最久的客户编号和姓名; + +-- 29.查询姓名为'张三','王丽'的客户信息; + +-- 30.查询订单价格最低的客户编号、姓名和订单金额; + +-- 31.查询没有邮箱信息的客户编号、姓名和订单金额; + +-- 32.查询订单中,比3号商品的所有订单金额都高的订单信息; + +-- 33.查询每个商品的最高金额信息:商品名称和最高金额 + +-- 34.查询3条订单信息,按订单金额降序排列 + +-- 35.从第2条开始,查询3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; + +-- 36.查询第1页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; + +-- 37.查询第2页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; + +-- 38.查询第3页,每页设置3条数据,数据包含客户编号、昵称、手机号码、订单金额、下单时间; + +-- 39.查询性别为2(女性)的客户的订单数量 + +-- 40.查询客户1和客户2的所有订单信息,要求:组合数据 + + + + + + + + + + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\350\257\255\345\217\245.sql" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\350\257\255\345\217\245.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b718d77675021c9e13a5c59df8ac8a11c3cc9b71 --- /dev/null +++ "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/1.\346\225\260\346\215\256\345\272\223\345\237\272\347\241\200\350\257\276\344\273\266/SQL\347\273\203\344\271\240\351\242\230/SQL\347\273\203\344\271\240\351\242\2302/40\351\242\230SQL\347\273\203\344\271\240\351\242\230/40\351\242\230SQL\350\257\255\345\217\245.sql" @@ -0,0 +1,90 @@ +-- 创建电商系统数据库 +create database if not exists commerce character set utf8mb4 collate utf8mb4_0900_ai_ci; + +-- 使用该数据库 +use commerce; + +-- 创建客户表 +create table if not exists customer ( + id int(11) primary key comment '客户编号', + customer_name varchar(255) comment '客户名称', + customer_nickname varchar(255) comment '客户昵称', + customer_age int(2) comment '客户年龄', + customer_sex int(1) comment '客户性别', + customer_phone varchar(11) comment '手机号码', + customer_email varchar(255) comment '客户邮箱', + customer_address varchar(255) comment '客户地址', + customer_time datetime(0) comment '客户注册时间' +) comment '客户信息表'; + +-- 创建商品表 +create table if not exists goods ( + id int(11) primary key comment '商品编号', + goods_name varchar(255) comment '商品名称', + goods_price decimal comment '商品价格', + goods_colour varchar(255) comment '商品颜色', + goods_weight int(11) comment '商品重量', + type_id int(11) comment '类型编号' +) comment '商品信息表'; + + +-- 商品分类表 +create table if not exists goods_type ( + id int(11) primary key comment '类别编号', + type_name varchar(255) comment '类别名称' +) comment '商品类别表'; + + +-- 创建订单表 +create table if not exists orders ( + id int(11) primary key comment '订单编号', + orders_num int(5) comment '订单数量', + orders_price decimal comment '订单价格', + orders_time datetime(0) comment '订单时间', + orders_address varchar(255) comment '订单地址', + goods_id int(11) comment '商品编号', + customer_id int(11) comment '客户编号' +) comment '订单信息表'; + +-- 插入客户数据 +insert into customer(id,customer_name,customer_nickname,customer_age,customer_sex, +customer_phone,customer_email,customer_address,customer_time) values +(1,'张三','电商1号',30,1,'15103021550','12313@qq.com','福建省龙岩市新罗区','2011-02-03 08:23:35'), +(2,'李四','电商5号',25,1,'15803021550','52353@qq.com','福建省龙岩市漳平市','2013-05-18 12:50:01'), +(3,'王丽','电商3号',29,2,'15105021500','17810@qq.com','福建省龙岩市永定区','2017-08-03 01:31:50'), +(4,'徐艳','电商4号',22,2,'18103021732','98003@qq.com','广东省广州市白云区','2013-11-20 09:10:11'), +(5,'欧阳琳','电商2号',31,2,'19103022380','12213@qq.com','云南省丽江市古城区','2009-11-10 17:32:35') +; + +insert into customer(id,customer_name,customer_nickname,customer_age,customer_sex, +customer_phone,customer_address,customer_time) values +(6,'谢云','电商6号',24,1,'18055123367','陕西省西安市雁塔区','2015-06-06 19:21:35'); + +-- 插入商品数据 +insert into goods(id,goods_name,goods_price,goods_colour,goods_weight,type_id) values +(1,'iPhone 15 Pro',9999.00,'白色',300,2), +(2,'联想拯救者 y9000p',8999.00,'灰色',2600,1), +(3,'洗发水',53.00,'蓝色',500,3) +; + +-- 插入商品分类表数据 +insert into goods_type(id,type_name) values +(1,'电脑办公'), +(2,'手机数码'), +(3,'日用产品'), +(4,'日用产品') +; + +-- 插入订单表 +insert into orders(id,orders_num,orders_price,orders_time,orders_address,goods_id,customer_id) values +(1,2,19998.00,'2023-09-13 19:21:35','陕西省西安市雁塔区秦皇小区1号',1,6), +(2,1,9999.00,'2024-01-15 11:28:01','云南省丽江市古城区古城小区15号',1,5), +(3,1,8999.00,'2024-01-01 08:35:38','云南省丽江市古城区古城小区15号',2,5), +(4,1,53.00,'2024-01-01 08:37:38','云南省丽江市古城区古城小区5号',3,5), +(5,1,8999.00,'2023-11-11 11:35:38','福建省龙岩市漳平市樟树小区3-3号',2,2), +(6,1,8999.00,'2023-11-11 20:37:38','福建省龙岩市永定区永富小区8号',2,3), +(7,3,29997.00,'2023-11-11 20:37:38','福建省龙岩市漳平市樟树小区3-3号',1,2), +(8,10,530.00,'2023-12-01 09:50:05','福建省龙岩市新罗区万达小区0-1号',3,1) +; + + diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/Git-2.26.0-64-bit.exe" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/Git-2.26.0-64-bit.exe" new file mode 100644 index 0000000000000000000000000000000000000000..aeb6c1501b8b4b4d20de7361814836be3b6d730d Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/Git-2.26.0-64-bit.exe" differ diff --git "a/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/JDK_API.zip" "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/JDK_API.zip" new file mode 100644 index 0000000000000000000000000000000000000000..e44622ad5f27fc83cef8b996c9d25c12ef3df754 Binary files /dev/null and "b/my-mysql/\350\257\276\345\220\216\344\275\234\344\270\232/2024.4.08/JDK_API.zip" differ