diff --git "a/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test01_market.md" "b/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test01_market.md" deleted file mode 100644 index 60bbbc18247efe6bf29e0042d575e710bcb3671d..0000000000000000000000000000000000000000 --- "a/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test01_market.md" +++ /dev/null @@ -1,31 +0,0 @@ -#1、创建数据库test01_market -CREATE database test01_market; -use test01_market; -#2、创建表格customers -#| 字段名 | 数据类型 | -#| --------- | ----------- | -#| c_num | int(11) | -#| c_name | varchar(50) | -#| c_contact | varchar(50) | -#| c_city | varchar(50) | -#| c_birth | date | -CREATE TABLE customers( -c_num int (11), -c_name VARCHAR(50), -c_contact VARCHAR(50), -c_city VARCHAR(50), -c_birth DATE -); -#要求3:将c_contact字段移动到c_birth字段后面 -ALTER TABLE customers MODIFY c_contact VARCHAR(50) AFTER c_birth; -#要求4:将c_name字段数据类型改为 varchar(70) -ALTER TABLE customers MODIFY c_name VARCHAR(70); -#要求5:将c_contact字段改名为c_phone -ALTER TABLE customers CHANGE c_contact c_phone VARCHAR(50); -#要求6:增加c_gender字段到c_name后面,数据类型为char(1) -ALTER TABLE customers ADD COLUMN c_gender char(1); -ALTER TABLE customers MODIFY c_gender char(1) AFTER c_name; -#要求7:将表名改为customers_info -ALTER TABLE customers RENAME TO customers_info; -#要求8:删除字段c_city -ALTER TABLE customers_info DROP COLUMN c_city; \ No newline at end of file diff --git "a/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test02_library(1).md" "b/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test02_library(1).md" deleted file mode 100644 index fdf1167ce5f42ed3e56c23fb0d5cfe3b6447bc58..0000000000000000000000000000000000000000 --- "a/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test02_library(1).md" +++ /dev/null @@ -1,49 +0,0 @@ -#1、创建数据库test02_library -CREATE DATABASE test02_library; -USE test02_library; -#2、创建表格books -CREATE TABLE books( -b_id int(11) not null , -b_name VARCHAR(50) NOT NULL, -`authors` VARCHAR(100) NOT NULL, -price FLOAT NOT null , -pubdate year NOT NULL, -note varchar(100) , -num int(11) not NULL -); -DESC books; -#| 字段名 | 字段说明 | 数据类型 | 允许为空 | 唯一 | -#| ------- | -------- | ------------- | -------- | ---- | -#| b_id | 书编号 | int(11) | 否 | 是 | -#| b_name | 书名 | varchar(50) | 否 | 否 | -#| authors | 作者 | varchar(100) | 否 | 否 | -#| price | 价格 | float | 否 | 否 | -#| pubdate | 出版日期 | year | 否 | 否 | -#| note | 说明 | varchar(100) | 是 | 否 | -#| num | 库存 | int(11) | 否 | 否 | -#3、向books表中插入记录 -#1) 指定所有字段名称插入第一条记录 -INSERT INTO books (b_id,b_name,`authors`,price,pubdate,note,num) VALUES (1,'Tal of AAA','Dickes',23,'1995','novel',11); -SELECT*FROM books; -#2)不指定字段名称插入第二记录 -INSERT INTO books VALUES(2,'EmmaT','Jane lura',35,'1993','joke',22); -#3)同时插入多条记录(剩下的所有记录) -INSERT INTO books VALUES(3,'Story of Jane','Jane Tim',40,'2001','novel',0),(4,'Lovey Day','George Byron',20,'2005','novel',30),(5,'Old land','Honore Byron',20,'2010','law',0),(6,'The Battle','Upton Sara',30,'1999','medicine',40),(7,'Rose Hood','Richard haggard',28,'2008','cartoon',28); -SELECT*FROM books; -#| b_id | b_name | authors | price | pubdate | note | num | -#| ---- | ------------- | --------------- | ----- | ------- | -------- | ---- | -#| 1 | Tal of AAA | Dickes | 23 | 1995 | novel | 11 | -#| 2 | EmmaT | Jane lura | 35 | 1993 | joke | 22 | -#| 3 | Story of Jane | Jane Tim | 40 | 2001 | novel | 0 | -#| 4 | Lovey Day | George Byron | 20 | 2005 | novel | 30 | -#| 5 | Old land | Honore Blade | 30 | 2010 | law | 0 | -#| 6 | The Battle | Upton Sara | 30 | 1999 | medicine | 40 | -#| 7 | Rose Hood | Richard haggard | 28 | 2008 | cartoon | 28 | - -#4、将小说类型(novel)的书的价格都增加5。 -UPDATE books set price =price+5 WHERE note='novel'; -#5、将名称为EmmaT的书的价格改为40。 -UPDATE books set price=40 WHERE b_name='EmmaT'; -#6、删除库存为0的记录 -DELETE from books where num=0; -SELECT*FROM books; \ No newline at end of file diff --git "a/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test03_bookstore.md" "b/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test03_bookstore.md" deleted file mode 100644 index d957f1aaeefd34bd809afc662a8d757327226f99..0000000000000000000000000000000000000000 --- "a/17 \350\221\243\345\272\206\345\274\272/#1\343\200\201\345\210\233\345\273\272\346\225\260\346\215\256\345\272\223test03_bookstore.md" +++ /dev/null @@ -1,123 +0,0 @@ -#1、创建数据库test03_bookstore -CREATE DATABASE test03_booksore; -USE test03_booksore; -#2、创建book表 -#+----------+--------------+------+-----+---------+----------------+ -#| Field | Type | Null | Key | Default | Extra | -#+----------+--------------+------+-----+---------+----------------+ -#| id | int(11) | NO | PRI | NULL | auto_increment | -#| title | varchar(100) | NO | | NULL | | -#| author | varchar(100) | NO | | NULL | | -#| price | double(11,2) | NO | | NULL | | -#| sales | int(11) | NO | | NULL | | -#| stock | int(11) | NO | | NULL | | -#| img_path | varchar(100) | NO | | NULL | | -#+----------+--------------+------+-----+---------+----------------+ -CREATE TABLE book( -id int(11) UNSIGNED auto_increment PRIMARY KEY not null, -title VARCHAR(100) NOT NULL, -`authors` VARCHAR(100) NOT NULL, -price double(11,2) NOT NULL, -sales INT(11) NOT NULL, -stock INT(11) NOT NULL, -img_path VARCHAR(100) NOT null -); -DESC book; -#尝试添加部分模拟数据,参考示例如下: -#```mysql -#+----+-------------+------------+-------+-------+-------+----------------------------+ -#| id | title | author | price | sales | stock | img_path | -#+----+-------------+------------+-------+-------+-------+-----------------------------+ -#| 1 | 解忧杂货店 | 东野圭吾 | 27.20 | 102 | 98 | upload/books/解忧杂货店.jpg | -#| 2 | 边城 | 沈从文 | 23.00 | 102 | 98 | upload/books/边城.jpg | -#+----+---------------+------------+-------+-------+-------+----------------------------+ -INSERT INTO book VALUES(1,'解忧杂货店','东野吾圭',27.20,102,98,'upload/books/解忧杂货店.jpg'),(2,'边城','沈从文',23.00,102,98,'upload/books/边城.jpg'); -SELECT*FROM book; - -#3、创建用户表users,并插入数据 -#+----------+--------------+------+-----+---------+----------------+ -#| Field | Type | Null | Key | Default | Extra | -#+----------+--------------+------+-----+---------+----------------+ -#| id | int(11) | NO | PRI | NULL | auto_increment | -#| username | varchar(100) | NO | UNI | NULL | | -#| password | varchar(100) | NO | | NULL | | -#| email | varchar(100) | YES | | NULL | | -#+----------+--------------+------+-----+---------+----------------+ -CREATE TABLE users( -id INT(11) UNSIGNED auto_increment PRIMARY key NOT null, -usersname VARCHAR(100) UNIQUE KEY NOT NULL, -`password` VARCHAR(100) NOT null, -email VARCHAR(100) NULL -); -DESC users; -#尝试添加部分模拟数据,参考示例如下: -#+----+----------+----------------------------------+--------------------+ -#| id | username | password | email | -#+----+----------+----------------------------------+--------------------+ -#| 1 | admin | 112233 | admin@mxdx.com | -#+----+----------+----------------------------------+--------------------+ -INSERT INTO users VALUES(1,'admin',112233,'admin@mxdx.com'); -SELECT*FROM users; - -#4、创建订单表orders -#+--------------+--------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+--------------+--------------+------+-----+---------+-------+ -#| id | varchar(100) | NO | PRI | NULL | | -#| order_time | datetime | NO | | NULL | | -#| total_count | int(11) | NO | | NULL | | -#| total_amount | double(11,2) | NO | | NULL | | -#| state | int(11) | NO | | NULL | | -#| user_id | int(11) | NO | MUL | NULL | | -#+--------------+--------------+------+-----+---------+-------+ -CREATE TABLE orders( -id VARCHAR(100) PRIMARY KEY NOT NULL, -order_time DATETIME NOT NULL, -total_count INT(11) NOT NULL, -total_amount DOUBLE(11,2) NOT NULL, -state INT(11) NOT NULL, -user_id INT(11) not null -); -DESC orders; -#尝试添加部分模拟数据,参考示例如下: -#+----------------+---------------------+-------------+--------------+-------+---------+ -#| id | order_time | total_count | total_amount | state | user_id | -#+----------------+---------------------+-------------+--------------+-------+---------+ -#| 15294258455691 | 2018-06-20 00:30:45 | 2 | 50.20 | 0 | 1 | -#+----------------+---------------------+-------------+--------------+-------+----- -INSERT INTO orders VALUES(152942258455691,'2018-06-20 00:30:45',2,50.20,0,1); -SELECT*FROM orders; - -#5、创建订单明细表order_items -#+----------+--------------+------+-----+---------+----------------+ -#| Field | Type | Null | Key | Default | Extra | -#+----------+--------------+------+-----+---------+----------------+ -#| id | int(11) | NO | PRI | NULL | auto_increment | -#| count | int(11) | NO | | NULL | | -#| amount | double(11,2) | NO | | NULL | | -#| title | varchar(100) | NO | | NULL | | -#| author | varchar(100) | NO | | NULL | | -#| price | double(11,2) | NO | | NULL | | -#| img_path | varchar(100) | NO | | NULL | | -#| order_id | varchar(100) | NO | MUL | NULL | | -#+----------+--------------+------+-----+---------+----------------+ -CREATE TABLE order_items( -id INT(11) UNSIGNED auto_increment PRIMARY key NOT null, -count INT(11) NOT NULL, -amount DOUBLE(11,2) NOT NULL, -title VARCHAR(100) NOT NULL, -`author` varchar(100) NOT NULL, -price DOUBLE(11,2) NOT NULL, -img_path VARCHAR(100) NOT NULL, -order_id VARCHAR(100) NOT NULL -); -DESC order_items; -#尝试添加部分模拟数据,参考示例如下: -#+----+-------+--------+---------+---------+-------+----------------+----------------+ -#| id |count| amount| title | author | price | img_path | order_id | -#+----+-------+--------+------------+----------+-------+----------------+----------------+ -#| 1 | 1 | 27.20| 解忧杂货店 | 东野圭吾 | 27.20 | static/img/default.jpg|15294258455691 | -#| 2 | 1 | 23.00| 边城 | 沈从文 | 23.00 | static/img/default.jpg|15294258455691 | -#+----+-------+--------+------------+----------+-------+------------+----------------+ -INSERT INTO order_items VALUES(1,1,27.20,'解忧杂货店','东野圭吾',27.20,'static/img/default.jpg',15294258455691),(2,1,23.00,'边城','沈从文',23.00,'static/img/default.jpg',15294258455691); -SELECT*FROM order_items; \ No newline at end of file diff --git "a/17 \350\221\243\345\272\206\345\274\272/20220223\345\244\215\344\271\240.md" "b/17 \350\221\243\345\272\206\345\274\272/20220223\345\244\215\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..578eaee3cc3224a7abff310c7b9912611cc9bf1f --- /dev/null +++ "b/17 \350\221\243\345\272\206\345\274\272/20220223\345\244\215\344\271\240.md" @@ -0,0 +1,25 @@ +**常用函数** + +AVG(x) :求平均值 + +SUM(x):求总和 + +MAX(x):求最大值 + +MIN(x) :求最小值 + +COUNT(x) :统计记录数 + +**数学函数** + +ABS(X) 返回x的绝对值 + +CEIL(x)返回大于x的最小整数值 + +FLOOR(x)返回小于x的最大 + +mod用于两数的模 + +rand 随机数 + + diff --git "a/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" "b/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" deleted file mode 100644 index 10dcfd853e9d41ae54c1f2eeabb1a047da2a5f2e..0000000000000000000000000000000000000000 --- "a/17 \350\221\243\345\272\206\345\274\272/202302022\350\277\220\347\256\227\347\254\246.md" +++ /dev/null @@ -1,89 +0,0 @@ -# 笔记 - -```mysql -select 字段 as 命名 from 表名 #临时命名字段 - -select 字段1 运算符 字段2 as 命名 from 表名 #重新命名运算后的字段 - -select * from 表名 where 条件 #查询条件字段 - -select* from 表名 where 字段 like '%字符%' #搜素指定字符的字段 -``` - -# 作业 - -```mysql -create database class11 CHARSET utf8; -use class11; -CREATE TABLE employee( -id int, -`name` varchar(20), -sex varchar(20), -tel varchar(20), -addr varchar(50), -salary FLOAT -); -insert into employee values(10001,'张一一','男','13456789000','广东韶关',10010.58); -insert into employee values(10002,'刘小红','女','13454319000','广东江门',12010.21); -insert into employee VALUES(10003,'李四','男','0751-1234567','广东佛山',10040.11); -insert into employee VALUES(10004,'刘小强','男','0755-5555555','广东深圳',15010.23); -insert into employee VALUES(10005,'王艳','男',NULL,'广东广州',14050.16); -select * from employee; -#要求1:**查询出薪资在12000~13000之间的员工信息。 -select * from employee where salary >= 12000 and salary <=13000; -#**要求2:**查询出姓“刘”的员工的工号,姓名,家庭住址。 -select id,`name`,addr from employee WHERE `name` like '刘%'; -#**要求3:**将“李四”的家庭住址改为“广东韶关” -UPDATE employee set addr="广东昭关" where `name`='李四'; -#**要求4:**查询出名字中带“小”的员工 -select * from employee where `name` like '%小%'; -#**要求5:**查询出薪资高于11000的男员工信息 -select * from employee where salary>11000; -#**要求6:**查询没有登记电话号码的员工 -select * from employee where tel is null; -#**要求7:**查询薪资高于12000或者家是广东深圳、广州的男员工 -select * from employee where salary>12000 AND (addr='广东深圳' or addr= '广东广州') AND sex='男'; -#**要求8:**查询每个员工的年薪,显示“姓名、年薪” -select `name` '姓名',salary '年薪' from employee; - -``` - -```mysql -CREATE TABLE countries_info( - `name` VARCHAR(100), - `continent` VARCHAR(100), - `area` INT, - population INT, - gdp BIGINT -); -desc countries_info; -INSERT INTO countries_info VALUES('Afghanistan','Asia',652230,25500100,20343000000); -INSERT INTO countries_info VALUES('Albania','Europe',28748,2831741,12960000000); -INSERT INTO countries_info VALUES('Algeria','Africa',2381741,37100000,188681000000); -INSERT INTO countries_info VALUES('Andorra','Europe',468,78115,3712000000); -INSERT INTO countries_info VALUES('Angola','Africa',1246700,20609294,100990000000); -select * from countries_info; -#要求1:** 查询大国 的国家名称、人口和面积。 -select `name`,area,population from countries_info; -#如果一个国家满足下述两个条件之一,则认为该国是 大国 : -#- 面积至少为 300万平方公里(即,3000000 km2) -select * from countries_info where area>=3000000; -#- 人口至少为 2500 万(即 25000000) -select * from countries_info where population>=25000000; -#**要求2:**查询属于亚洲的国家名称、所属大陆、面积、人口和 GDP 值 -select * from countries_info where continent='Asia'; -#**要求3:**查询国土面积不足1万平方公里且人口不走10万人的国家信息 -select * from countries_info where area <10000 and population <100000; -#**要求4:**查询国家名字中包含“o“字母的国家信息 -select * from countries_info where `name`like '%o%'; -#**要求5:**查询GDP值超过10000000000的国家信息 -select * from countries_info where gdp>10000000000; -#**要求6:**查询每个国家的人均贡献GDP值(GDP/人口总数)并显示为“国家名、人口、GDP值、人均贡献GDP值” -select continent,population,gdp, gdp/population as '人均GDP' from countries_info; -#**要求7:**查询人均贡献GDP值低于1000的国家信息。 -select gdp/population as "人均GDP" from countries_info where (gdp/population)<1000; -#**要求8:**查询每个国家的人均国土面积(面积/人口总数)并显示为“国家名、面积、人口、人均国土面积值” - select continent,area,population,area/population as '人均国土面积' from countries_info; -``` - - diff --git "a/17 \350\221\243\345\272\206\345\274\272/20230213\345\256\211\350\243\205.md" "b/17 \350\221\243\345\272\206\345\274\272/20230213\345\256\211\350\243\205.md" new file mode 100644 index 0000000000000000000000000000000000000000..34f89e4569ec723b3ad6adfbc8ccdfa88df387b1 --- /dev/null +++ "b/17 \350\221\243\345\272\206\345\274\272/20230213\345\256\211\350\243\205.md" @@ -0,0 +1,13 @@ +在mysql网站上下载mysql5,7然后进入数据库安装界面。 + +下载完成后进入任务管理器点开服务界面,找到mysql服务将它设为自动并开启。 + +对此电脑右击进入属性选择高级管理进入环境变量中找到path变量将mysql路径输入C:\Program Files\MySQL\MySQL Server 5.7\bin。 + +使用win+r输入cmd进入管理员界面输入mysql出现以下代码表示安装成功 + +mysql -u root -p + +密码 root + + diff --git "a/17 \350\221\243\345\272\206\345\274\272/20230221 \344\270\252\344\272\272\344\273\213\347\273\215.md" "b/17 \350\221\243\345\272\206\345\274\272/20230215 \344\270\252\344\272\272\344\273\213\347\273\215.md" similarity index 100% rename from "17 \350\221\243\345\272\206\345\274\272/20230221 \344\270\252\344\272\272\344\273\213\347\273\215.md" rename to "17 \350\221\243\345\272\206\345\274\272/20230215 \344\270\252\344\272\272\344\273\213\347\273\215.md" diff --git "a/17 \350\221\243\345\272\206\345\274\272/20230221DDL\345\222\214DML.md" "b/17 \350\221\243\345\272\206\345\274\272/20230216DDL\345\222\214DML.md" similarity index 100% rename from "17 \350\221\243\345\272\206\345\274\272/20230221DDL\345\222\214DML.md" rename to "17 \350\221\243\345\272\206\345\274\272/20230216DDL\345\222\214DML.md" diff --git "a/17 \350\221\243\345\272\206\345\274\272/20230221 \347\272\246\346\235\237.md" "b/17 \350\221\243\345\272\206\345\274\272/20230220 \347\272\246\346\235\237.md" similarity index 100% rename from "17 \350\221\243\345\272\206\345\274\272/20230221 \347\272\246\346\235\237.md" rename to "17 \350\221\243\345\272\206\345\274\272/20230220 \347\272\246\346\235\237.md"