From e8d7a0a9933704c59c8de90d6713149a468fce97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=B9=8F?= <3460863727@qq.com> Date: Fri, 16 Sep 2022 04:53:51 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E9=99=88=E9=B9=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈鹏 <3460863727@qq.com> --- .../\344\275\234\344\270\232.sql" | 17 +++++++++++++++++ .../\347\254\224\350\256\260.txt" | 8 ++++++++ 2 files changed, 25 insertions(+) create mode 100644 "\351\231\210\351\271\217/\344\275\234\344\270\232.sql" create mode 100644 "\351\231\210\351\271\217/\347\254\224\350\256\260.txt" diff --git "a/\351\231\210\351\271\217/\344\275\234\344\270\232.sql" "b/\351\231\210\351\271\217/\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..beddb87 --- /dev/null +++ "b/\351\231\210\351\271\217/\344\275\234\344\270\232.sql" @@ -0,0 +1,17 @@ +-- 1. 随机生成短信验证码(6位数字) +SELECT RPAD(ROUND(RAND()*100000,0),6,0); +-- 2. 统计每个用户的所有卡余额之和,并四舍五入,保留一位小数 +SELECT ROUND(SUM(CardMoney),1) FROM bankcard +INNER JOIN accountinfo a on a.AccountId=bankcard.AccountId +GROUP BY realname; +-- 3.查询用户表中名字部分为中文的所有用户记录(即必须含有中文,但不能全部是中文,比如‘刘备a1’,但不能是'刘备') +select * from accountinfo +where length(RealName) != 3*char_length(RealName) and length(RealName) != char_length(RealName); + + +-- 4.找出所有含有非法字符('笨蛋','傻瓜','死')的记录,并这些非法字符,比如 '死张三是傻瓜' 变成 '*张三是**'(几个字符,就替换为几个*) +select replace(replace(replace(replace(replace(RealName,'笨','*'),'蛋','*'),'傻','*'),'瓜','*'),'死','*') from accountinfo; + +-- 5.查找账号表中相同月份开户的用户 +SELECT RIGHT(LEFT(opentime,7),2)开户月份,COUNT(*)人数 FROM accountinfo +GROUP BY RIGHT(LEFT(opentime,7),2 ); diff --git "a/\351\231\210\351\271\217/\347\254\224\350\256\260.txt" "b/\351\231\210\351\271\217/\347\254\224\350\256\260.txt" new file mode 100644 index 0000000..e691db0 --- /dev/null +++ "b/\351\231\210\351\271\217/\347\254\224\350\256\260.txt" @@ -0,0 +1,8 @@ +四舍五入1,ROUND(CardMoney,1) + +四舍五入2 FROM `bankcard` ; +CHAR_LENGTH 字符长度 +LENGTH: 字节长度(数字,字母,符号占用一个字节,一个汉字占3个字节--utf8) +INSERT(str,pos,len,newstr) 指定位置、指定长度替换 +REPLACE(str,from_str,to_str) 模糊查找替换 +截取 LEFT(str,len) 左边 RIGHT(str,len) 右边 substr(,)中间 -- Gitee From 157735413f100f65b4d0882ddc79e59b86db0a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=B9=8F?= <3460863727@qq.com> Date: Sun, 18 Sep 2022 13:14:11 +0000 Subject: [PATCH 2/5] 2022-9-18 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈鹏 <3460863727@qq.com> --- .../\344\275\234\344\270\232/SQLQuery2.sql" | 54 +++++++++++++++++++ ...41\350\257\276\346\237\245\350\257\242.md" | 19 +++++++ 2 files changed, 73 insertions(+) create mode 100644 "18\351\231\210\351\271\217/\344\275\234\344\270\232/SQLQuery2.sql" create mode 100644 "18\351\231\210\351\271\217/\347\254\224\350\256\260/9-16\347\254\254\344\272\214\346\254\241\350\257\276\346\237\245\350\257\242.md" diff --git "a/18\351\231\210\351\271\217/\344\275\234\344\270\232/SQLQuery2.sql" "b/18\351\231\210\351\271\217/\344\275\234\344\270\232/SQLQuery2.sql" new file mode 100644 index 0000000..8a36b87 --- /dev/null +++ "b/18\351\231\210\351\271\217/\344\275\234\344\270\232/SQLQuery2.sql" @@ -0,0 +1,54 @@ +--1. ѯ人еԱϢҪʾԼԱϸ +select * from People +join Department on People.DepartmentId = Department.DepartmentId +where PeopleAddress ='人'; + +--2. ѯ人еԱϢҪʾƣְԼԱϸ +select * from People +join Department on People.DepartmentId = Department.DepartmentId +join [rank] on people.departmentid=[rank].rankid +where PeopleAddress ='人'; + +--3. ݲŷͳԱԱܺͣƽʣ߹ʺ͹ʡ +select DepartmentName,COUNT(*) Ա, SUM(PeopleSalary) ܺ, AVG(PeopleSalary) ƽ, MAX(PeopleSalary) ,MIN(PeopleSalary) С from People +join Department on People.DepartmentId = Department.DepartmentId +group by DepartmentName; + +--4. ݲŷͳԱԱܺͣƽʣ߹ʺ͹ʣƽ10000 µIJͳƣҸƽʽС +select DepartmentName,COUNT(*) Ա, SUM(PeopleSalary) ܺ, AVG(PeopleSalary) ƽ, MAX(PeopleSalary) ,MIN(PeopleSalary) С from People +join Department on People.DepartmentId = Department.DepartmentId +group by DepartmentName +having AVG(PeopleSalary)>=10000 +order by AVG(PeopleSalary) desc; + + + + +--5. ݲƣȻְλƣͳԱԱܺͣƽʣ߹ʺ͹ +select DepartmentName,RankName ,[Rank].RankId ְλȼ , COUNT(*) Ա,SUM(PeopleSalary) ܺ, AVG(PeopleSalary) ƽ, MAX(PeopleSalary) ,MIN(PeopleSalary) С from people +join department on People.DepartmentId = Department.DepartmentId +join [Rank] on People.RankId = [Rank].RankId +group by DepartmentName,RankName,[Rank].RankId + + +--6.ѯз 6.22--7.22 ԱϢ +select * from people where +(MONTH(PeopleBirth)=6 and DAY(PeopleBirth)>=22) or +(MONTH(PeopleBirth)=7 and DAY(PeopleBirth)<=22) + +--7.ѯԱϢһʾ(,ţ,,,,,,,,,,) +select * , +case when datepart(YY,PeopleBirth)%12=0 then'' +when datepart(YY,PeopleBirth)%12=1 then'ţ' +when datepart(YY,PeopleBirth)%12=2 then'' +when datepart(YY,PeopleBirth)%12=3 then'' +when datepart(YY,PeopleBirth)%12=4 then'' +when datepart(YY,PeopleBirth)%12=5 then'' +when datepart(YY,PeopleBirth)%12=6 then'' +when datepart(YY,PeopleBirth)%12=7 then'' +when datepart(YY,PeopleBirth)%12=8 then'' +when datepart(YY,PeopleBirth)%12=9 then'' +when datepart(YY,PeopleBirth)%12=10 then'' +when datepart(YY,PeopleBirth)%12=11 then'' +end as +from people ; \ No newline at end of file diff --git "a/18\351\231\210\351\271\217/\347\254\224\350\256\260/9-16\347\254\254\344\272\214\346\254\241\350\257\276\346\237\245\350\257\242.md" "b/18\351\231\210\351\271\217/\347\254\224\350\256\260/9-16\347\254\254\344\272\214\346\254\241\350\257\276\346\237\245\350\257\242.md" new file mode 100644 index 0000000..ef141a6 --- /dev/null +++ "b/18\351\231\210\351\271\217/\347\254\224\350\256\260/9-16\347\254\254\344\272\214\346\254\241\350\257\276\346\237\245\350\257\242.md" @@ -0,0 +1,19 @@ +## 第二次课查询 + +--保留小数点后2位 + +--round(小数,保留位数) + +--convert 02154.13200 decimal(5,2):保留小数后2位,有效数字总共是5 + +--convert和cast 可以强制转换数据类型 + +--count(*):空值也统计 count(字段):当前字段的空值不统计 + +--删除数据 +delete from 表名 where 列名='' + +--删除 +--drop 删除整张表 +--truncate删除整张表,表还在 + -- Gitee From 90d2208bec030e9f904c96b489de8ba8e1efab4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=B9=8F?= <3460863727@qq.com> Date: Sun, 18 Sep 2022 13:17:13 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E9=99=88=E9=B9=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\275\234\344\270\232.sql" | 17 ----------------- .../\347\254\224\350\256\260.txt" | 8 -------- 2 files changed, 25 deletions(-) delete mode 100644 "\351\231\210\351\271\217/\344\275\234\344\270\232.sql" delete mode 100644 "\351\231\210\351\271\217/\347\254\224\350\256\260.txt" diff --git "a/\351\231\210\351\271\217/\344\275\234\344\270\232.sql" "b/\351\231\210\351\271\217/\344\275\234\344\270\232.sql" deleted file mode 100644 index beddb87..0000000 --- "a/\351\231\210\351\271\217/\344\275\234\344\270\232.sql" +++ /dev/null @@ -1,17 +0,0 @@ --- 1. 随机生成短信验证码(6位数字) -SELECT RPAD(ROUND(RAND()*100000,0),6,0); --- 2. 统计每个用户的所有卡余额之和,并四舍五入,保留一位小数 -SELECT ROUND(SUM(CardMoney),1) FROM bankcard -INNER JOIN accountinfo a on a.AccountId=bankcard.AccountId -GROUP BY realname; --- 3.查询用户表中名字部分为中文的所有用户记录(即必须含有中文,但不能全部是中文,比如‘刘备a1’,但不能是'刘备') -select * from accountinfo -where length(RealName) != 3*char_length(RealName) and length(RealName) != char_length(RealName); - - --- 4.找出所有含有非法字符('笨蛋','傻瓜','死')的记录,并这些非法字符,比如 '死张三是傻瓜' 变成 '*张三是**'(几个字符,就替换为几个*) -select replace(replace(replace(replace(replace(RealName,'笨','*'),'蛋','*'),'傻','*'),'瓜','*'),'死','*') from accountinfo; - --- 5.查找账号表中相同月份开户的用户 -SELECT RIGHT(LEFT(opentime,7),2)开户月份,COUNT(*)人数 FROM accountinfo -GROUP BY RIGHT(LEFT(opentime,7),2 ); diff --git "a/\351\231\210\351\271\217/\347\254\224\350\256\260.txt" "b/\351\231\210\351\271\217/\347\254\224\350\256\260.txt" deleted file mode 100644 index e691db0..0000000 --- "a/\351\231\210\351\271\217/\347\254\224\350\256\260.txt" +++ /dev/null @@ -1,8 +0,0 @@ -四舍五入1,ROUND(CardMoney,1) - -四舍五入2 FROM `bankcard` ; -CHAR_LENGTH 字符长度 -LENGTH: 字节长度(数字,字母,符号占用一个字节,一个汉字占3个字节--utf8) -INSERT(str,pos,len,newstr) 指定位置、指定长度替换 -REPLACE(str,from_str,to_str) 模糊查找替换 -截取 LEFT(str,len) 左边 RIGHT(str,len) 右边 substr(,)中间 -- Gitee From 93bc4d07c85bd42b7dcffc7147dc5a8c6884bf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=B9=8F?= <3460863727@qq.com> Date: Sun, 18 Sep 2022 13:17:20 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20READ?= =?UTF-8?q?ME.en.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 README.en.md diff --git a/README.en.md b/README.en.md deleted file mode 100644 index ac31e94..0000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# SQL进阶 - -#### Description -11 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) -- Gitee From 9ea55235688e5e68aa8f98d8ce348f5aa889d83e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=B9=8F?= <3460863727@qq.com> Date: Sun, 18 Sep 2022 13:17:26 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20READ?= =?UTF-8?q?ME.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 1c4b0e7..0000000 --- a/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# SQL进阶 - -#### 介绍 -11 - -#### 软件架构 -软件架构说明 - - -#### 安装教程 - -1. xxxx -2. xxxx -3. xxxx - -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) -- Gitee