From b08a293dd50aa4f4cd41ec9efb3fb453cf6ee9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=A9=89=E5=A9=B7?= <1029854305@qq.com> Date: Fri, 16 Sep 2022 12:25:28 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E7=AC=94?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 222.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 222.txt diff --git a/222.txt b/222.txt new file mode 100644 index 0000000..e69de29 -- Gitee From e4e1c152f81e4f85fb95e69f339499c1a8cfba61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=A9=89=E5=A9=B7?= <1029854305@qq.com> Date: Sun, 18 Sep 2022 08:25:50 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20222.?= =?UTF-8?q?txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 222.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 222.txt diff --git a/222.txt b/222.txt deleted file mode 100644 index e69de29..0000000 -- Gitee From 900e52c3a936186a8707f0b26e2f00d4d88eddc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=A9=89=E5=A9=B7?= <1029854305@qq.com> Date: Sun, 18 Sep 2022 17:02:05 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E7=AC=94?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\350\241\250\347\264\242\345\274\225.sql" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "19\345\217\267\347\231\275\345\251\211\345\251\267/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" diff --git "a/19\345\217\267\347\231\275\345\251\211\345\251\267/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" "b/19\345\217\267\347\231\275\345\251\211\345\251\267/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" new file mode 100644 index 0000000..3e93527 --- /dev/null +++ "b/19\345\217\267\347\231\275\345\251\211\345\251\267/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" @@ -0,0 +1,59 @@ +--创建数据库 DBTEST +create database DBTEST + +-- 再创建表: +-- 部门信息表(sectionInfo) +-- 部门编号 sectionID int 标识列 主键 +-- 部门名称 sectionName varchar(10) 不能为空 +create table sectionInfo( + sectionID int primary key identity(1,1), + secitonName varchar(10) not null +); + insert sectionInfo (secitonName) + values + ('部门1'),('部门2'),('部门3'),('部门4'),('部门5'); + +select * from sectionInfo + +-- 员工信息表(userInfo) +-- 员工编号 userNo int 标识列 主键 不允许为空 +-- 员工姓名 userName varchar(10) 唯一约束 不允许为空 长度必须大于4 +-- 员工性别 userSex varchar(2) 不允许为空 只能是男或女 +-- 员工年龄 userAge int 不能为空 范围在1-100之间 +-- 员工地址 userAddress varchar(50) 默认值为“湖北” +-- 员工部门 userSection int 外键,引用部门信息表的部门编号 +create table userInfo( + userNo int primary key identity(1,1) 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(len(userAge)<100 or len(userAge)>1), + userAddress varchar(50) default('湖北'), + userSection int foreign key references sectionInfo(sectionID) +) + insert userInfo (userName,userSex,userAge,userAddress,userSection) + values + ('张三三三三','男','35','湖北','1'), + ('李思思思四','女','30','湖南','2'), + ('王五无无五','女','25','广东','3'), + ('六溜刘柳柳','男','22','广西','4'), + ('七一一一一','男','20','河北','5'); + select * from userInfo +-- 员工考勤表(workInfo) +-- 考勤编号 workId int 标识列 主键 不能为空 +-- 考勤员工 userId int 外键 引用员工信息表的员工编号 不能为空 +-- 考勤时间 workTime datetime 不能为空 +-- 考勤说明 workDescription varchar(40) 不能为空 内容只能是“迟到”,“早退”,“旷工”,“病假”,“事假”中的一种 +create table workInfo( + workId int primary key not null identity(1,1), + userId int foreign key 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 + ('11','2001-11-1','迟到'), + ('12','2001-11-1','早退'), + ('13','2001-11-1','旷工'), + ('14','2001-11-1','病假'), + ('15','2001-11-1','事假'); + select * from workInfo \ No newline at end of file -- Gitee From 1f647f64c58cc6b3b202d5a1811a5f602b9de4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=A9=89=E5=A9=B7?= <1029854305@qq.com> Date: Sun, 18 Sep 2022 17:05:46 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E7=AC=94?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "19\345\217\267\347\231\275\345\251\211\345\251\267/SQLQuery1.sql" diff --git "a/19\345\217\267\347\231\275\345\251\211\345\251\267/SQLQuery1.sql" "b/19\345\217\267\347\231\275\345\251\211\345\251\267/SQLQuery1.sql" new file mode 100644 index 0000000..a137807 --- /dev/null +++ "b/19\345\217\267\347\231\275\345\251\211\345\251\267/SQLQuery1.sql" @@ -0,0 +1,67 @@ +--创建数据库 create database 数据库名 +-- database;数据库 +-- create database DBTEST + + +if exists(select * from sys.databases where name='DBTEST') +drop database DBTEST + +create database DBTEST + +--使用数据库 +use DBTEST + +--创建班级表 +create table classInfo( + ClassId int primary key identity(1,1), + ClassName varchar(20) + +) +--插入数据 +insert into ClassInfo (ClassName) values('软件1班'); + +insert classInfo values('软件2班') +select * from classInfo + + +--创建数据表 +create table stuInfo( + stuId int primary key identity(1,1), --学生ID + + --添加检查约束,判断用户插入新增的数据,性别字段性别是不是男或者女 + --default 默认约束 + --check + stugender varchar(2) not null default('男') check(stugender='男'or stugender='女'), --学生性别 bit (位):0 1 汉字占用两个字节 varchar(2)需要2 + stuphone char(11) unique check(len(stuphone)=11), + --创建班级外键 + classID int foreign key references ClassInfo(ClassID) +); + +--增加外键 +--修改表结构 表名 add constraint 约束名 foreign key(引用字段) references 主键表(字段) +Alter table StuInfo add constraint FK_StuInfo_ClassId foreign key (ClassID) references ClassInfo(ClassID) + +--新增姓名列 +alter table StuInfo add stuName varchar(20) + +--如果没给出列名,默认按照顺序一个个添加 +--insert stuInfo values('女',1388888) + +--insert stuInfo (stuphone)values(15888888) + +select * from stuInfo; + +--字符串:char(5),varchar(5),nvarchar(5) 之间区别:占用内存 + + + +--删除表 drop table +drop table stuInfo + +--非空 not null +--约束,自增(表示列) identity(1,1) +--外键 foreign key references +--主键 默认唯一 primary key +--默认 default('') +--唯一 unique +--check检查 check(stugender='男'or stugender='女' \ No newline at end of file -- Gitee From 81338cfb4b2cd2220ba895c926c57490d629d762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=A9=89=E5=A9=B7?= <1029854305@qq.com> Date: Sun, 18 Sep 2022 23:04:09 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022.9.16 \346\237\245\350\257\242.sql" | 68 +++++++++++++++++++ .../SQL Server\345\237\272\347\241\200.md" | 45 ++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 "9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/2022.9.16 \346\237\245\350\257\242.sql" create mode 100644 "9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/SQL Server\345\237\272\347\241\200.md" diff --git "a/9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/2022.9.16 \346\237\245\350\257\242.sql" "b/9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/2022.9.16 \346\237\245\350\257\242.sql" new file mode 100644 index 0000000..9b51e96 --- /dev/null +++ "b/9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/2022.9.16 \346\237\245\350\257\242.sql" @@ -0,0 +1,68 @@ + + +use DBTEST1; + + +--1. 查询出武汉地区所有的员工信息,要求显示部门名称以及员工的详细资料 + +select P.*,d.DepartmentName from People p +join Department d on d.DepartmentId = p.DepartmentId + where PeopleAddress='武汉'; + + +--2. 查询出武汉地区所有的员工信息,要求显示部门名称,职级名称以及员工的详细资料 + +select p.*,d.DepartmentName from People p +join Department d on d.DepartmentId = p.DepartmentId +join Rank r on r.RankId = p.RankId +where PeopleAddress = '武汉'; + + +--3. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资。 + +select COUNT(PeopleId)员工人数,SUM(PeopleSalary)工资总和,AVG(peopleSalary)平均工资,MAX(peopleSalary)最高工资,MIN(peopleSalary)最低工资 from People p +join Department d on d.DepartmentId=p.DepartmentId +group by d.DepartmentId; + + +--4. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资,平均工资在10000 以下的不参与统计,并且根据平均工资降序排列。 +select count(PeopleId)员工人数,SUM(PeopleSalary)工资总和,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People p +join Department d on d.DepartmentId = p.DepartmentId +group by d.DepartmentId +having avg(PeopleSalary) >= 10000 +order by avg(PeopleSalary) desc; + + +--5. 根据部门名称,然后根据职位名称,分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资 +select d.DepartmentName,r.RankName,count(PeopleId)员工人数,SUM(PeopleSalary)工资总和,AVG(PeopleSalary)平均工资,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People p +join Department d on d.DepartmentId = p.DepartmentId +join Rank r on r.RankId = p.RankId +group by d.DepartmentName,r.RankName; + + + +--6.查询出巨蟹 6.22--7.22 的员工信息 +select * from People +where CONCAT(RIGHT(month(PeopleBirth)+100,2),RIGHT(day(PeopleBirth)+100,2)) > '0622' +and CONCAT(RIGHT(month(PeopleBirth)+100,2),RIGHT(day(PeopleBirth)+100,2)) < '0722' + + +--7.查询所有员工信息,添加一列显示属相(鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪) +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 '狗' + else '猪' + end +)属相 +from People; diff --git "a/9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/SQL Server\345\237\272\347\241\200.md" "b/9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/SQL Server\345\237\272\347\241\200.md" new file mode 100644 index 0000000..cc3c97a --- /dev/null +++ "b/9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/SQL Server\345\237\272\347\241\200.md" @@ -0,0 +1,45 @@ +1.SQLServer 2014涓嬭浇: + +https://blog.csdn.net/lililove2000/article/details/115673285 + +2.鍒涘缓鏁版嵁搴 + +```sql +create database 鏁版嵁搴撳悕 +``` + +3.鍒涘缓鏁版嵁琛 + +```sql +create table 琛ㄥ悕( +) +``` + + + +4.鏁版嵁绾︽潫 + +--闈炵┖ not null +--绾︽潫锛岃嚜澧烇紙琛ㄧず鍒楋級 identity(1,1) +--澶栭敭 foreign key references +--涓婚敭 榛樿鍞竴 primary key +--榛樿 default('') +--鍞竴 unique +--check妫鏌 check(stugender='鐢'or stugender='濂' + +5.鎻掑叆鏁版嵁 + +insert into 琛ㄥ悕(鍒楀悕) values('鍐呭'); + +6.淇敼鏁版嵁 + +alter table StuInfo add 琛ㄥ悕 where 鏉′欢 + +7.鍒犻櫎鏁版嵁 + +drop table 琛ㄥ悕 where 鏉′欢 + +8.鏌ヨ鏁版嵁 + +select * from 琛ㄥ悕 + -- Gitee From e2f235bed3615af065a36bc2a1b9a57e6cee53fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=A9=89=E5=A9=B7?= <1029854305@qq.com> Date: Sun, 18 Sep 2022 23:11:54 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 0 ...5\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" | 0 .../2022.9.16 \346\237\245\350\257\242.sql" | 0 .../SQL Server\345\237\272\347\241\200.md" | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename "19\345\217\267\347\231\275\345\251\211\345\251\267/SQLQuery1.sql" => "19\345\217\267\347\231\275\345\251\211\345\251\267/9.15 \345\273\272\345\272\223\345\273\272\350\241\250/SQLQuery1.sql" (100%) rename "19\345\217\267\347\231\275\345\251\211\345\251\267/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" => "19\345\217\267\347\231\275\345\251\211\345\251\267/9.15 \345\273\272\345\272\223\345\273\272\350\241\250/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" (100%) rename "9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/2022.9.16 \346\237\245\350\257\242.sql" => "19\345\217\267\347\231\275\345\251\211\345\251\267/9.16 \346\237\245\350\257\242/2022.9.16 \346\237\245\350\257\242.sql" (100%) rename "9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/SQL Server\345\237\272\347\241\200.md" => "19\345\217\267\347\231\275\345\251\211\345\251\267/9.16 \346\237\245\350\257\242/SQL Server\345\237\272\347\241\200.md" (100%) diff --git "a/19\345\217\267\347\231\275\345\251\211\345\251\267/SQLQuery1.sql" "b/19\345\217\267\347\231\275\345\251\211\345\251\267/9.15 \345\273\272\345\272\223\345\273\272\350\241\250/SQLQuery1.sql" similarity index 100% rename from "19\345\217\267\347\231\275\345\251\211\345\251\267/SQLQuery1.sql" rename to "19\345\217\267\347\231\275\345\251\211\345\251\267/9.15 \345\273\272\345\272\223\345\273\272\350\241\250/SQLQuery1.sql" diff --git "a/19\345\217\267\347\231\275\345\251\211\345\251\267/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" "b/19\345\217\267\347\231\275\345\251\211\345\251\267/9.15 \345\273\272\345\272\223\345\273\272\350\241\250/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" similarity index 100% rename from "19\345\217\267\347\231\275\345\251\211\345\251\267/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" rename to "19\345\217\267\347\231\275\345\251\211\345\251\267/9.15 \345\273\272\345\272\223\345\273\272\350\241\250/\345\273\272\345\272\223\345\273\272\350\241\250\347\264\242\345\274\225.sql" diff --git "a/9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/2022.9.16 \346\237\245\350\257\242.sql" "b/19\345\217\267\347\231\275\345\251\211\345\251\267/9.16 \346\237\245\350\257\242/2022.9.16 \346\237\245\350\257\242.sql" similarity index 100% rename from "9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/2022.9.16 \346\237\245\350\257\242.sql" rename to "19\345\217\267\347\231\275\345\251\211\345\251\267/9.16 \346\237\245\350\257\242/2022.9.16 \346\237\245\350\257\242.sql" diff --git "a/9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/SQL Server\345\237\272\347\241\200.md" "b/19\345\217\267\347\231\275\345\251\211\345\251\267/9.16 \346\237\245\350\257\242/SQL Server\345\237\272\347\241\200.md" similarity index 100% rename from "9.16 19\345\217\267 \347\231\275\345\251\211\345\251\267/SQL Server\345\237\272\347\241\200.md" rename to "19\345\217\267\347\231\275\345\251\211\345\251\267/9.16 \346\237\245\350\257\242/SQL Server\345\237\272\347\241\200.md" -- Gitee