From 279b4bde8eb6d743f1c4f2e1055960f1d5112fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E5=9B=BD=E5=BB=BA?= <168718453@qq.com> Date: Mon, 19 Sep 2022 04:21:39 +0000 Subject: [PATCH 1/2] 9.19 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 卢国建 <168718453@qq.com> --- "\344\275\234\344\270\232/9.19/SQLQuery1.sql" | 65 +++++++++++++++++++ .../9.19/\347\254\224\350\256\260.txt" | 27 ++++++++ 2 files changed, 92 insertions(+) create mode 100644 "\344\275\234\344\270\232/9.19/SQLQuery1.sql" create mode 100644 "\344\275\234\344\270\232/9.19/\347\254\224\350\256\260.txt" diff --git "a/\344\275\234\344\270\232/9.19/SQLQuery1.sql" "b/\344\275\234\344\270\232/9.19/SQLQuery1.sql" new file mode 100644 index 0000000..8280b6d --- /dev/null +++ "b/\344\275\234\344\270\232/9.19/SQLQuery1.sql" @@ -0,0 +1,65 @@ +--1. ѯ人еԱϢҪʾԼԱϸ +select pe.*,de.DepartmentName from Department de +inner join +(select * from People +where PeopleAddress='人') pe on pe.DepartmentId=de.DepartmentId + + + + +--2. ѯ人еԱϢҪʾƣְԼԱϸ +select a.*,R.RankName ְ from [Rank] R +inner join + ( + select pe.*,de.DepartmentName from Department de + inner join + ( + select * from People + where PeopleAddress='人' + ) + pe on pe.DepartmentId=de.DepartmentId + ) a on a.RankId=R.RankId + + +--3. ݲŷͳԱԱܺͣƽʣ߹ʺ͹ʡ +select * from People + + +select count(DepartmentId) ,sum(PeopleSalary) Źܺ,avg(PeopleSalary) ƽ ,max(PeopleSalary) ߹,min(PeopleSalary) ͹ from people +group by DepartmentId + + + + +--4. ݲŷͳԱԱܺͣƽʣ߹ʺ͹ʣƽ10000 µIJͳƣҸƽʽС +select count(DepartmentId) ,sum(PeopleSalary) Źܺ,avg(PeopleSalary) ƽ ,max(PeopleSalary) ߹,min(PeopleSalary) ͹ from people +where peopleSalary>=10000 +group by DepartmentId + + + + +--5. ݲƣȻְλƣͳԱԱܺͣƽʣ߹ʺ͹ + + + +select D.DepartmentName, count(DepartmentName) ,sum(p.PeopleSalary) ܺ,avg(p.PeopleSalary) ƽ,max(p.PeopleSalary) ߹,min(p.PeopleSalary) ͹ from people p +inner join [Rank] R on R.RankId=p.RankId +inner join Department D on D.DepartmentId=D.DepartmentId +group by D.DepartmentName + + + +--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.ѯԱϢһʾ(4,ţ5,6,7,8,9,10,11,0,1,2,3) +--Ϊ꣬2022%12=6,ڵֱַӦ + +select a.*,replace(b.s,0,'') from people a + inner join + (select PeopleId,(year(PeopleBirth)%12) s from people) b on b.PeopleId=a.PeopleId + \ No newline at end of file diff --git "a/\344\275\234\344\270\232/9.19/\347\254\224\350\256\260.txt" "b/\344\275\234\344\270\232/9.19/\347\254\224\350\256\260.txt" new file mode 100644 index 0000000..757784f --- /dev/null +++ "b/\344\275\234\344\270\232/9.19/\347\254\224\350\256\260.txt" @@ -0,0 +1,27 @@ +--创建职级表,rank为系统关键字,此处使用[]代表自定义名字,而非系统关键字 +create table [Rank] +( + RankId int primary key identity(1,1), + RankName nvarchar(50) not null, + RankRemark text +); +go + +--创建员工信息表 +create table People +( + PeopleId int primary key identity(1,1), + --references代表外键引用,此字段必须符合与其它表的外键约束 + DepartmentId int references Department(DepartmentId) not null, + RankId int references [Rank](RankId) not null, + PeopleName nvarchar(50) not null, + --default代表字段默认值; check可以规定字段值的约束条件; + PeopleSex nvarchar(1) default('男') check(PeopleSex='男' or PeopleSex='女') not null, + PeopleBirth datetime not null, + PeopleSalary decimal(12,2) check(PeopleSalary>= 1000 and PeopleSalary <= 100000) not null, + --unique代表唯一约束,为数据提供唯一性保证; + PeoplePhone nvarchar(20) unique not null, + PeopleAddress nvarchar(100), + --datetime和smalldatetime都可以表示时间类型,getdate()用于获取系统当前时间 + PeopleAddTime smalldatetime default(getdate()) +); \ No newline at end of file -- Gitee From 231395cfff34fa8d5a46bb051338c0fc91a3c317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E5=9B=BD=E5=BB=BA?= <168718453@qq.com> Date: Mon, 19 Sep 2022 04:22:27 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=20=E4=B8=BA=20=E5=8D=A2=E5=9B=BD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../9.19/SQLQuery1.sql" | 0 .../9.19/\347\254\224\350\256\260.txt" | 0 .../\344\275\234\344\270\232.sql" | 0 .../\347\254\224\350\256\260.txt" | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename "\344\275\234\344\270\232/9.19/SQLQuery1.sql" => "\345\215\242\345\233\275\345\273\272/9.19/SQLQuery1.sql" (100%) rename "\344\275\234\344\270\232/9.19/\347\254\224\350\256\260.txt" => "\345\215\242\345\233\275\345\273\272/9.19/\347\254\224\350\256\260.txt" (100%) rename "\344\275\234\344\270\232/\344\275\234\344\270\232.sql" => "\345\215\242\345\233\275\345\273\272/\344\275\234\344\270\232.sql" (100%) rename "\344\275\234\344\270\232/\347\254\224\350\256\260.txt" => "\345\215\242\345\233\275\345\273\272/\347\254\224\350\256\260.txt" (100%) diff --git "a/\344\275\234\344\270\232/9.19/SQLQuery1.sql" "b/\345\215\242\345\233\275\345\273\272/9.19/SQLQuery1.sql" similarity index 100% rename from "\344\275\234\344\270\232/9.19/SQLQuery1.sql" rename to "\345\215\242\345\233\275\345\273\272/9.19/SQLQuery1.sql" diff --git "a/\344\275\234\344\270\232/9.19/\347\254\224\350\256\260.txt" "b/\345\215\242\345\233\275\345\273\272/9.19/\347\254\224\350\256\260.txt" similarity index 100% rename from "\344\275\234\344\270\232/9.19/\347\254\224\350\256\260.txt" rename to "\345\215\242\345\233\275\345\273\272/9.19/\347\254\224\350\256\260.txt" diff --git "a/\344\275\234\344\270\232/\344\275\234\344\270\232.sql" "b/\345\215\242\345\233\275\345\273\272/\344\275\234\344\270\232.sql" similarity index 100% rename from "\344\275\234\344\270\232/\344\275\234\344\270\232.sql" rename to "\345\215\242\345\233\275\345\273\272/\344\275\234\344\270\232.sql" diff --git "a/\344\275\234\344\270\232/\347\254\224\350\256\260.txt" "b/\345\215\242\345\233\275\345\273\272/\347\254\224\350\256\260.txt" similarity index 100% rename from "\344\275\234\344\270\232/\347\254\224\350\256\260.txt" rename to "\345\215\242\345\233\275\345\273\272/\347\254\224\350\256\260.txt" -- Gitee