From 47ff0dd98330a03b0c377ac6eb521b92625bbe7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E7=81=BF=E8=8A=B3?= <2409046129@qq.com> Date: Tue, 30 Aug 2022 21:57:12 +0800 Subject: [PATCH] =?UTF-8?q?830=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../8.29 day1\344\275\234\344\270\232.md" | 54 +++++++++++++ .../8.30 day2 \344\275\234\344\270\232.md" | 78 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 "\344\275\234\344\270\232/8.29 day1\344\275\234\344\270\232.md" create mode 100644 "\344\275\234\344\270\232/8.30 day2 \344\275\234\344\270\232.md" diff --git "a/\344\275\234\344\270\232/8.29 day1\344\275\234\344\270\232.md" "b/\344\275\234\344\270\232/8.29 day1\344\275\234\344\270\232.md" new file mode 100644 index 0000000..53287ad --- /dev/null +++ "b/\344\275\234\344\270\232/8.29 day1\344\275\234\344\270\232.md" @@ -0,0 +1,54 @@ +# 8.29 day1作业 + +```sql +create database DBTEST +go +use DBTEST +go +create table sectionInfo( + sectionID int primary key identity(1,1), + sectionName varchar(10) not null +) +go +create table userinfo( + userNo int primary key identity(1,1), + 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>1 and userAge<=100), + userAddress varchar(50) default('湖北'), + userSection int references sectionInfo(sectionID) +) +go +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) check(workDescription='迟到' or workDescription='早退' or workDescription='旷工'or workDescription='病假' or workDescription='事假') +) +go +insert sectionInfo values + ('营销部'), + ('市场部'), + ('销售部'), + ('开发部'), + ('售后部') +go +insert userinfo values + ('aaaaa','女',20,'江西','1'), + ('bbbbb','女',20,'江西','1'), + ('ccccc','女',20,'江西','1'), + ('ddddd','女',20,'江西','1'), + ('eeeee','女',20,'江西','1') +go +insert workInfo values + (13,'2022/2/2','迟到'), + (14,'2022/2/2','迟到'), + (15,'2022/2/2','迟到'), + (16,'2022/2/2','迟到'), + (17,'2022/2/2','迟到') + +select * from sectionInfo +select * from userinfo +select * from workInfo +``` + diff --git "a/\344\275\234\344\270\232/8.30 day2 \344\275\234\344\270\232.md" "b/\344\275\234\344\270\232/8.30 day2 \344\275\234\344\270\232.md" new file mode 100644 index 0000000..1883762 --- /dev/null +++ "b/\344\275\234\344\270\232/8.30 day2 \344\275\234\344\270\232.md" @@ -0,0 +1,78 @@ +# 8.30 day2 作业 + +```sql +--1. 查询所有行所有列 +select * from People +--2. 指定列查询(姓名,性别,月薪,电话) +select PeopleName,PeopleSex,PeopleSalary,PeoplePhone from People +--3. 指定列查询,并自定义中文列名(姓名,性别,月薪,电话) +select PeopleName 姓名,PeopleSex 性别,PeopleSalary 月薪,PeoplePhone 电话 from People +--4. 查询公司员工所在城市(不需要重复数据) +select distinct PeopleAddress from People +--5. 假设工资普调10%,查询原始工资和调整后的工资,显示(姓名,性别,月薪,加薪后的月薪)(添加列查询)。 +select PeopleName,PeopleSex,PeopleSalary,PeopleSalary*1.1 调整后 from People +--1. 根据指定列(姓名,性别,月薪,电话)查询性别为女的员工信息,并自定义中文列名 +select PeopleName,PeopleSex,PeopleSalary,PeoplePhone from People +where PeopleSex='女' +--2. 查询月薪大于等于10000 的员工信息( 单条件 ) +select PeopleName,PeopleSex,PeopleSalary,PeoplePhone from People +where PeopleSalary >10000 +--3. 查询月薪大于等于10000 的女员工信息(多条件) +select PeopleName,PeopleSex,PeopleSalary,PeoplePhone from People +where PeopleSex='女' and PeopleSalary >10000 +--4. 显示出出身年月在1980-1-1之后,而且月薪大于等于10000的女员工信息。 +select * from People +where PeopleSex='女' and PeopleSalary >10000 and PeopleBirth>1980-1-1 +--5. 显示出月薪大于等于15000 的员工,或者月薪大于等于8000的女员工信息。 +select * from People where PeopleSalary >= 15000 or PeopleSalary >8000 and PeopleSex='女' +--6. 查询月薪在10000-20000 之间员工信息( 多条件 ) +select * from people where PeopleSalary >=10000 and PeopleSalary <= 20000 +--7. 查询出地址在北京或者上海的员工信息 +select * from People where PeopleAddress ='北京' or PeopleAddress='上海' +--8. 查询所有员工信息(根据工资排序,降序排列) +select * from People +order by PeopleSalary desc +--9. 显示所有的员工信息,按照名字的长度进行倒序排列 +select * from People +order by len(PeopleName) desc +--10. 查询工资最高的5个人的信息 +select top 5 * from People +order by PeopleSalary desc +--11. 查询工资最高的10%的员工信息 + +--12. 查询出地址没有填写的员工信息 +select * from People where PeopleAddress is null +--13. 查询出地址已经填写的员工信息 +select * from People where PeopleAddress is not null +--14. 查询所有的80后员工信息 +select * from People +where PeopleBirth>1980-1-1 +--15. 查询年龄在30-40 之间,并且工资在15000-30000 之间的员工信息 +select * from people +where (YEAR(GETDATE())-YEAR(PeopleBirth)) between 30 and 40 +--16. 查询出巨蟹 6.22--7.22 的员工信息 +select * from People where (MONTH(PeopleBirth)=6 and day(PeopleBirth)>=22)or (month(PeopleBirth)=7 and day(PeopleBirth)<=22) +--17. 查询工资比赵云高的人 +select * from People where PeopleSalary > (select PeopleSalary from People where PeopleName = '赵云') +--18. 查询出和赵云在同一个城市的人 +select * from People where PeopleAddress = (select PeopleAddress from People where PeopleName = '赵云') +--19. 查询出生肖为鼠的人员信息 +select * from people where (year(PeopleBirth)%12)-3 =1 +--20. 查询所有员工信息,添加一列显示属相(鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪) +select *, + case + when (year(peoplebirth)%12)-3 =1 then '鼠' + when (year(peoplebirth)%12)-3 =2 then '牛' + when (year(peoplebirth)%12)-3 =3 then '虎' + when (year(peoplebirth)%12)-3 =4 then '兔' + when (year(peoplebirth)%12)-3 =5 then '龙' + when (year(peoplebirth)%12)-3 =6 then '蛇' + when (year(peoplebirth)%12)-3 =7 then '马' + when (year(peoplebirth)%12)-3 =8 then '羊' + when (year(peoplebirth)%12)-3 =9 then '猴' + when (year(peoplebirth)%12)-3 =10 then '鸡' + when (year(peoplebirth)%12)-3 =11 then '狗' + when (year(peoplebirth)%12)-3 =12 then '猪' + else '' end 生肖 from People +``` + -- Gitee