From bee76af9a1468357ccf47d1d77ed92e459c85635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Fri, 16 Sep 2022 01:06:01 +0000 Subject: [PATCH 01/12] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E6=88=B4=E4=BF=8A?= =?UTF-8?q?=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 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\270\200\357\274\211/.keep" 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" new file mode 100644 index 0000000..e69de29 -- Gitee From 43023aef715a53473df2af797e29cf52037c25e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Fri, 16 Sep 2022 01:06:27 +0000 Subject: [PATCH 02/12] =?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\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/.keep" 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" new file mode 100644 index 0000000..e69de29 -- Gitee From 64da7267e9d20d8699a8cc537a5edf1daa974907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Fri, 16 Sep 2022 01:06:39 +0000 Subject: [PATCH 03/12] =?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\357\274\210\344\270\200\357\274\211/\347\254\224\350\256\260/.keep" 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" new file mode 100644 index 0000000..e69de29 -- Gitee From 66c789a285c3642e7b128453ac93452e0f7c9860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Fri, 16 Sep 2022 01:07:07 +0000 Subject: [PATCH 04/12] =?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\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\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/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/\344\275\234\344\270\232/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/\344\275\234\344\270\232/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\357\274\210\344\270\200\357\274\211/\344\275\234\344\270\232/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 fd65fe67b7dbd5e3ca59bf730e88d6df34dc51a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Fri, 16 Sep 2022 01:07:50 +0000 Subject: [PATCH 05/12] =?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/?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A/2022.9.15=E7=AC=94=E8=AE=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022.9.15\347\254\224\350\256\260.md" | 53 ------------------- 1 file changed, 53 deletions(-) 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\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/\344\275\234\344\270\232/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/\344\275\234\344\270\232/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/\344\275\234\344\270\232/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 e2e157fbc073b8213eadecd8abd765d9b523533e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Fri, 16 Sep 2022 01:08:12 +0000 Subject: [PATCH 06/12] =?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\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" 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" new file mode 100644 index 0000000..e112875 --- /dev/null +++ "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" @@ -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 òϢIJű + +--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 c86f2316ab28473564eff2ac3cc24b6565099af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E4=BF=8A=E9=94=8B?= <379646933@qq.com> Date: Fri, 16 Sep 2022 01:08:31 +0000 Subject: [PATCH 07/12] =?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\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\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/\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" new file mode 100644 index 0000000..1d4f017 --- /dev/null +++ "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" @@ -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 ffb3ec7c4f48241bc5eebfc3387612555aaa1ec3 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 07:52:25 +0000 Subject: [PATCH 08/12] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E6=88=B4=E4=BF=8A?= =?UTF-8?q?=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 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\346\210\264\344\277\212\351\224\213\357\274\210\344\272\214\357\274\211/.keep" 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" new file mode 100644 index 0000000..e69de29 -- Gitee From fab78004b7ac960298db2a9b4f5de88d7d61a8bd 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 07:52:44 +0000 Subject: [PATCH 09/12] =?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\357\274\210\344\272\214\357\274\211/\344\275\234\344\270\232/.keep" 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" new file mode 100644 index 0000000..e69de29 -- Gitee From 1d969e9f5661e95241fadf2f4da7509872dca8f8 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 07:53:18 +0000 Subject: [PATCH 10/12] =?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.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\357\274\210\344\272\214\357\274\211/2022.9.16\344\275\234\344\270\232.sql" 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" new file mode 100644 index 0000000..ebf1aee --- /dev/null +++ "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" @@ -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 4aacc1e7e2efdaf2e4bdf789b6c7046c44227aa4 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 07:53:32 +0000 Subject: [PATCH 11/12] =?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\357\274\210\344\272\214\357\274\211/\347\254\224\350\256\260/.keep" 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" new file mode 100644 index 0000000..e69de29 -- Gitee From bba9b308a41b25ac7c6b339f7864c1f3d5d44189 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 07:54:09 +0000 Subject: [PATCH 12/12] =?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.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\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/\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" new file mode 100644 index 0000000..1e7e728 --- /dev/null +++ "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" @@ -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()与CAST()函数: + +```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