From cc3bb3e569b858f487968bc87043e90cd3220509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E5=90=AF=E6=81=92?= <3013545725@qq.com> Date: Mon, 19 Sep 2022 05:07:28 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E7=BD=97=E5=90=AF=E6=81=92?= 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 "\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/.keep" diff --git "a/\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/.keep" "b/\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From ef15a8ce7514bac8881c67a2a3b268946fcf9e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E5=90=AF=E6=81=92?= <3013545725@qq.com> Date: Mon, 19 Sep 2022 05:07:42 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BD=97=E5=90=AF=E6=81=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 罗启恒 <3013545725@qq.com> --- ...4\350\256\260\346\237\245\350\257\242.sql" | 86 +++++++++++++++++++ .../2022-9-19 \344\275\234\344\270\232.sql" | 51 +++++++++++ 2 files changed, 137 insertions(+) create mode 100644 "\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/\347\275\227\345\220\257\346\201\222/2022-9-17 \347\254\224\350\256\260\346\237\245\350\257\242.sql" create mode 100644 "\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/\347\275\227\345\220\257\346\201\222/2022-9-19 \344\275\234\344\270\232.sql" diff --git "a/\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/\347\275\227\345\220\257\346\201\222/2022-9-17 \347\254\224\350\256\260\346\237\245\350\257\242.sql" "b/\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/\347\275\227\345\220\257\346\201\222/2022-9-17 \347\254\224\350\256\260\346\237\245\350\257\242.sql" new file mode 100644 index 0000000..d39053c --- /dev/null +++ "b/\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/\347\275\227\345\220\257\346\201\222/2022-9-17 \347\254\224\350\256\260\346\237\245\350\257\242.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 diff --git "a/\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/\347\275\227\345\220\257\346\201\222/2022-9-19 \344\275\234\344\270\232.sql" "b/\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/\347\275\227\345\220\257\346\201\222/2022-9-19 \344\275\234\344\270\232.sql" new file mode 100644 index 0000000..2af99c9 --- /dev/null +++ "b/\347\254\254\344\272\214\346\254\241\347\275\227\345\220\257\346\201\222/\347\275\227\345\220\257\346\201\222/2022-9-19 \344\275\234\344\270\232.sql" @@ -0,0 +1,51 @@ +--1. ѯ人еԱϢҪʾԼԱϸ + +select d.DepartmentName,p.* from People p +inner join Department d on d.DepartmentId=p.DepartmentId +where p.PeopleAddress='人'; +--2. ѯ人еԱϢҪʾƣְԼԱϸ + +select * from People +inner join Department on People.DepartmentId=Department.DepartmentId +inner join Rank on People.RankId=Rank.RankId +where PeopleAddress ='人' + +--3. ݲŷͳԱԱܺͣƽʣ߹ʺ͹ʡ + +select count(*),sum(PeopleSalary)Աܺ,avg(PeopleSalary)ƽ,max(PeopleSalary)߹,min(PeopleSalary)͹ from People +group by DepartmentId +--4. ݲŷͳԱԱܺͣƽʣ߹ʺ͹ʣƽ10000 µIJͳƣҸƽʽС + +select DepartmentName,COUNT(People.DepartmentId)Ա,SUM(PeopleSalary)Աܺ,AVG(PeopleSalary)ƽ,MAX(PeopleSalary)߹,MIN(PeopleSalary)͹ from People +inner join Department on People.DepartmentId=Department.DepartmentId +group by DepartmentName +having AVG(PeopleSalary)>=10000 +order by AVG(PeopleSalary) desc + +--5. ݲƣȻְλƣͳԱԱܺͣƽʣ߹ʺ͹ + +select DepartmentName,RankId,COUNT(People.DepartmentId)Ա,SUM(PeopleSalary)Աܺ,AVG(PeopleSalary)ƽ,MAX(PeopleSalary)߹,MIN(PeopleSalary)͹ from People +inner join Department on People.DepartmentId=Department.DepartmentId +group by RankId,DepartmentName + +--6.ѯз 6.22--7.22 ԱϢ + +select * from People where MONTH(PeopleBirth)+CONVERT(float,DAY(PeopleBirth))/100 between 6.22 and 7.22 + +--7.ѯԱϢһʾ(,ţ,,,,,,,,,,) + +select *, case + when year(PeopleBirth)%12 =0 then '' + when YEAR(PeopleBirth)%12=1then '' + when YEAR(PeopleBirth)%12=2then '' + when YEAR(PeopleBirth)%12=3then '' + when YEAR(PeopleBirth)%12=4then '' + when YEAR(PeopleBirth)%12=5then 'ţ' + when YEAR(PeopleBirth)%12=6then '' + when YEAR(PeopleBirth)%12=7then '' + when YEAR(PeopleBirth)%12=8then '' + when YEAR(PeopleBirth)%12=9then '' + when YEAR(PeopleBirth)%12=10then '' + when YEAR(PeopleBirth)%12=11then '' + end + from People \ No newline at end of file -- Gitee