From 7ca35f66b2259bf9ed7e88945c70d722482244c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=8E=9A=E8=BE=B0?= Date: Thu, 19 Oct 2023 02:08:15 +0800 Subject: [PATCH 1/2] twenty-second --- ...27\345\217\243\345\207\275\346\225\260.md" | 84 ++++++++++--------- .../\347\264\242\345\274\225.md" | 56 +++++++++++++ 2 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 "53 \345\221\250\345\216\232\350\276\260/20231019 \347\254\254\344\272\214\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232 \347\264\242\345\274\225/\347\264\242\345\274\225.md" diff --git "a/53 \345\221\250\345\216\232\350\276\260/20231016 \347\254\254\344\272\214\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232 \347\252\227\345\217\243\345\207\275\346\225\260/\347\252\227\345\217\243\345\207\275\346\225\260.md" "b/53 \345\221\250\345\216\232\350\276\260/20231016 \347\254\254\344\272\214\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232 \347\252\227\345\217\243\345\207\275\346\225\260/\347\252\227\345\217\243\345\207\275\346\225\260.md" index f594c56..46dfa8d 100644 --- "a/53 \345\221\250\345\216\232\350\276\260/20231016 \347\254\254\344\272\214\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232 \347\252\227\345\217\243\345\207\275\346\225\260/\347\252\227\345\217\243\345\207\275\346\225\260.md" +++ "b/53 \345\221\250\345\216\232\350\276\260/20231016 \347\254\254\344\272\214\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232 \347\252\227\345\217\243\345\207\275\346\225\260/\347\252\227\345\217\243\345\207\275\346\225\260.md" @@ -251,58 +251,64 @@ CASE 0 ELSE 1 END 年龄 FROM - employee;#求每个员工还有多少天过生日,并返回下次生日是星期几 -SELECT + employee; + +#求每个员工还有多少天过生日,并返回下次生日是星期几 +select +CURRENT_DATE (),concat_ws('-',YEAR (CURRENT_DATE),MONTH (birth),DAY (birth)) + from employee; + + +select ename, - CONCAT_WS( '-', MONTH ( birth ), DAY ( birth ) ) 生日, - DATEDIFF( - CURRENT_DATE (), - CONCAT_WS( - '-', - YEAR ( CURRENT_DATE ), - MONTH ( birth ), - DAY ( birth ) - ) - ) 距离下次生日的天数, -CASE - DATE_FORMAT( - CONCAT_WS( + concat_ws( '-', month ( birth ), day ( birth ) ) 生日, + + + CASE + WHEN DATE_FORMAT(birth,'%m-%d')>DATE_FORMAT(CURRENT_DATE,'%m-%d') THEN + DATEDIFF(CONCAT_ws('-',DATE_FORMAT(CURRENT_DATE,'%Y')+1,DATE_FORMAT(birth,'%m-%d')),CURRENT_DATE) + ELSE + DATEDIFF(CURRENT_DATE,CONCAT_ws('-',DATE_FORMAT(CURRENT_DATE,'%Y'),DATE_FORMAT(birth,'%m-%d'))) +end + + 距离下次生日的天数, + + + +case + date_format( + concat_ws( '-', - CASE + case - WHEN DATEDIFF( - CURRENT_DATE (), - CONCAT_WS( - '-', - YEAR ( CURRENT_DATE ), - MONTH ( birth ), - DAY ( birth ) - ) - ) > 0 THEN - YEAR ( CURRENT_DATE )+ 1 ELSE YEAR ( CURRENT_DATE ) - END, - MONTH ( birth ), - DAY ( birth ) + when DATE_FORMAT(birth,'%m-%d')>DATE_FORMAT(CURRENT_DATE,'%m-%d') then + CONCAT_ws('-',DATE_FORMAT(CURRENT_DATE,'%Y')+1,DATE_FORMAT(birth,'%m-%d'))ELSE + CONCAT_ws('-',DATE_FORMAT(CURRENT_DATE,'%Y'),DATE_FORMAT(birth,'%m-%d')) + end, + month ( birth ), + day ( birth ) ), '%w' ) - WHEN 0 THEN + when 0 then '周日' - WHEN 1 THEN + when 1 then '周一' - WHEN 2 THEN + when 2 then '周二' - WHEN 3 THEN + when 3 then '周三' - WHEN 4 THEN + when 4 then '周四' - WHEN 5 THEN + when 5 then '周五' - WHEN 6 THEN + when 6 then '周六' - END 下次生日的星期 -FROM - employee;#求每个员工当前实发工资与入职时工资的增长率,输出员工姓名,部门,入职工资,实际工资,增长率 + end 下次生日的星期 +from + employee; + + #求每个员工当前实发工资与入职时工资的增长率,输出员工姓名,部门,入职工资,实际工资,增长率 SELECT ename, dname, diff --git "a/53 \345\221\250\345\216\232\350\276\260/20231019 \347\254\254\344\272\214\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232 \347\264\242\345\274\225/\347\264\242\345\274\225.md" "b/53 \345\221\250\345\216\232\350\276\260/20231019 \347\254\254\344\272\214\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232 \347\264\242\345\274\225/\347\264\242\345\274\225.md" new file mode 100644 index 0000000..deafe13 --- /dev/null +++ "b/53 \345\221\250\345\216\232\350\276\260/20231019 \347\254\254\344\272\214\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232 \347\264\242\345\274\225/\347\264\242\345\274\225.md" @@ -0,0 +1,56 @@ +2023年10月19日 + +# 索引 + +## 截图 + +![piiF340.md.png](https://z1.ax1x.com/2023/10/19/piiF340.md.png) + +![piiFYgU.md.png](https://z1.ax1x.com/2023/10/19/piiFYgU.md.png) + +## 作业代码 + +```mysql +drop database if exists d; +create database if not exists d; +use d; + +set global sync_binlog=0; +set global innodb_flush_log_at_trx_commit=0; + +delimiter // +create procedure p(in num int) +BEGIN + declare i int default 1; + declare sex char(1) default '男'; + declare hobby char(10) default '唱'; + drop table if exists t; + create table if not exists t( + id int primary key auto_increment, + `name` varchar(30), + phone char(20), + sex char(1), + hobby char(10) + ); + while i<=num + DO + insert into t values (null, CONCAT('小明', i),concat('1551',i),sex,hobby); + set sex='女'; + set hobby='跳'; + set i =i+1; + insert into t values (null, CONCAT('小明', i),concat('15561',i),sex,hobby); + set sex='男'; + set hobby='篮球'; + set i =i+1; + insert into t values (null, CONCAT('小明', i),concat('1551',i),sex,hobby); + set sex='女'; + set hobby='music'; + set i =i+1; + set sex='男'; + end while; +end // +delimiter ; + +call p(10000000); +``` + -- Gitee From 4886835d7edef5a6dba26d9344e1d91aea318b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=8E=9A=E8=BE=B0?= Date: Thu, 19 Oct 2023 02:15:23 +0800 Subject: [PATCH 2/2] twenty-second --- .../\347\264\242\345\274\225.md" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/53 \345\221\250\345\216\232\350\276\260/20231019 \347\254\254\344\272\214\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232 \347\264\242\345\274\225/\347\264\242\345\274\225.md" "b/53 \345\221\250\345\216\232\350\276\260/20231019 \347\254\254\344\272\214\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232 \347\264\242\345\274\225/\347\264\242\345\274\225.md" index deafe13..2c1ac92 100644 --- "a/53 \345\221\250\345\216\232\350\276\260/20231019 \347\254\254\344\272\214\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232 \347\264\242\345\274\225/\347\264\242\345\274\225.md" +++ "b/53 \345\221\250\345\216\232\350\276\260/20231019 \347\254\254\344\272\214\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232 \347\264\242\345\274\225/\347\264\242\345\274\225.md" @@ -4,9 +4,9 @@ ## 截图 -![piiF340.md.png](https://z1.ax1x.com/2023/10/19/piiF340.md.png) +![piiF340.md.png](https://z1.ax1x.com/2023/10/19/piiFdb9.png) -![piiFYgU.md.png](https://z1.ax1x.com/2023/10/19/piiFYgU.md.png) +![piiFYgU.md.png](https://z1.ax1x.com/2023/10/19/piiFaDJ.png) ## 作业代码 -- Gitee