diff --git "a/\345\215\242\345\233\275\345\273\272/9.19/SQLQuery1.sql" "b/\345\215\242\345\233\275\345\273\272/9.19/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..8280b6dfc7a27f150d872350679f274fe2e8189b --- /dev/null +++ "b/\345\215\242\345\233\275\345\273\272/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 以下的不参与统计,并且根据平均工资降序排列。 +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/\345\215\242\345\233\275\345\273\272/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" new file mode 100644 index 0000000000000000000000000000000000000000..757784f225f2b0b02665d3428219875e915e407d --- /dev/null +++ "b/\345\215\242\345\233\275\345\273\272/9.19/\347\254\224\350\256\260.txt" @@ -0,0 +1,27 @@ +--鍒涘缓鑱岀骇琛紝rank涓虹郴缁熷叧閿瓧锛屾澶勪娇鐢╗]浠h〃鑷畾涔夊悕瀛楋紝鑰岄潪绯荤粺鍏抽敭瀛 +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浠h〃澶栭敭寮曠敤,姝ゅ瓧娈靛繀椤荤鍚堜笌鍏跺畠琛ㄧ殑澶栭敭绾︽潫 + DepartmentId int references Department(DepartmentId) not null, + RankId int references [Rank](RankId) not null, + PeopleName nvarchar(50) not null, + --default浠h〃瀛楁榛樿鍊; 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浠h〃鍞竴绾︽潫锛屼负鏁版嵁鎻愪緵鍞竴鎬т繚璇; + PeoplePhone nvarchar(20) unique not null, + PeopleAddress nvarchar(100), + --datetime鍜宻malldatetime閮藉彲浠ヨ〃绀烘椂闂寸被鍨嬶紝getdate()鐢ㄤ簬鑾峰彇绯荤粺褰撳墠鏃堕棿 + PeopleAddTime smalldatetime default(getdate()) +); \ No newline at end of file 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"