From 8ec995582d5aae5d270f346f1310a536f4bb6271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:04:03 +0000 Subject: [PATCH 1/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B=EF=BC=88=E4=B8=80=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 .../\344\275\234\344\270\232/.keep" | 0 .../2022.9.15\344\275\234\344\270\232.sql" | 71 ------------------- .../\347\254\224\350\256\260/.keep" | 0 .../2022.9.15\347\254\224\350\256\260.md" | 53 -------------- 5 files changed, 124 deletions(-) delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/.keep" delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/.keep" delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\347\254\224\350\256\260/.keep" delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/.keep" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/.keep" deleted file mode 100644 index e69de29..0000000 diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/.keep" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/.keep" deleted file mode 100644 index e69de29..0000000 diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" deleted file mode 100644 index e112875..0000000 --- "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" +++ /dev/null @@ -1,71 +0,0 @@ ---创建数据库 DBTEST -if exists (select * from sys.databases where name = 'DBTEST') -drop database DBTEST -create database DBTEST; - - ---部门信息表(sectionInfo) --- 部门编号 sectionID int 标识列 主键 --- 部门名称 sectionName varchar(10) 不能为空 - -create table sectionInfo( - sectionID int primary key identity(1,1), - sectionName varchar(10) not null -) - -insert sectionInfo values('研发'); -insert sectionInfo values('生产'); -insert sectionInfo values('财务'); -insert sectionInfo values('人事'); -insert sectionInfo values('计划'); - --- select * from sectionInfo; - ---员工信息表(userInfo) --- 员工编号 userNo int 标识列 主键 不允许为空 --- 员工姓名 userName varchar(10) 唯一约束 不允许为空 长度必须大于4 --- 员工性别 userSex varchar(2) 不允许为空 只能是男或女 --- 员工年龄 userAge int 不能为空 范围在1-100之间 --- 员工地址 userAddress varchar(50) 默认值为“湖北” --- 员工部门 userSection int 外键,引用部门信息表的部门编号 - ---drop table userInfo; - -create table userInfo ( - userNo int identity(1,1) primary key not null, - userName varchar(10) unique not null check(len(userName) > 4), - userSex varchar(2) not null check(userSex = '男' or userSex = '女') , - userAge int not null check(userAge between 1 and 100), - userAddress varchar(50) default '湖北', - userSection int references sectionInfo(sectionId) -); - -insert userInfo (userName,userSex,userAge,userAddress,userSection) -values ('张三123','男','25','福建','1'), - ('李四123','女','30','上海','2'), - ('王五123','女','36','上海','3'), - ('赵六123','女','40','广州','4'), - ('11223','女','27','广州','5'); ---select * from userInfo - ---员工考勤表(workInfo) --- 考勤编号 workId int 标识列 主键 不能为空 --- 考勤员工 userId int 外键 引用员工信息表的员工编号 不能为空 --- 考勤时间 workTime datetime 不能为空 --- 考勤说明 workDescription varchar(40) 不能为空 内容只能是“迟到”,“早退”,“旷工”,“病假”,“事假”中的一种 - -create table workInfo( - workId int identity(1,1) primary key not null, - userId int references userInfo(userNo) not null, - workTime datetime not null, - workDescription varchar(40) not null check(workDescription = '迟到' or workDescription = '早退' or workDescription = '旷工' or workDescription = '病假' or workDescription = '事假') -) -insert workInfo(userId,workTime,workDescription) -values (1,'2022-1-15 15:15:1','迟到'), - (2,'2022-1-16 15:15:1','早退'), - (3,'2022-1-14 15:15:1','旷工'), - (4,'2022-1-16 15:15:1','病假'), - (5,'2022-1-12 15:15:1','事假'); - - ---select * from workInfo \ No newline at end of file diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\347\254\224\350\256\260/.keep" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\347\254\224\350\256\260/.keep" deleted file mode 100644 index e69de29..0000000 diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" deleted file mode 100644 index 1d4f017..0000000 --- "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" +++ /dev/null @@ -1,53 +0,0 @@ -# 1.绾︽潫 - -- 涓婚敭绾︽潫 primary key - - ```sql - create table a( - id int primary key identity(1,1) - ) - ``` - - ```sql - alter table 琛ㄥ悕 alter column 涓婚敭鍒楀悕 涓婚敭绫诲瀷 not null; - ``` - - - -- 澶栭敭绾︽潫 foreig key references - -```sql - --淇敼琛ㄧ粨鏋 琛ㄥ悕 add constraint 绾︽潫鍚 foreign key(瑕佸紩鐢ㄧ殑瀛楁) references 涓婚敭琛(瀛楁) - Alter table StuInfo add constraint FK_StuInfo_ClassId foreign key(ClassID) references ClassInfo(ClassID) -``` - -```sql -ClassID int references ClassInfo(ClassID) - ClassID int -``` - -- 榛樿 default - - ```sql - userAddress varchar(50) default '婀栧寳' - ``` - -- 鍞竴 unique - - ```sql - userName varchar(10) unique - ``` - -- check - -- 濡傛灉瀵瑰崟涓垪瀹氫箟 CHECK 绾︽潫锛岄偅涔堣鍒楀彧鍏佽鐗瑰畾鐨勫笺 - - 濡傛灉瀵逛竴涓〃瀹氫箟 CHECK 绾︽潫锛岄偅涔堟绾︽潫浼氬熀浜庤涓叾浠栧垪鐨勫煎湪鐗瑰畾鐨勫垪涓鍊艰繘琛岄檺鍒躲 - - ```sql - userAge int not null check(userAge between 1 and 100) - ``` - - - -- 闈炵┖ not null \ No newline at end of file -- Gitee From c84dca87ac0fa0412eee3019d94bc3d6ca739820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:04:09 +0000 Subject: [PATCH 2/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B=EF=BC=88=E4=BA=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 .../2022.9.16\344\275\234\344\270\232.sql" | 81 ------------------- .../\344\275\234\344\270\232/.keep" | 0 .../\347\254\224\350\256\260/.keep" | 0 .../2022.9.16\347\254\224\350\256\260.md" | 45 ----------- 5 files changed, 126 deletions(-) delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/.keep" delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/2022.9.16\344\275\234\344\270\232.sql" delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\344\275\234\344\270\232/.keep" delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\347\254\224\350\256\260/.keep" delete mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\347\254\224\350\256\260/2022.9.16\347\254\224\350\256\260.md" diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/.keep" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/.keep" deleted file mode 100644 index e69de29..0000000 diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/2022.9.16\344\275\234\344\270\232.sql" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/2022.9.16\344\275\234\344\270\232.sql" deleted file mode 100644 index ebf1aee..0000000 --- "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/2022.9.16\344\275\234\344\270\232.sql" +++ /dev/null @@ -1,81 +0,0 @@ ---查询出巨蟹 6.22--7.22 的员工信息 -select * from People -where datename(month,PeopleBirth) = 6 and day(PeopleBirth) between 22 and 30 -or datename(month,PeopleBirth) = 7 and day(PeopleBirth) between 1 and 22; - - ---查询所有员工信息,添加一列显示属相(鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪) -select *, case -when year(PeopleBirth)%12 = 0 -then '猴' -when year(PeopleBirth)%12 = 1 -then '鸡' -when year(PeopleBirth)%12 = 2 -then '狗' -when year(PeopleBirth)%12 = 3 -then '猪' -when year(PeopleBirth)%12 = 4 -then '鼠' -when year(PeopleBirth)%12 = 5 -then '牛' -when year(PeopleBirth)%12 = 6 -then '虎' -when year(PeopleBirth)%12 = 7 -then '兔' -when year(PeopleBirth)%12 = 8 -then '龙' -when year(PeopleBirth)%12 = 9 -then '蛇' -when year(PeopleBirth)%12 = 10 -then '马' -when year(PeopleBirth)%12 = 11 -then '羊' -end '生肖' -from People - - ---1. 查询出武汉地区所有的员工信息,要求显示部门名称以及员工的详细资料 -select p.*,d.DepartmentName from People p -inner join Department d -on p.DepartmentId = d.DepartmentId -where p.PeopleAddress = '武汉'; - - ---2. 查询出武汉地区所有的员工信息,要求显示部门名称,职级名称以及员工的详细资料 -select p.*,d.DepartmentName,r.RankName from People p -inner join Department d -on p.DepartmentId = d.DepartmentId -inner join Rank r on r.RankId = p.RankId -where p.PeopleAddress = '武汉'; - - ---3. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资。 -select count(D.DepartmentName)部门员工人数,sum(p.PeopleSalary)员工工资总和,convert(decimal(10,2), -avg(p.PeopleSalary))平均工资,max(p.PeopleSalary)最高工资,min(p.PeopleSalary)最低工资 -from People p -inner join Department d -on p.DepartmentId = d.DepartmentId -group by d.DepartmentName - - ---4. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资,平均工资在10000 以下的不参与统计, ---并且根据平均工资降序排列。 -select count(D.DepartmentName)部门员工人数,sum(p.PeopleSalary)员工工资总和,convert(decimal(10,2), -avg(p.PeopleSalary))平均工资,max(p.PeopleSalary)最高工资,min(p.PeopleSalary)最低工资 -from People p -inner join Department d -on p.DepartmentId = d.DepartmentId -group by d.DepartmentName -having avg(p.PeopleSalary) > 10000 -order by 平均工资 desc - - ---5. 根据部门名称,然后根据职位名称,分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资 -select d.DepartmentName,r.RankName,count(*)员工人数, -sum(p.PeopleSalary)员工工资总和,convert(decimal(10,2), -avg(p.PeopleSalary))平均工资,max(p.PeopleSalary)最高工资,min(p.PeopleSalary)最低工资 -from People p -inner join Department d -on p.DepartmentId = d.DepartmentId -inner join Rank r on r.RankId = p.RankId -group by d.DepartmentName,r.RankName \ No newline at end of file diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\344\275\234\344\270\232/.keep" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\344\275\234\344\270\232/.keep" deleted file mode 100644 index e69de29..0000000 diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\347\254\224\350\256\260/.keep" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\347\254\224\350\256\260/.keep" deleted file mode 100644 index e69de29..0000000 diff --git "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\347\254\224\350\256\260/2022.9.16\347\254\224\350\256\260.md" "b/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\347\254\224\350\256\260/2022.9.16\347\254\224\350\256\260.md" deleted file mode 100644 index 1e7e728..0000000 --- "a/\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/\347\254\224\350\256\260/2022.9.16\347\254\224\350\256\260.md" +++ /dev/null @@ -1,45 +0,0 @@ -# 1.妯$硦鏌ヨ - -```sql -[]锛氫唬琛ㄥ尮閰嶈寖鍥村唴 -[^]锛氫唬琛ㄥ尮閰嶄笉鍦ㄨ寖鍥村唴 -``` - -```sql -select * from Department where DepartmentId like '[1-3]' - -// [1-3] == 1,2,3 - -select * from Department where DepartmentId like '[^1-3]' - -//[^1-3] == 4 -``` - -# 2.CONVERT()涓嶤AST()鍑芥暟: - -```sql - -convert(decimal(13,2),12.45454) -cast(12.45454 as decimal(13,2)) -``` - -# 3.鏃堕棿鍑芥暟 - -```sql -select DATEDIFF(day, '2019-08-20', getDate()); --鑾峰彇鎸囧畾鏃堕棿鍗曚綅鐨勫樊鍊 -SELECT DATEADD(MINUTE,-5,GETDATE()) --鍔犲噺鏃堕棿,姝ゅ涓鸿幏鍙栦簲鍒嗛挓鍓嶇殑鏃堕棿,MINUTE 琛ㄧず鍒嗛挓锛屽彲涓 YEAR,MONTH,DAY,HOUR -select DATENAME(month, getDate()); --褰撳墠鏈堜唤 -select DATENAME(WEEKDAY, getDate()); --褰撳墠鏄熸湡鍑 -select DATEPART(month, getDate()); --褰撳墠鏈堜唤 -select DAY(getDate()); --杩斿洖褰撳墠鏃ユ湡澶╂暟 -select MONTH(getDate()); --杩斿洖褰撳墠鏃ユ湡鏈堟暟 -select YEAR(getDate()); --杩斿洖褰撳墠鏃ユ湡骞存暟 - -SELECT CONVERT(VARCHAR(22),GETDATE(),20) --2020-01-09 14:46:46 -SELECT CONVERT(VARCHAR(24),GETDATE(),21) --2020-01-09 14:46:55.91 -SELECT CONVERT(VARCHAR(22),GETDATE(),23) --2020-01-09 -SELECT CONVERT(VARCHAR(22),GETDATE(),24) --15:04:07 -Select CONVERT(varchar(20),GETDATE(),14) --15:05:49:330 -``` - -# \ No newline at end of file -- Gitee From 6f6f59545fc4214c0bf1d57576dce6a52e3cbec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:04:18 +0000 Subject: [PATCH 3/9] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E6=88=B4=E4=BF=8A?= =?UTF-8?q?=E9=94=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\346\210\264\344\277\212\351\224\213/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\346\210\264\344\277\212\351\224\213/.keep" diff --git "a/\346\210\264\344\277\212\351\224\213/.keep" "b/\346\210\264\344\277\212\351\224\213/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From e893cd2dd5ac3b5b7754c235c52e8a2a1974ea3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:04:56 +0000 Subject: [PATCH 4/9] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\275\234\344\270\232/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/.keep" diff --git "a/\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/.keep" "b/\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 4e70ed534d793e346bfc3b97c6f1dd70fe2b9414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:05:05 +0000 Subject: [PATCH 5/9] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\254\224\350\256\260/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/.keep" diff --git "a/\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/.keep" "b/\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From c1a5826f65f7393dba9eb2f514c9084f45f200d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:05:40 +0000 Subject: [PATCH 6/9] =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 鎴翠繆閿 <379646933@qq.com> --- .../2022.9.15\344\275\234\344\270\232.sql" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" diff --git "a/\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" "b/\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..e112875 --- /dev/null +++ "b/\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" @@ -0,0 +1,71 @@ +--创建数据库 DBTEST +if exists (select * from sys.databases where name = 'DBTEST') +drop database DBTEST +create database DBTEST; + + +--部门信息表(sectionInfo) +-- 部门编号 sectionID int 标识列 主键 +-- 部门名称 sectionName varchar(10) 不能为空 + +create table sectionInfo( + sectionID int primary key identity(1,1), + sectionName varchar(10) not null +) + +insert sectionInfo values('研发'); +insert sectionInfo values('生产'); +insert sectionInfo values('财务'); +insert sectionInfo values('人事'); +insert sectionInfo values('计划'); + +-- select * from sectionInfo; + +--员工信息表(userInfo) +-- 员工编号 userNo int 标识列 主键 不允许为空 +-- 员工姓名 userName varchar(10) 唯一约束 不允许为空 长度必须大于4 +-- 员工性别 userSex varchar(2) 不允许为空 只能是男或女 +-- 员工年龄 userAge int 不能为空 范围在1-100之间 +-- 员工地址 userAddress varchar(50) 默认值为“湖北” +-- 员工部门 userSection int 外键,引用部门信息表的部门编号 + +--drop table userInfo; + +create table userInfo ( + userNo int identity(1,1) primary key not null, + userName varchar(10) unique not null check(len(userName) > 4), + userSex varchar(2) not null check(userSex = '男' or userSex = '女') , + userAge int not null check(userAge between 1 and 100), + userAddress varchar(50) default '湖北', + userSection int references sectionInfo(sectionId) +); + +insert userInfo (userName,userSex,userAge,userAddress,userSection) +values ('张三123','男','25','福建','1'), + ('李四123','女','30','上海','2'), + ('王五123','女','36','上海','3'), + ('赵六123','女','40','广州','4'), + ('11223','女','27','广州','5'); +--select * from userInfo + +--员工考勤表(workInfo) +-- 考勤编号 workId int 标识列 主键 不能为空 +-- 考勤员工 userId int 外键 引用员工信息表的员工编号 不能为空 +-- 考勤时间 workTime datetime 不能为空 +-- 考勤说明 workDescription varchar(40) 不能为空 内容只能是“迟到”,“早退”,“旷工”,“病假”,“事假”中的一种 + +create table workInfo( + workId int identity(1,1) primary key not null, + userId int references userInfo(userNo) not null, + workTime datetime not null, + workDescription varchar(40) not null check(workDescription = '迟到' or workDescription = '早退' or workDescription = '旷工' or workDescription = '病假' or workDescription = '事假') +) +insert workInfo(userId,workTime,workDescription) +values (1,'2022-1-15 15:15:1','迟到'), + (2,'2022-1-16 15:15:1','早退'), + (3,'2022-1-14 15:15:1','旷工'), + (4,'2022-1-16 15:15:1','病假'), + (5,'2022-1-12 15:15:1','事假'); + + +--select * from workInfo \ No newline at end of file -- Gitee From ed423890310350832d94dd5462e97b0c1b5bcddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:06:25 +0000 Subject: [PATCH 7/9] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A--=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 鎴翠繆閿 <379646933@qq.com> --- .../2022.9.16\344\275\234\344\270\232.sql" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/2022.9.16\344\275\234\344\270\232.sql" diff --git "a/\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/2022.9.16\344\275\234\344\270\232.sql" "b/\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/2022.9.16\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..ebf1aee --- /dev/null +++ "b/\346\210\264\344\277\212\351\224\213/\344\275\234\344\270\232/2022.9.16\344\275\234\344\270\232.sql" @@ -0,0 +1,81 @@ +--查询出巨蟹 6.22--7.22 的员工信息 +select * from People +where datename(month,PeopleBirth) = 6 and day(PeopleBirth) between 22 and 30 +or datename(month,PeopleBirth) = 7 and day(PeopleBirth) between 1 and 22; + + +--查询所有员工信息,添加一列显示属相(鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪) +select *, case +when year(PeopleBirth)%12 = 0 +then '猴' +when year(PeopleBirth)%12 = 1 +then '鸡' +when year(PeopleBirth)%12 = 2 +then '狗' +when year(PeopleBirth)%12 = 3 +then '猪' +when year(PeopleBirth)%12 = 4 +then '鼠' +when year(PeopleBirth)%12 = 5 +then '牛' +when year(PeopleBirth)%12 = 6 +then '虎' +when year(PeopleBirth)%12 = 7 +then '兔' +when year(PeopleBirth)%12 = 8 +then '龙' +when year(PeopleBirth)%12 = 9 +then '蛇' +when year(PeopleBirth)%12 = 10 +then '马' +when year(PeopleBirth)%12 = 11 +then '羊' +end '生肖' +from People + + +--1. 查询出武汉地区所有的员工信息,要求显示部门名称以及员工的详细资料 +select p.*,d.DepartmentName from People p +inner join Department d +on p.DepartmentId = d.DepartmentId +where p.PeopleAddress = '武汉'; + + +--2. 查询出武汉地区所有的员工信息,要求显示部门名称,职级名称以及员工的详细资料 +select p.*,d.DepartmentName,r.RankName from People p +inner join Department d +on p.DepartmentId = d.DepartmentId +inner join Rank r on r.RankId = p.RankId +where p.PeopleAddress = '武汉'; + + +--3. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资。 +select count(D.DepartmentName)部门员工人数,sum(p.PeopleSalary)员工工资总和,convert(decimal(10,2), +avg(p.PeopleSalary))平均工资,max(p.PeopleSalary)最高工资,min(p.PeopleSalary)最低工资 +from People p +inner join Department d +on p.DepartmentId = d.DepartmentId +group by d.DepartmentName + + +--4. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资,平均工资在10000 以下的不参与统计, +--并且根据平均工资降序排列。 +select count(D.DepartmentName)部门员工人数,sum(p.PeopleSalary)员工工资总和,convert(decimal(10,2), +avg(p.PeopleSalary))平均工资,max(p.PeopleSalary)最高工资,min(p.PeopleSalary)最低工资 +from People p +inner join Department d +on p.DepartmentId = d.DepartmentId +group by d.DepartmentName +having avg(p.PeopleSalary) > 10000 +order by 平均工资 desc + + +--5. 根据部门名称,然后根据职位名称,分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资 +select d.DepartmentName,r.RankName,count(*)员工人数, +sum(p.PeopleSalary)员工工资总和,convert(decimal(10,2), +avg(p.PeopleSalary))平均工资,max(p.PeopleSalary)最高工资,min(p.PeopleSalary)最低工资 +from People p +inner join Department d +on p.DepartmentId = d.DepartmentId +inner join Rank r on r.RankId = p.RankId +group by d.DepartmentName,r.RankName \ No newline at end of file -- Gitee From 45d501e19fefcb3727391dc7d775d5fefef209f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:06:58 +0000 Subject: [PATCH 8/9] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E7=AC=94?= =?UTF-8?q?=E8=AE=B0--=E5=BB=BA=E5=BA=93=E5=BB=BA=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 鎴翠繆閿 <379646933@qq.com> --- .../2022.9.15\347\254\224\350\256\260.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" diff --git "a/\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" "b/\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" new file mode 100644 index 0000000..1d4f017 --- /dev/null +++ "b/\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" @@ -0,0 +1,53 @@ +# 1.绾︽潫 + +- 涓婚敭绾︽潫 primary key + + ```sql + create table a( + id int primary key identity(1,1) + ) + ``` + + ```sql + alter table 琛ㄥ悕 alter column 涓婚敭鍒楀悕 涓婚敭绫诲瀷 not null; + ``` + + + +- 澶栭敭绾︽潫 foreig key references + +```sql + --淇敼琛ㄧ粨鏋 琛ㄥ悕 add constraint 绾︽潫鍚 foreign key(瑕佸紩鐢ㄧ殑瀛楁) references 涓婚敭琛(瀛楁) + Alter table StuInfo add constraint FK_StuInfo_ClassId foreign key(ClassID) references ClassInfo(ClassID) +``` + +```sql +ClassID int references ClassInfo(ClassID) + ClassID int +``` + +- 榛樿 default + + ```sql + userAddress varchar(50) default '婀栧寳' + ``` + +- 鍞竴 unique + + ```sql + userName varchar(10) unique + ``` + +- check + +- 濡傛灉瀵瑰崟涓垪瀹氫箟 CHECK 绾︽潫锛岄偅涔堣鍒楀彧鍏佽鐗瑰畾鐨勫笺 + + 濡傛灉瀵逛竴涓〃瀹氫箟 CHECK 绾︽潫锛岄偅涔堟绾︽潫浼氬熀浜庤涓叾浠栧垪鐨勫煎湪鐗瑰畾鐨勫垪涓鍊艰繘琛岄檺鍒躲 + + ```sql + userAge int not null check(userAge between 1 and 100) + ``` + + + +- 闈炵┖ not null \ No newline at end of file -- Gitee From df81acdbe22ae07d1a5f08a1f18dfc509c8f94c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Sun, 18 Sep 2022 08:07:32 +0000 Subject: [PATCH 9/9] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E7=AC=94?= =?UTF-8?q?=E8=AE=B0--=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 鎴翠繆閿 <379646933@qq.com> --- .../2022.9.16\347\254\224\350\256\260.md" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/2022.9.16\347\254\224\350\256\260.md" diff --git "a/\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/2022.9.16\347\254\224\350\256\260.md" "b/\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/2022.9.16\347\254\224\350\256\260.md" new file mode 100644 index 0000000..1e7e728 --- /dev/null +++ "b/\346\210\264\344\277\212\351\224\213/\347\254\224\350\256\260/2022.9.16\347\254\224\350\256\260.md" @@ -0,0 +1,45 @@ +# 1.妯$硦鏌ヨ + +```sql +[]锛氫唬琛ㄥ尮閰嶈寖鍥村唴 +[^]锛氫唬琛ㄥ尮閰嶄笉鍦ㄨ寖鍥村唴 +``` + +```sql +select * from Department where DepartmentId like '[1-3]' + +// [1-3] == 1,2,3 + +select * from Department where DepartmentId like '[^1-3]' + +//[^1-3] == 4 +``` + +# 2.CONVERT()涓嶤AST()鍑芥暟: + +```sql + +convert(decimal(13,2),12.45454) +cast(12.45454 as decimal(13,2)) +``` + +# 3.鏃堕棿鍑芥暟 + +```sql +select DATEDIFF(day, '2019-08-20', getDate()); --鑾峰彇鎸囧畾鏃堕棿鍗曚綅鐨勫樊鍊 +SELECT DATEADD(MINUTE,-5,GETDATE()) --鍔犲噺鏃堕棿,姝ゅ涓鸿幏鍙栦簲鍒嗛挓鍓嶇殑鏃堕棿,MINUTE 琛ㄧず鍒嗛挓锛屽彲涓 YEAR,MONTH,DAY,HOUR +select DATENAME(month, getDate()); --褰撳墠鏈堜唤 +select DATENAME(WEEKDAY, getDate()); --褰撳墠鏄熸湡鍑 +select DATEPART(month, getDate()); --褰撳墠鏈堜唤 +select DAY(getDate()); --杩斿洖褰撳墠鏃ユ湡澶╂暟 +select MONTH(getDate()); --杩斿洖褰撳墠鏃ユ湡鏈堟暟 +select YEAR(getDate()); --杩斿洖褰撳墠鏃ユ湡骞存暟 + +SELECT CONVERT(VARCHAR(22),GETDATE(),20) --2020-01-09 14:46:46 +SELECT CONVERT(VARCHAR(24),GETDATE(),21) --2020-01-09 14:46:55.91 +SELECT CONVERT(VARCHAR(22),GETDATE(),23) --2020-01-09 +SELECT CONVERT(VARCHAR(22),GETDATE(),24) --15:04:07 +Select CONVERT(varchar(20),GETDATE(),14) --15:05:49:330 +``` + +# \ No newline at end of file -- Gitee