From 913d4ab9c9c9d61c5466f256455b88a79c561bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Thu, 15 Sep 2022 17:31:30 +0000 Subject: [PATCH 01/10] =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张耀仁 <1579614208@qq.com> --- ...0\344\273\201\344\275\234\344\270\232.sql" | 48 ++++++++++++ ...2\350\241\250\347\272\246\346\235\237.sql" | 78 +++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 "\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" create mode 100644 "\345\274\240\350\200\200\344\273\201\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" diff --git "a/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" "b/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..d04ca45 --- /dev/null +++ "b/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" @@ -0,0 +1,48 @@ +--ݿ DBTEST +create database DBTEST; +--ʹݿ +use dbtest; +--Ϣ +create table sectioninfo( + sectionID int primary key identity(1,1), + sectionName varchar(10) not null +); +--ԱϢ +create table userinfo( + userNo int primary key identity(1,1) not null, + userName varchar(10) not null unique check(len(userName)>4), + userSex varchar(2) not null default('') check(userSex='' or userSex='Ů'), + userAge int not null check(userAge between 1 and 100), + userAddress varchar(50) default(''), + userSection INT +); +--Աڱ +create table workinfo( + workId int primary key identity(1,1), + userId int references userinfo(userNo) not null , + workTime datetime not null, + workDescription varchar(40) not null check(workDescription in('ٵ','','','','¼')) +); +Alter table workInfo add constraint FK_workInfo_ClassId foreign key(userId) references userInfo(userNo); +-- +insert into sectionInfo(sectionName) values + (''), + ('в'), + ('²'), + ('߻'), + (''); +select * from sectionInfo; +insert into userInfo(userName,userSex,userAge,userAddress,userSection) values + ('֣Դ','',8,'Ȫ',1), + ('ӱ','',9,'',2), + ('Ԭɭ','Ů',25,'ɽ',3), + ('С','',38,'δ֪',4), + ('С','',15,'δ֪',5); +select * from userInfo; +insert into workInfo(userId,workTime,workDescription) values + (1,'2022-01-05 15:25:46','ٵ'), + (2,'2022-02-15 16:44:44',''), + (3,'2022-03-29 12:25:46',''), + (4,'2022-04-25 08:45:46',''), + (5,'2022-06-18 19:25:46','¼'); +select * from workInfo; \ No newline at end of file diff --git "a/\345\274\240\350\200\200\344\273\201\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" "b/\345\274\240\350\200\200\344\273\201\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" new file mode 100644 index 0000000..526c95e --- /dev/null +++ "b/\345\274\240\350\200\200\344\273\201\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" @@ -0,0 +1,78 @@ +--ϵݿ:SQL server, Mysql, Oracle +--ݿ⣺create database ݿ +--database:ݿ + +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] (ֶ) values(ֵ) + insert into ClassInfo( ClassName) values('1'); + + insert ClassInfo values('2') + + select * from ClassInfo + + --ݱ + create table StuInfo( + stuId int primary key identity(1001,1), --ѧID + --һԼжû/ݣԱֶDzлŮ + --default:ĬԼ + --check + stugender varchar(2) not null default('') check(stugender='' or stugender='Ů'), --ѧԱ + stuphone char(11) check(len(stuphone)=11) unique, + --༶ + --ClassID int references ClassInfo(ClassID) + ClassID int + + ); + + + -- + --޸ıṹ 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('Ů',13888888888) + + --insert StuInfo(stuphone) values(15888888888) + + + + select * from StuInfo; + + --ַchar(5),varchar(5),nvarchar(5)֮ʲô + + + + --ɾ:drop table + drop table StuInfo + + + --ǿ + + --Լ(ʶ) + + -- + --ĬΨһ + --Ĭ + --Ψһ + --check: + + --ݣinsert into \ No newline at end of file -- Gitee From 516a711bdaa91249955f4f38b9ae2f235fa720db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:27:18 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张耀仁 <1579614208@qq.com> --- "0918\344\275\234\344\270\232.sql" | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "0918\344\275\234\344\270\232.sql" diff --git "a/0918\344\275\234\344\270\232.sql" "b/0918\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..ebf1aee --- /dev/null +++ "b/0918\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 µIJͳƣ +--ҸƽʽС +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 266302e32c1d5c2de94bb27c4e68dd803e579101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:27:48 +0000 Subject: [PATCH 03/10] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20=E5=BC=A0?= =?UTF-8?q?=E8=80=80=E4=BB=81=E4=BD=9C=E4=B8=9A=20=E4=B8=BA=200915?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" => "0915\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" (100%) diff --git "a/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" "b/0915\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" similarity index 100% rename from "\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" rename to "0915\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" -- Gitee From ca783cdf84cfbcc06f5239b05addd41e199ba8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:28:03 +0000 Subject: [PATCH 04/10] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20=E5=BC=A0?= =?UTF-8?q?=E8=80=80=E4=BB=81=E7=AC=94=E8=AE=B0=20=E4=B8=BA=200915?= =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "\345\274\240\350\200\200\344\273\201\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" => "0915\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" (100%) diff --git "a/\345\274\240\350\200\200\344\273\201\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" "b/0915\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" similarity index 100% rename from "\345\274\240\350\200\200\344\273\201\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" rename to "0915\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" -- Gitee From 234f8237ac1b373ecb35e48182ac6aa4920bfa30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:36:00 +0000 Subject: [PATCH 05/10] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=200915?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=20=E4=B8=BA=2040=E5=BC=A0=E8=80=80=E4=BB=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "0915\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" => "40\345\274\240\350\200\200\344\273\201/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" (100%) diff --git "a/0915\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" "b/40\345\274\240\350\200\200\344\273\201/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" similarity index 100% rename from "0915\344\275\234\344\270\232/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" rename to "40\345\274\240\350\200\200\344\273\201/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" -- Gitee From 28be31383e41cb8179581dc582e31b82b331c76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:36:16 +0000 Subject: [PATCH 06/10] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=200915?= =?UTF-8?q?=E7=AC=94=E8=AE=B0=20=E4=B8=BA=20=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "0915\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" => "\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" (100%) diff --git "a/0915\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" "b/\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" similarity index 100% rename from "0915\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" rename to "\347\254\224\350\256\260/2022-09-15-\345\273\272\345\272\223\345\273\272\350\241\250\347\272\246\346\235\237.sql" -- Gitee From 2a051b2a430ce60db494942d31ad0d9536c9b027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:36:32 +0000 Subject: [PATCH 07/10] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=2040=E5=BC=A0?= =?UTF-8?q?=E8=80=80=E4=BB=81/=E5=BC=A0=E8=80=80=E4=BB=81=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A.sql=20=E4=B8=BA=2040=E5=BC=A0=E8=80=80=E4=BB=81/0915?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0915\344\275\234\344\270\232.sql" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "40\345\274\240\350\200\200\344\273\201/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" => "40\345\274\240\350\200\200\344\273\201/0915\344\275\234\344\270\232.sql" (100%) diff --git "a/40\345\274\240\350\200\200\344\273\201/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" "b/40\345\274\240\350\200\200\344\273\201/0915\344\275\234\344\270\232.sql" similarity index 100% rename from "40\345\274\240\350\200\200\344\273\201/\345\274\240\350\200\200\344\273\201\344\275\234\344\270\232.sql" rename to "40\345\274\240\350\200\200\344\273\201/0915\344\275\234\344\270\232.sql" -- Gitee From 4192e260a2ca0cdbd0ea88d4b3bb6ab25bb17060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:36:55 +0000 Subject: [PATCH 08/10] =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张耀仁 <1579614208@qq.com> --- .../0918\344\275\234\344\270\232.sql" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "40\345\274\240\350\200\200\344\273\201/0918\344\275\234\344\270\232.sql" diff --git "a/40\345\274\240\350\200\200\344\273\201/0918\344\275\234\344\270\232.sql" "b/40\345\274\240\350\200\200\344\273\201/0918\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..ebf1aee --- /dev/null +++ "b/40\345\274\240\350\200\200\344\273\201/0918\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 µIJͳƣ +--ҸƽʽС +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 5dbab9b5e4a9223c63b2aa0c1c98844a585d57d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:37:11 +0000 Subject: [PATCH 09/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2009?= =?UTF-8?q?18=E4=BD=9C=E4=B8=9A.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "0918\344\275\234\344\270\232.sql" | 81 ------------------------------ 1 file changed, 81 deletions(-) delete mode 100644 "0918\344\275\234\344\270\232.sql" diff --git "a/0918\344\275\234\344\270\232.sql" "b/0918\344\275\234\344\270\232.sql" deleted file mode 100644 index ebf1aee..0000000 --- "a/0918\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 µIJͳƣ ---ҸƽʽС -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 d04ce00628d8c655868ddbd8763d8d29f80dd2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= <1579614208@qq.com> Date: Sun, 18 Sep 2022 15:39:52 +0000 Subject: [PATCH 10/10] =?UTF-8?q?=E5=BC=A0=E8=80=80=E4=BB=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张耀仁 <1579614208@qq.com> --- .../0916\347\254\224\350\256\260.sql" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "\347\254\224\350\256\260/0916\347\254\224\350\256\260.sql" diff --git "a/\347\254\224\350\256\260/0916\347\254\224\350\256\260.sql" "b/\347\254\224\350\256\260/0916\347\254\224\350\256\260.sql" new file mode 100644 index 0000000..d39053c --- /dev/null +++ "b/\347\254\224\350\256\260/0916\347\254\224\350\256\260.sql" @@ -0,0 +1,86 @@ +--ѯ˾ԱڳУҪظݣ +--distinct +select distinct PeopleAddress from People + +--ѯԱϢ(ݹ(order by)) +select * from People order by PeopleSalary desc + + +--ѯ1980ԺԱϢ +select * from People where year(PeopleBirth)>=1980 + + +--ѯз 6.22--7.22 ԱϢ + +--ѯͬһе + + +select * from People where PeopleAddress=(select peopleAddress from People where PeopleName='') + +--ѯ绰뿪ͷ138ԱϢ,4λ78 һ5 +select * from people +where PeoplePhone like '138[7-9]%5' --789 + +--ѯ绰뿪ͷ133ԱϢ,4λ2-5֮ һ벻23 +select * from people +where PeoplePhone like '138[2-5]%[^23]' + + +--ƽߵԱϢ +--ƽ䣺- +select avg(year(getdate())-year(peoplebirth)) ƽ from People + +select * from people where (year(getdate())-year(peoplebirth))>(select avg(year(getdate())-year(peoplebirth)) ƽ from People) + +--ƽ +select avg(PeopleSalary) ƽ from People + +--С2λ +--round(С,λ) +select round(avg(PeopleSalary),2) ƽ from People + +--convert 02154.13200 decimal(5,2):С2λЧܹ5 + +--convertcast ǿת +select convert(decimal(13,2),avg(PeopleSalary)) ƽ from People + +--cast +select cast(avg(PeopleSalary) as decimal(13,2)) ƽ from People + + +--ԱڵͳԱԱܺͣƽʣ߹ʺ͹ʣ +--ҪɸѡԱ2˼ϵļ¼1985꼰ԺԱͳơ +--count(*):ֵҲͳ count(ֶ)ǰֶεĿֵͳ +select count(*) Ա,sum(PeopleSalary) ܺ, max(PeopleSalary) ߹,min(PeopleSalary) ͹ from People +where year(PeopleBirth)<1985 +group by PeopleAddress +having count(*)>=2 + + +--ɾ +delete from People where PeopleName='ţ' + +--ɾ +--drop ɾű +--truncateɾű + +--ݲŷͳԱԱܺͣƽʣ߹ʺ͹ʣƽ10000 µIJͳƣҸƽʽС +select count(*) Ա, sum(PeopleSalary) Աܺ,convert(decimal(15,2),avg(PeopleSalary)) ƽ from Department de +join People po on de.DepartmentId = po.DepartmentId +group by po.DepartmentId having avg(PeopleSalary)>=10000 +order by ƽ desc + +create table B( + cid int primary key, + cname varchar(20) +) + + +create table A( + sid int, + sname varchar(10), + cid int references B(cid) +) + +select * from A +left join B on A.cid=B.cid \ No newline at end of file -- Gitee