diff --git "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243 (2).txt" "b/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/.keep" similarity index 100% rename from "\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243 (2).txt" rename to " 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2321/.keep" similarity index 100% rename from "\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" rename to " 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2321/.keep" diff --git "a/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2321/SQLQuery1.sql" "b/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2321/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..ae1c1113053d702a7b8e2a6fb530de2132dd1fc7 --- /dev/null +++ "b/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2321/SQLQuery1.sql" @@ -0,0 +1,77 @@ +create database LSY + +use LSY + +--学生信息表(stuInfo) +create table stuinfo( +stuID int primary key identity, +stuName nvarchar(30), +stuAge int, +stuSex int, +time date +) +--课程信息表(courseInfo) +create table courseinfo( +courseID int primary key identity, +courseName nvarchar(30), +courseMarks int +) +--分数信息表(scoreInfo) +create table scoreinfo( +scoreID int primary key identity, +stuID int references stuinfo(stuID), +courseID int references courseinfo(courseID), +score int +) + +--插入数据 +insert into stuinfo(stuName,stuAge,stuSex,time) +values('Tom',19,1,null),('Jack',20,0,null),('Rose',21,1,null), + ('Lulu',19,1,null),('Lili',21,0,null),('abc',20,1,'2007-01-07 01:11:36.590') + +insert into courseinfo(courseName,courseMarks) +values('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) + +insert into scoreinfo(stuID,courseID,score) +values(1,1,80),(1,2,85),(1,4,50),(2,1,75), +(2,3,45),(2,4,75),(3,1,45),(4,1,95), +(4,2,75),(4,3,90),(4,4,45) + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuinfo.stuID 编号,stuname 姓名,count(courseid)选修的课程数量,avg(score)所选修的课程的考试的平均分 from stuinfo +join scoreinfo on stuinfo.stuID=scoreinfo.scoreID +group by stuinfo.stuID,stuname +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName 课程名称,count(scoreinfo.courseid)每门课程的选修的学生的个数,sum(score)学生考试的总分 from scoreinfo +join courseinfo on courseinfo.courseID=scoreinfo.courseID +group by courseName +--3.查询出性别一样并且年龄一样的学生的信息 +select one.stuid,one.stuname,one.stuage,one.stusex from stuinfo one +inner join stuinfo two on one.stusex=two.stusex and one.stuAge=two.stuage +where one.stuID!=two.stuid +--4.查询出学分一样的课程信息 +select distinct one.courseid,one.coursename,one.coursemarks from courseinfo one +join courseinfo two on one.courseMarks=two.courseMarks +where one.courseid!=two.courseID +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuinfo.stuid,stuinfo.stuName,scoreinfo.courseID,scoreinfo.score from stuinfo +join scoreinfo on stuinfo.stuID=scoreinfo.stuID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuinfo.stuID,stuinfo.stuName ,scoreinfo.courseID,courseinfo.courseMarks, scoreinfo.score from stuinfo +left join scoreinfo on stuinfo.stuID=scoreinfo.stuID +left join courseinfo on courseinfo.courseID=scoreinfo.courseID +where score is not null +--7.查询出没有参加考试的学生的学号和姓名 +select stuinfo.stuID,stuinfo.stuName from stuinfo +left join scoreinfo on stuinfo.stuID=scoreinfo.stuID +where score is null +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from stuinfo where stuinfo.stuName like'%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuinfo.stuID,avg(score) 考试平均分,count(courseinfo.courseid) 选修课程的数量 from stuinfo +join scoreinfo on scoreinfo.stuID=stuinfo.stuID +join courseinfo on courseinfo.courseID=scoreinfo.courseID +group by stuinfo.stuID +having avg(score)>70 and count(courseinfo.courseid)>2 \ No newline at end of file diff --git "a/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2322/.keep" "b/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2322/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2322/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\272\214wan.sql" "b/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2322/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\272\214wan.sql" new file mode 100644 index 0000000000000000000000000000000000000000..2296c15a877ef73138257c9bf8317e665e26f059 --- /dev/null +++ "b/ 37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214 \344\275\234\344\270\2322/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\272\214wan.sql" @@ -0,0 +1,69 @@ +create database wangba; + +use wangba; + +create table tbl_card( +id nvarchar(50) primary key , +password char(50) , +balance bigint , +usename nvarchar(50)); + +create table tbl_computer( +id varchar(10) primary key , +onuse int, +note int ); +create table tbl_record( +id int primary key , +cardid char(50) , +computerid varchar(10), +begintime date, +endtime date, +fee int ); + + + + +/*查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列*/ +select usename,tbl_card.id ,tbl_computer.id,begintime ,endtime ,fee from tbl_card join tbl_computer on tbl_card.id=tbl_computer.id join tbl_record on tbl_card.id=tbl_record.id +group by usename,tbl_card.id ,tbl_computer.id,begintime ,endtime ,fee +order by fee desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select sum(fee) zongjine ,count(onuse) from tbl_computer join tbl_record on tbl_computer.id=tbl_record.computerid + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select sum(fee) , onuse from tbl_computer join tbl_record on tbl_computer.id=tbl_record.computerid +where onuse=1 +group by onuse + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select sum(fee) , onuse from tbl_computer join tbl_record on tbl_computer.id=tbl_record.computerid +where onuse=0 +group by onuse + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card as a, tbl_card as b where a.password=b.usename; +--6. 查询出使用次数最多的机器号和使用次数 + + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select * from tbl_card,tbl_computer,tbl_record where tbl_card.id like '%ABC%' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.usename,tbl_computer.id, sum(fee) as '总费用' +from tbl_card,tbl_computer,tbl_record +where tbl_card.id=tbl_computer.id and tbl_card.id=tbl_record.id +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select * from tbl_card a,上机登记表 b where a.卡号=b.卡号 +and 时间>='00:00:01' and 时间<='23:59:59' + + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select top 3 * from tbl_card,tbl_computer,tbl_record + + + +*/ + + + diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/37/lenovo20230217214915.png" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/37/lenovo20230217214915.png" new file mode 100644 index 0000000000000000000000000000000000000000..2a1af1b26fadda23a2bb3ef3da8453f12934f988 Binary files /dev/null and "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/37/lenovo20230217214915.png" differ diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..beb69327701e9b9e81831347d9dc8fdd8d1c5435 --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" @@ -0,0 +1,126 @@ +create database Student +go + +use Student +go + +create table Class( + ClassId int primary key identity,--班级编号 + ClassName nvarchar(20) --班级名称 +); +go +create table student( + studentId int primary key identity, --学生编号 + studentName nvarchar(50), --学生姓名 + studentSex tinyint not null, --学生性别 + studentBirth date, --出生日期 + studentAddress nvarchar(255) not null,--地址 + classId int --班级编号 +); +insert into Class(ClassName) +values ('软件一班'),('软件二班'),('计算机应用技术班') +select * from Class + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区',1); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +( '钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3); + +insert into student(studentName, studentSex, studentBirth, studentAddress) +values ('东方不败',3,'1999-12-11' ,'河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1 ,'2000-08-11', '陕西省渭南市华阴市玉泉路南段'); +select * from student + +create table course ( +courseid int primary key identity , --课程编号 +coursename nvarchar(50) not null, --课程名称 +coutsecredit tinyint not null default 0 --课程学分 +); + +create table classcourse( +classcourseid int primary key identity, --自增编号 +classid int references class(classid), --班级编号 +courseid int references course(courseid) --课程编号 +); + +create table score ( +scoreid int primary key identity , --自增编号 +studentid int not null references student(studentid), --学生编号 +courseid int references course(courseid), --课程编号 +score int not null --分数 +); + +insert into course( coursename, coutsecredit) +values ('数据库高级应用',3), + ('javascript编程基础',3), + ('web前端程序设计基础',4), + ('动态网页设计.net基础',6), + ('动态网页设计php基础',6) +select *from course + +insert into classcourse(classid, courseid) +values (1,1),(1,2),(1,3),(1,4), + (2,1),(2,2),(2,3),(2,4), + (3,1),(3,2),(3,3),(3,5) + +insert into score( studentid, courseid, score) +values (1,1,80),(1,2,78),(1,3,65),(1,4,90), +(2,1,60),(2,2,77),(2,3,68),(2,4,88), +(3,1,88),(3,2,45),(3,3,66),(3,4,75), +(4,1,56),(4,2,80),(4,3,75),(4,4,66), +(5,1,88),(5,2,79),(5,3,72),(5,4,85), +(6,1,68),(6,2,88),(6,3,73),(6,5,63), +(7,1,84),(7,2,90),(7,3,92),(7,5,78), +(8,1,58),(8,2,59),(8,3,65),(8,5,75), +(9,1,48),(9,2,67),(9,3,71),(9,5,56),(9,1,48) +select * from score + +--1.分数表这边 李逍遥 数据库高级应用 成绩 插入重复了,请帮忙删除其中一条数据 +delete from score where scoreid=37 +select * from score + +--2.计算机应用技术班 的 欧阳天天 生日写错了,正确的生日应该是:2000-04-06,请用sql进行修改。 +update student set studentBirth='2000-04-06' +where studentId=7 +select * from student + +--3.计算机应用技术班的徐长卿的javascript编程基础分数填错,正确的分数应该是:61,请用sql进行修改。 +update score set score=61 +where studentid=8 and courseid=2; +select * from score + +--查询信息 +--1. 查询所有的班级 Class 信息。 +select * from Class +--2. 查询所有的学生 Student 信息。 +select * from Student +--3. 查询所有的课程 Course 信息。 +select * from Course +--4. 查询所有的班级课程 ClassCourse 信息。 +select * from ClassCourse +--5. 查询所有的分数 Score 信息。 +select * from Score +--6. 只查询学生的姓名和地址信息。 +select studentName,studentADDress from Student +--7. 查询获取学生信息表中20%的学生信息。 +select top 20 percent * from Student +--8. 查询学生信息表中的班级编号有哪些(去除重复值)。 +select distinct classId from Student +--9. 查询分数表中有成绩的学生编号; +select distinct studentid from Score +--10. 查询所有的课程 Course 信息,并且按照学分从大到小排列。 +select * from Course order by coutsecredit desc +--11. 查询所有的分数 Score 信息,并且按照分数从小到大排列。 +select * from Score order by score asc +--12. 查询所有的学生 Student 信息,并且按照年龄从小到大排列。 +select * from Student order by studentBirth asc \ No newline at end of file diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\242\201\350\257\227\351\233\250/SQLQuery1.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\242\201\350\257\227\351\233\250/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..f33a313027321329ab61f56b0f23a5c6552fc972 --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\242\201\350\257\227\351\233\250/SQLQuery1.sql" @@ -0,0 +1,37 @@ +create database STUDENT + +use STUDENT + +CREATE TABLE CLASS +( +CLASSID int identity not null primary key , --班级编号 +classname nvarchar(50) not null , --班级名称 +) + +create table Student( +Studentld int identity not null primary key , --班级编号 +StudentName nvarchar(50) not null , --学生名字 +StudentSex tinyint not null default 3 , --学生性别 +StudentBirth date , --学生生日 +StudentAddress nvarchar(255) not null , --学生地址 +Classld int not null , --所属班级id +) + +create table Course( +CourseId int identity not null primary key , --课程编号 +CourseName nvarchar(50) not null , --课程名称 +CourseCredit tinyint not null default 0 , --课程学分 +) + +create table ClassCourse( +ClassCourseId int identity not null primary key , --自增编号 +ClassId int not null , --班级编号 +CourseId int not null , --课程编号 +) + +create table Score( +ScoreId int identity not null primary key , --自增编号 +StudentId int not null , --学生编号 +CourseId int not null , --课程编号 +Score int not null , --分数 +) \ No newline at end of file diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322" new file mode 100644 index 0000000000000000000000000000000000000000..d177c3d6260996120c11709db9f8631388c66a67 --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322" @@ -0,0 +1,76 @@ +create database STUDENT ; +go +use STUDENT; +go +create table ORDERS ( +orderId int not null primary key identity , +orderdate nvarchar(50) not null +); + +create table ORDERITEM ( +itemid int not null identity , +orderid int not null , +itemtype nvarchar(50) not null , +itemname nvarchar(50) not null , +thenumber int not null , +themoney int not null ); + +insert into orders(orderdate) +values('2008-01-12 00:00:00.000'), + ('2008-02-10 00:00:00.000'), + ('2008-02-15 00:00:00.000'), + ('2008-03-10 00:00:00.000') +select * from ORDERS + +insert into orderitem(orderid,itemtype,itemname,thenumber,themoney) +values(1,'文具','笔',72,2), + (1,'文具','尺',10,1), + (1,'体育用品','篮球',1,56), + (2,'文具','笔',36,2), + (2,'文具','固体胶',20,3), + (2,'日常用品','透明胶',2,1), + (3,'体育用品','羽毛球',20,3), + (3,'文具','订书机',20,3), + (3,'文具','订书针',10,3), + (4,'文具','裁纸刀',5,5), + (4,'文具','笔',20,2), + (4,'文具','信纸',50,1), + (4,'日常用品','毛巾',4,5), + (4,'日常用品','透明胶',30,1), + (4,'体育用品','羽毛球',20,3) +select * from ORDERITEM +--1.查询所有订单订购的所有物品数量总和 +select * from ORDERITEM; +select sum(thenumber) as 总数 from ORDERITEM ; + +--2.查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select sum(thenumber) as 总数 , avg(themoney) as 平均单价 from ORDERITEM +where orderid < 3 +having avg(themoney) <10; + +--3.查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select sum(thenumber) as 总数 , avg(themoney) as 平均单价 from ORDERITEM +where thenumber>50 +having avg(themoney) <10 ; + +--4.查询每种类别的产品分别订购了几次,例如: +-- 文具 9 +-- 体育用品 3 +-- 日常用品 3 +select count(0) as '文具' from ORDERITEM where itemtype='文具'; +select count(0) as '体育用品' from ORDERITEM where itemtype='体育用品'; +select count(0) as '日常用品' from ORDERITEM where itemtype='日常用品'; +select *from ORDERITEM; + +--5.查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select itemtype ,sum(thenumber) as 数量 ,avg(themoney)as 平均单价 from ORDERITEM +group by itemtype +having sum(thenumber)>100 ; + +--6.查询每种产品的订购次数,订购总数量和订购的平均单价,例如: + +-- 产品名称 订购次数 总数量 平均单价 +-- 笔 3 120 2 +select* from ORDERITEM ; +select itemname ,count(0) as次数 ,sum(thenumber) as 总数量 , avg(themoney) as 平均单价 from ORDERITEM +group by itemname ; \ No newline at end of file diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\350\257\227\351\233\250.docx" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\350\257\227\351\233\250.docx" new file mode 100644 index 0000000000000000000000000000000000000000..435afee689671455b71e8e07333463e92465ef68 Binary files /dev/null and "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\350\257\227\351\233\250.docx" differ diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/SQLQuery6.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/SQLQuery6.sql" new file mode 100644 index 0000000000000000000000000000000000000000..9eefe08f1a2825ee204ad4f6ba34df093077a68d --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/SQLQuery6.sql" @@ -0,0 +1,86 @@ +create database Student +go + +use Student +go + +create table Class( + ClassId int primary key identity,--班级编号 + ClassName nvarchar(20) --班级名称 +); +go +create table student( + studentId int primary key identity, --学生编号 + studentName nvarchar(50), --学生姓名 + studentSex tinyint not null, --学生性别 + studentBirth date, --出生日期 + studentAddress nvarchar(255) not null,--地址 + classId int --班级编号 +); +insert into Class(ClassName) +values ('软件一班'),('软件二班'),('计算机应用技术班') +select * from Class + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区',1); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +( '钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3); + +insert into student(studentName, studentSex, studentBirth, studentAddress) +values ('东方不败',3,'1999-12-11' ,'河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1 ,'2000-08-11', '陕西省渭南市华阴市玉泉路南段'); +select * from student + +create table course ( +courseid int primary key identity , --课程编号 +coursename nvarchar(50) not null, --课程名称 +coutsecredit tinyint not null default 0 --课程学分 +); + +create table classcourse( +classcourseid int primary key identity, --自增编号 +classid int references class(classid), --班级编号 +courseid int references course(courseid) --课程编号 +); + +create table score ( +scoreid int primary key identity , --自增编号 +studentid int not null references student(studentid), --学生编号 +courseid int references course(courseid), --课程编号 +score int not null --分数 +); + +insert into course( coursename, coutsecredit) +values ('数据库高级应用',3), + ('javascript编程基础',3), + ('web前端程序设计基础',4), + ('动态网页设计.net基础',6), + ('动态网页设计php基础',6) +select *from course + +insert into classcourse(classid, courseid) +values (1,1),(1,2),(1,3),(1,4), + (2,1),(2,2),(2,3),(2,4), + (3,1),(3,2),(3,3),(3,5) + +insert into score( studentid, courseid, score) +values (1,1,80),(1,2,78),(1,3,65),(1,4,90), +(2,1,60),(2,2,77),(2,3,68),(2,4,88), +(3,1,88),(3,2,45),(3,3,66),(3,4,75), +(4,1,56),(4,2,80),(4,3,75),(4,4,66), +(5,1,88),(5,2,79),(5,3,72),(5,4,85), +(6,1,68),(6,2,88),(6,3,73),(6,5,63), +(7,1,84),(7,2,90),(7,3,92),(7,5,78), +(8,1,58),(8,2,59),(8,3,65),(8,5,75), +(9,1,48),(9,2,67),(9,3,56),(9,5,48) +select * from score \ No newline at end of file diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230/SQLQuery4.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230/SQLQuery4.sql" new file mode 100644 index 0000000000000000000000000000000000000000..d219af832405c550849985719d6f8692eebc1d8a --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230/SQLQuery4.sql" @@ -0,0 +1,152 @@ +create database STUDENT +go +use STUDENT +go +create table Class( + ClassId int primary key identity,--班级编号 + ClassName nvarchar(20) --班级名称 +); +go +create table student( + studentId int primary key identity, --学生编号 + studentName nvarchar(50), --学生姓名 + studentSex tinyint not null, --学生性别 + studentBirth date, --出生日期 + studentAddress nvarchar(255) not null,--地址 + classId int --班级编号 +); +insert into Class(ClassName) +values ('软件一班'),('软件二班'),('计算机应用技术班') +select * from Class + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区',1); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +( '钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3); + +insert into student(studentName, studentSex, studentBirth, studentAddress) +values ('东方不败',3,'1999-12-11' ,'河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1 ,'2000-08-11', '陕西省渭南市华阴市玉泉路南段'); +select * from student + +create table course ( +courseid int primary key identity , --课程编号 +coursename nvarchar(50) not null, --课程名称 +coutsecredit tinyint not null default 0 --课程学分 +); + +create table classcourse( +classcourseid int primary key identity, --自增编号 +classid int references class(classid), --班级编号 +courseid int references course(courseid) --课程编号 +); + +create table score ( +scoreid int primary key identity , --自增编号 +studentid int not null references student(studentid), --学生编号 +courseid int references course(courseid), --课程编号 +score int not null --分数 +); + +insert into course( coursename, coutsecredit) +values ('数据库高级应用',3), + ('javascript编程基础',3), + ('web前端程序设计基础',4), + ('动态网页设计.net基础',6), + ('动态网页设计php基础',6) +select *from course + +insert into classcourse(classid, courseid) +values (1,1),(1,2),(1,3),(1,4), + (2,1),(2,2),(2,3),(2,4), + (3,1),(3,2),(3,3),(3,5) + +insert into score( studentid, courseid, score) +values (1,1,80),(1,2,78),(1,3,65),(1,4,90), +(2,1,60),(2,2,77),(2,3,68),(2,4,88), +(3,1,88),(3,2,45),(3,3,66),(3,4,75), +(4,1,56),(4,2,80),(4,3,75),(4,4,66), +(5,1,88),(5,2,79),(5,3,72),(5,4,85), +(6,1,68),(6,2,88),(6,3,73),(6,5,63), +(7,1,84),(7,2,90),(7,3,92),(7,5,78), +(8,1,58),(8,2,59),(8,3,65),(8,5,75), +(9,1,48),(9,2,67),(9,3,71),(9,5,56),(9,1,48) +select * from score + +--1.分数表这边 李逍遥 数据库高级应用 成绩 插入重复了,请帮忙删除其中一条数据 +delete from score where scoreid=37 +select * from score + +--2.计算机应用技术班 的 欧阳天天 生日写错了,正确的生日应该是:2000-04-06,请用sql进行修改。 +update student set studentBirth='2000-04-06' +where studentId=7 +select * from student + +--3.计算机应用技术班的徐长卿的javascript编程基础分数填错,正确的分数应该是:61,请用sql进行修改。 +update score set score=61 +where studentid=8 and courseid=2; +select * from score + +--查询信息 +--1. 查询所有的班级 Class 信息。 +select * from Class +--2. 查询所有的学生 Student 信息。 +select * from Student +--3. 查询所有的课程 Course 信息。 +select * from Course +--4. 查询所有的班级课程 ClassCourse 信息。 +select * from ClassCourse +--5. 查询所有的分数 Score 信息。 +select * from Score +--6. 只查询学生的姓名和地址信息。 +select studentName,studentADDress from Student +--7. 查询获取学生信息表中20%的学生信息。 +select top 20 percent * from Student +--8. 查询学生信息表中的班级编号有哪些(去除重复值)。 +select distinct classId from Student +--9. 查询分数表中有成绩的学生编号; +select distinct studentid from Score +--10. 查询所有的课程 Course 信息,并且按照学分从大到小排列。 +select * from Course order by coutsecredit desc +--11. 查询所有的分数 Score 信息,并且按照分数从小到大排列。 +select * from Score order by score asc +--12. 查询所有的学生 Student 信息,并且按照年龄从小到大排列。 +select * from Student order by studentBirth asc +--13.查询软件一班所有的学生信息,显示学生id,姓名、性别、生日、住址。 +select * from student where classId=1 +--14.查询所有的女生,显示学生id,姓名、性别、生日、住址。 +select * from student where studentSex=2 +--15.查询2000年出生的所有学生,显示学生id,姓名、性别、生日、住址。 +select * from student where studentBirth between '2000-01-01' and '2000-12-30' +--16. 查询姓是欧阳的学生 +select *from Student where StudentName like '%欧阳%' +--17. 询地址是桂林市的学生 +select *from Student where StudentAddress like '%桂林市%' +--18. 查询姓李的学生,并且是三个字的 +select *from Student where StudentName like '李__' +--19. 查询 软件一班 有几个学生 +select count(StudentId) from Student where ClassId=1 +--20. 查询 软件一班 有几门课程 +select count(CourseId) from ClassCourse where ClassId=1 +--21. 查询 刘正(学生编号为1) 的总分 +select sum(Score) from Score where StudentId=1 +--22. 查询所有学生 数据库高级应用 的平均分 +select avg(Score) from Score where CourseId=1 +--23. 查询 所有学生 的总分 +select StudentId'学生编号' , sum(Score)'总分' from Score group by StudentId +--24. 查询 所有学生 的平均分 +select StudentId'学生编号' ,avg(Score)'平均分' from Score group by StudentId +--25. 查询 所有学生 的平均分,并且按照平均分从高到低排列 +select StudentId'学生编号' ,avg(Score)'平均分' from Score group by StudentId order by avg(score) desc +--26. 查询 所有学生中 平均分 大于80分的学生。(聚合查询 + 分组 + having) +select StudentId'学生编号' ,avg(Score)'平均分' from Score group by StudentId having avg(Score)>80 \ No newline at end of file diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321/SQLQuery5.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321/SQLQuery5.sql" new file mode 100644 index 0000000000000000000000000000000000000000..411cb5eb9055ee265d89c3763e3f307885b298ee --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321/SQLQuery5.sql" @@ -0,0 +1,100 @@ +create database LSY +go +use LSY +go +create table stuinfo( +stuNO nvarchar(50) primary key, +stuName nvarchar(50), +stuAge tinyint, +stuAddress nvarchar(50), +stuSeat int identity, +stuSex int +) + +create table stuexam( +examNO int primary key identity, +stuNO nvarchar(50) references stuinfo(stuNO), +writtenExam int, +labExam int +) + +insert into stuinfo(stuNO,stuName,stuAge,stuAddress,stuSex) +values('s2501','张秋利',20,'美国硅谷',1), + ('s2502','李斯文',18,'湖北武汉',0), + ('s2503','马文才',22,'湖南长沙',1), + ('s2504','欧阳俊雄',21,'湖北武汉',0), + ('s2505','梅超风',20,'湖北武汉',1), + ('s2506','陈旋风',19,'美国硅谷',1), + ('s2507','陈风',20,'美国硅谷',0) + +insert into stuexam(stuNO,writtenExam,labExam) +values ('s2501',50,70), + ('s2502',60,65), + ('s2503',86,85), + ('s2504',40,80), + ('s2505',70,90), + ('s2506',85,90) + +---1.查询学生信息表(stuinfo)中所有列信息,给每列取上中文名称 +select stuNO 学号,stuName 姓名,stuAge 年龄,stuAddress 地址,stuSeat 座号,stuSex 性别 from stuinfo +--2.查询学生信息表(stuinfo)中的姓名,年龄和地址三列的信息 +select stuName 姓名,stuAge 年龄,stuAddress 地址 from stuinfo +--3.查询学生分数表(stuexam)中的学号,笔试和机试三列的信息,并为这三列取中文名字 +-- 注意:要用三种方法 +select stuNO 学号,writtenExam 笔试,labExam 机试 from stuexam +select stuNO '学号',writtenExam '笔试',labExam '机试' from stuexam +select stuNO as 学号,writtenExam as 笔试,labExam as 机试 from stuexam +--4.查询学生信息表(stuInfo)中的学号,姓名,地址,以及将:姓名+@+地址 组成新列 “邮箱” +select stuNO 学号,stuName 姓名,stuAddress 地址, stuNO+'@'+stuAddress 邮箱 from stuinfo +--5.查询学生分数表(stuexam)中的学生的学号,笔试,机试以及总分这四列的信息 +select stuNO 学号,writtenExam 笔试,labExam 机试,writtenExam+labExam 总分 from stuexam +--6.查询学生信息表(stuInfo)中学生来自哪几个地方 +select distinct stuAddress 地址 from stuinfo +--7.查询学生信息表(stuInfo)中学生有哪几种年龄,并为该列取对应的中文列名 +select distinct stuAge 年龄 from stuinfo +--8.查询学生信息表(stuInfo)中前3行记录 +select top 3 * from stuinfo +--9.查询学生信息表(stuInfo)中前4个学生的姓名和座位号 +select top 4 stuName 姓名,stuSeat 座位号 from stuinfo +--10.查询学生信息表(stuInfo)中一半学生的信息 +select top 50 percent * from stuinfo +--11.将地址是湖北武汉,年龄是20的学生的所有信息查询出来 +select * from stuinfo where stuAddress like '湖北武汉' and stuAge like 20 +--12.将机试成绩在60-80之间的信息查询出来,并按照机试成绩降序排列(用两种方法实现) +select*from stuexam where labExam between 60 and 80 order by labExam desc +select*from stuexam where labExam>=60 and labExam<=80 order by labExam desc +--13.查询来自湖北武汉或者湖南长沙的学生的所有信息(用两种方法实现) +select*from stuinfo where stuAddress like '湖北武汉' or stuAddress like '湖南长沙' +select*from stuinfo where stuAddress = '湖北武汉' or stuAddress = '湖南长沙' +--14.查询出笔试成绩不在70-90之间的信息,并按照笔试成绩升序排列(用两种方法实现) +select writtenExam 笔试 from stuexam where not(writtenExam>=70 and writtenExam<=90) order by writtenExam asc +select writtenExam 笔试 from stuexam where not(writtenExam between 70 and 90) order by writtenExam asc + +--15.查询年龄没有写的学生所有信息 +select * from stuinfo where stuAge='' +select * from stuinfo where stuAge is null +--16.查询年龄写了的学生所有信息 +select * from stuinfo where stuAge !='' +select * from stuinfo where not(stuAge is null) +--17.查询姓张的学生信息 +select * from stuinfo where stuName like '张%' +--18.查询学生地址中有‘湖’字的信息 +select * from stuinfo where stuAddress like '%湖%' +--19.查询姓张但名为一个字的学生信息 +select * from stuinfo where stuName like '张_' +--20.查询姓名中第三个字为‘俊’的学生的信息,‘俊’后面有多少个字不限制 +select * from stuinfo where stuName like '__俊%' +--21.按学生的年龄降序显示所有学生信息 +select * from stuinfo order by stuAge desc +--22.按学生的年龄降序和座位号升序来显示所有学生的信息 +select * from stuinfo order by stuAge desc , stuSeat asc +--23.显示笔试第一名的学生的考试号,学号,笔试成绩和机试成绩 +select top 1 * from stuexam order by writtenExam desc +--24.显示机试倒数第一名的学生的考试号,学号,笔试成绩和机试成绩 +select top 1 * from stuexam order by labExam asc +--25.查询每个地方的学生的平均年龄 +select stuAddress, avg(stuAge) 平均年龄 from stuinfo group by stuAddress +--26.查询男女生的分别的年龄总和 +select stuSex , sum(stuAge) 年龄总和 from stuinfo group by stuSex +--27.查询每个地方的男女生的平均年龄和年龄的总和 +select stuAddress 地址,stuSex 性别, avg(stuAge) 平均年龄, sum(stuAge)年龄总和 from stuinfo group by stuAddress,stuSex \ No newline at end of file diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/SQLQuery8.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/SQLQuery8.sql" new file mode 100644 index 0000000000000000000000000000000000000000..95e0585b6eea47361b957314397b3814e97a96b3 --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/SQLQuery8.sql" @@ -0,0 +1,100 @@ +create database Student +go + +use Student +go + +create table Class( + ClassId int primary key identity,--班级编号 + ClassName nvarchar(20) --班级名称 +); +go +create table student( + studentId int primary key identity, --学生编号 + studentName nvarchar(50), --学生姓名 + studentSex tinyint not null, --学生性别 + studentBirth date, --出生日期 + studentAddress nvarchar(255) not null,--地址 + classId int --班级编号 +); +insert into Class(ClassName) +values ('软件一班'),('软件二班'),('计算机应用技术班') +select * from Class + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区',1); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +( '钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3); + +insert into student(studentName, studentSex, studentBirth, studentAddress) +values ('东方不败',3,'1999-12-11' ,'河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1 ,'2000-08-11', '陕西省渭南市华阴市玉泉路南段'); +select * from student + +create table course ( +courseid int primary key identity , --课程编号 +coursename nvarchar(50) not null, --课程名称 +coutsecredit tinyint not null default 0 --课程学分 +); + +create table classcourse( +classcourseid int primary key identity, --自增编号 +classid int references class(classid), --班级编号 +courseid int references course(courseid) --课程编号 +); + +create table score ( +scoreid int primary key identity , --自增编号 +studentid int not null references student(studentid), --学生编号 +courseid int references course(courseid), --课程编号 +score int not null --分数 +); + +insert into course( coursename, coutsecredit) +values ('数据库高级应用',3), + ('javascript编程基础',3), + ('web前端程序设计基础',4), + ('动态网页设计.net基础',6), + ('动态网页设计php基础',6) +select *from course + +insert into classcourse(classid, courseid) +values (1,1),(1,2),(1,3),(1,4), + (2,1),(2,2),(2,3),(2,4), + (3,1),(3,2),(3,3),(3,5) + +insert into score( studentid, courseid, score) +values (1,1,80),(1,2,78),(1,3,65),(1,4,90), +(2,1,60),(2,2,77),(2,3,68),(2,4,88), +(3,1,88),(3,2,45),(3,3,66),(3,4,75), +(4,1,56),(4,2,80),(4,3,75),(4,4,66), +(5,1,88),(5,2,79),(5,3,72),(5,4,85), +(6,1,68),(6,2,88),(6,3,73),(6,5,63), +(7,1,84),(7,2,90),(7,3,92),(7,5,78), +(8,1,58),(8,2,59),(8,3,65),(8,5,75), +(9,1,48),(9,2,67),(9,3,71),(9,5,56),(9,1,48) +select * from score + +--1.分数表这边 李逍遥 数据库高级应用 成绩 插入重复了,请帮忙删除其中一条数据 +delete from score where scoreid=37 +select * from score + +--2.计算机应用技术班 的 欧阳天天 生日写错了,正确的生日应该是:2000-04-06,请用sql进行修改。 +update student set studentBirth='2000-04-06' +where studentId=7 +select * from student + +--3.计算机应用技术班的徐长卿的javascript编程基础分数填错,正确的分数应该是:61,请用sql进行修改。 +update score set score=61 +where studentid=8 and courseid=2; +select * from score diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2324/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2324/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2324/SQLQuery1.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2324/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..2928c1538f80d53a2d7ca8e2cd1b6aaed73a40de --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2324/SQLQuery1.sql" @@ -0,0 +1,119 @@ +create database STUDENT +go +use STUDENT +go +create table Class( + ClassId int primary key identity,--班级编号 + ClassName nvarchar(20) --班级名称 +); +go +create table student( + studentId int primary key identity, --学生编号 + studentName nvarchar(50), --学生姓名 + studentSex tinyint not null, --学生性别 + studentBirth date, --出生日期 + studentAddress nvarchar(255) not null,--地址 + classId int --班级编号 +); +insert into Class(ClassName) +values ('软件一班'),('软件二班'),('计算机应用技术班') +select * from Class + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区',1); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +( '钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2); + +insert into student(studentName, studentSex, studentBirth, studentAddress, classId) +values ('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3); + +insert into student(studentName, studentSex, studentBirth, studentAddress) +values ('东方不败',3,'1999-12-11' ,'河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1 ,'2000-08-11', '陕西省渭南市华阴市玉泉路南段'); +select * from student + +create table course ( +courseid int primary key identity , --课程编号 +coursename nvarchar(50) not null, --课程名称 +coutsecredit tinyint not null default 0 --课程学分 +); + +create table classcourse( +classcourseid int primary key identity, --自增编号 +classid int references class(classid), --班级编号 +courseid int references course(courseid) --课程编号 +); + +create table score ( +scoreid int primary key identity , --自增编号 +studentid int not null references student(studentid), --学生编号 +courseid int references course(courseid), --课程编号 +score int not null --分数 +); + +insert into course( coursename, coutsecredit) +values ('数据库高级应用',3), + ('javascript编程基础',3), + ('web前端程序设计基础',4), + ('动态网页设计.net基础',6), + ('动态网页设计php基础',6) +select *from course + +insert into classcourse(classid, courseid) +values (1,1),(1,2),(1,3),(1,4), + (2,1),(2,2),(2,3),(2,4), + (3,1),(3,2),(3,3),(3,5) + +insert into score( studentid, courseid, score) +values (1,1,80),(1,2,78),(1,3,65),(1,4,90), +(2,1,60),(2,2,77),(2,3,68),(2,4,88), +(3,1,88),(3,2,45),(3,3,66),(3,4,75), +(4,1,56),(4,2,80),(4,3,75),(4,4,66), +(5,1,88),(5,2,79),(5,3,72),(5,4,85), +(6,1,68),(6,2,88),(6,3,73),(6,5,63), +(7,1,84),(7,2,90),(7,3,92),(7,5,78), +(8,1,58),(8,2,59),(8,3,65),(8,5,75), +(9,1,48),(9,2,67),(9,3,71),(9,5,56),(9,1,48) +select * from score + +--1. 查询 李逍遥(编号id为9) 所在的班级名称(连接查询 2表) +select * from Class inner join student on Class.ClassId=student.classid where student.studentid=9; + +--2. 查询 李逍遥(学生编号id为9) 学习的课程有哪几门,需要姓名、课程名称、课程学分(连接查询) +select studentname,coursename ,coutsecredit from student +join classcourse on classcourse.classid=student.classid +inner join course on course.courseid=classcourse.courseid +where student.studentid=9 ; +--3. 查询 李逍遥(学生编号id为9) 学习的课程考试得分,需要姓名、课程名称、课程学分、得分(连接查询) +select studentname,coursename ,coutsecredit,score from student +join classcourse on classcourse.classid=student.classid +inner join course on course.courseid=classcourse.courseid +join score on score.courseid=classcourse.courseid +where student.studentid=9 ; + +--4. 使用子查询查询 软件一班的每个学生 的平均分(聚合查询 + 子查询 + 分组) +select StudentId, avg(Score) as TotalScore from Score +join classcourse on score.courseid=classcourse.courseid +join Class on Class.ClassId=classcourse.classid +where Class.ClassId=1 +group by StudentId; + +--5. 使用连接查询 软件二班的每个学生 的平均分(聚合查询 + 连接查询 + 分组) +select StudentId, avg(Score) as TotalScore from Score +join classcourse on score.courseid=classcourse.courseid +join Class on Class.ClassId=classcourse.classid +where Class.ClassId=2 +group by StudentId; + +--6. 按照班级查询所有课程的平均分,并且按照平均分高低进行排序。(聚合查询 + 连接查询 + 分组) +select Class.ClassId, avg(Score) as TotalScore from Score +join classcourse on score.courseid=classcourse.courseid +join Class on Class.ClassId=classcourse.classid +group by Class.ClassId; \ No newline at end of file diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\273\203\344\271\2402/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\273\203\344\271\2402/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\273\203\344\271\2402/SQLQuery2.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\273\203\344\271\2402/SQLQuery2.sql" new file mode 100644 index 0000000000000000000000000000000000000000..fb8f185915fe31cfb46bd74308b7ed2a9dafcb74 --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\273\203\344\271\2402/SQLQuery2.sql" @@ -0,0 +1,73 @@ +create database LSY +go +use LSY +go +create table orders( +orderid int primary key identity, +orderdate nvarchar(50) +) + +create table orderitem( +itemid int primary key identity, +orderid int, +itemtype nvarchar(50), +itemname nvarchar(50), +thenumber int, +themoney int +) + +insert into orders(orderdate) +values('2008-01-12 00:00:00.000'), + ('2008-02-10 00:00:00.000'), + ('2008-02-15 00:00:00.000'), + ('2008-03-10 00:00:00.000') + +insert into orderitem(orderid,itemtype,itemname,thenumber,themoney) +values(1,'文具','笔',72,2), + (1,'文具','尺',10,1), + (1,'体育用品','篮球',1,56), + (2,'文具','笔',36,2), + (2,'文具','固体胶',20,3), + (2,'日常用品','透明胶',2,1), + (3,'体育用品','羽毛球',20,3), + (3,'文具','订书机',20,3), + (3,'文具','订书针',10,3), + (4,'文具','裁纸刀',5,5), + (4,'文具','笔',20,2), + (4,'文具','信纸',50,1), + (4,'日常用品','毛巾',4,5), + (4,'日常用品','透明胶',30,1), + (4,'体育用品','羽毛球',20,3) + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderid 订单编号,orderdate 订单日期,itemtype 类别,itemname 产品名称,thenumber 订购数量,themoney 订购单价 from orders +join orderitem on orders.orderid=orderitem.orderid + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderid 订单编号,orderdate 订单日期,itemtype 类别,itemname 产品名称,thenumber 订购数量,themoney 订购单价 from orders +join orderitem on orders.orderid=orderitem.orderid +where thenumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderid 订单编号,orderdate 订单日期,itemtype 类别,itemname 产品名称,thenumber 订购数量,themoney 订购单价,sum(themoney)订购总价 from orders +join orderitem on orders.orderid=orderitem.orderid +group by orders.orderid ,orderdate ,itemtype ,itemname,thenumber,themoney + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderid 订单编号,orderdate 订单日期,itemtype 类别,itemname 产品名称,thenumber 订购数量,themoney 订购单价,sum(themoney)订购总价 from orders +join orderitem on orders.orderid=orderitem.orderid +where themoney>=5 and thenumber>=50 +group by orders.orderid ,orderdate ,itemtype ,itemname,thenumber,themoney + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 订购日期 +-- 1 3 +-- 2 4 +select orderitem.orderid 编号,count(thenumber)订购产品数 from orderitem +group by orderitem.orderid,thenumber + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,订购日期,例如: + +-- 订单编号 产品类别 订购次数 总数量 订购日期 +select orderitem.orderid 订单编号,itemtype 类别,thenumber 订购数量,sum(themoney)订购总价 from orderitem +group by orderitem.orderid,itemtype,thenumber,themoney \ No newline at end of file diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\347\273\203\344\271\2401" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\347\273\203\344\271\2401" new file mode 100644 index 0000000000000000000000000000000000000000..6b15cfd6164eca82f53c56501eb081e773aa368e --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\347\273\203\344\271\2401" @@ -0,0 +1,66 @@ +create database LSY +go +use LSY +go +create table student ( +stuno nvarchar(10) primary key, +stuname nvarchar(20) not null, +stuage int not null, +stuaddress nvarchar(20) not null, +stuseat int identity, +stusex nvarchar(1) not null +); + +insert into student(stuno, stuname, stuage, stuaddress, stusex) +values('s2501','张秋利',20,'美国硅谷',1), +('s2502','李斯文',18,'湖北武汉',0), +('s2503','马文才',22,'湖南长沙',1), +('s2504','欧阳俊雄',21,'湖北武汉',0), +('s2505','梅超风',20,'湖北武汉',1), +('s2506','陈旋风',19,'美国硅谷',1), +('s2507','陈风',20,'美国硅谷',0) + +create table exam( +examno int primary key identity, +stuno nvarchar(10) references student (stuno), +writtenexam int not null, +labexam int not null +); + +insert into exam(stuno,writtenexam,labexam) +values('s2501',50,70), +('s2502',60,65), +('s2503',86,85), +('s2504',40,80), +('s2505',70,90), +('s2506',85,90) + +--查询学生的姓名,年龄,笔试成绩和机试成绩 +select student.stuname 姓名,stuage 年龄,writtenexam 笔试,labexam 机试 from student +join exam on student.stuno=exam.stuno + +--查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select student.stuname 姓名,stuage 年龄,writtenexam 笔试,labexam 机试 from student +join exam on student.stuno=exam.stuno +where writtenexam>60 and labexam>60 + +--查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select student.stuname 姓名,stuage 年龄,writtenexam 笔试,labexam 机试 from student +left join exam on student.stuno=exam.stuno +order by exam.writtenexam,exam.labexam desc + +--查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select student.stuname 姓名,stuage 年龄,writtenexam 笔试,labexam 机试 from student +join exam on student.stuno=exam.stuno +where stuage>=20 +order by exam.writtenexam desc + +--查询男女生的机试平均分 +select stusex,avg(labexam) from student +inner join exam on student.stuno=exam.stuno +group by stusex + +--查询男女生的笔试总分 +select stusex,sum(writtenexam) from student +inner join exam on student.stuno=exam.stuno +group by stusex ; diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/.keep" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/37\346\242\201\350\257\227\351\233\250\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" new file mode 100644 index 0000000000000000000000000000000000000000..f642f34060de5761e79b724ebdb80860377c97d9 --- /dev/null +++ "b/37\346\242\201\350\257\227\351\233\250\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" @@ -0,0 +1,45 @@ +create database Test1; + +use Test1; + +--班级信息表 +create table Class( + ClassId int primary key identity(1,1),--班级编号,主键,自增 + ClassName nvarchar(50) not null unique,--班级名称,不允许为空,唯一约束 + ); + +--学生信息表 +create table Student( + StudentId int primary key identity(1,1),--班级编号,主键,自增 + StudentName nvarchar(50) not null,--学生姓名,不允许为空 + StudentSex tinyint not null default 3 check(StudentSex=1 or StudentSex=2 or StudentSex=3),--学生性别,不允许为空,默认值为3,check约束 + StudentBirth date, --学生生日 + StudntAddress nvarchar(255) not null,--学生地址,不允许为空 + ClassId int not null default 0 , --所属班级ID,不允许为空,默认值0 + foreign key(ClassId) references Class(ClassId)--外键 +); + +--课程信息表 +create table Course( + CourseId int primary key identity(1,1), --课程编号,自增,主键 + CourseName nvarchar(50) not null unique,--课程名称,不允许为空,唯一约束 + CouseCredit tinyint not null default 0 check(CouseCredit>0)--课程学分,不允许为空,默认值为0 + ); + +--班级课程表 +create table ClassCourse( + ClassCouseId int identity(1,1),--自增编号,主键,自增 + ClassId int not null ,--班级编号,不允许为空 + CourseId int primary key not null, --课程编号,不允许为空 + foreign key(CourseId) references Course(CourseId) --外键 + ); + +--分数信息表 +create table Score( + ScoreId int primary key identity(1,1),--自增编号,主键,自增 + StudentId int not null, --学生编号,不允许为空 + foreign key(StudentId) references Student(StudentId),--外键 + CourseId int not null,--课程编号,不允许为空 + foreign key(CourseId) references ClassCourse(CourseId),--外键 + Score int not null check(Score>=0) --分数,不允许为空,check约束 + ); \ No newline at end of file diff --git a/bdhfb.txt b/bdhfb.txt deleted file mode 100644 index 602653a6535fd9a2e29ab6e6c03ae3f9dad4cb79..0000000000000000000000000000000000000000 --- a/bdhfb.txt +++ /dev/null @@ -1 +0,0 @@ -chdgyudvy \ No newline at end of file diff --git a/lsy.txt b/lsy.txt deleted file mode 100644 index d88916b23a3ed9189d09f026906495e8a9e0275a..0000000000000000000000000000000000000000 --- a/lsy.txt +++ /dev/null @@ -1 +0,0 @@ -dwqfdwef diff --git "a/\345\244\215\344\271\240\351\242\230/.keep" "b/\345\244\215\344\271\240\351\242\230/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\345\244\215\344\271\240\351\242\230/SQLQuery1.sql" "b/\345\244\215\344\271\240\351\242\230/SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..2d53dec49ba6e20d4833c0d0eb1e6240e92b1817 --- /dev/null +++ "b/\345\244\215\344\271\240\351\242\230/SQLQuery1.sql" @@ -0,0 +1,49 @@ +create database GoodsDB +go +use GoodsDB +go + +create table GoodsType(---商品类型表 +TypeID int primary key identity(1,1) not null , ---商品类型编号 +TypeName nvarchar(20) not null , ---商品类型名称 +) + +create table GoodsInfo(---商品信息表 +GoodsID int primary key identity(1,1) not null , ---商品编号 +GoodsName nvarchar(20) not null , ---商品名称 +GoodsColor nvarchar(20) not null , ---商品颜色 +GoodsBrand nvarchar(20) , ---商品品牌 +GoodsMoney money not null , ---商品价格 +TypeID int foreign key (TypeID) references GoodsType (TypeID) ---商品类型编号 +) + +insert into GoodsType (TypeName) +values ('服装内衣'),('鞋包配饰'),('手机数码') + +select * from GoodsType + +insert into GoodsInfo(GoodsName,GoodsColor,GoodsBrand,GoodsMoney,TypeID) +values ('提花小西装','红色','菲曼琪',300,1), + ('百搭短裤','绿色','哥弟',100,1), + ('无袖背心','白色','阿依莲',700,1), + ('低帮休闲鞋','红色','菲曼琪',900,2), + ('中跟单鞋','绿色','哥弟',400,2), + ('平底鞋','白色','阿依莲',200,2), + ('迷你照相机','红色','尼康',500,3), + ('硬盘','黑色','希捷',600,3), + ('显卡','黑色','技嘉',800,3) + +select * from GoodsInfo + +--1、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo +order by GoodsMoney desc + +--2、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select MAX(GoodsMoney) 商品最高价格,MIN(GoodsMoney) 商品最低价格,AVG(GoodsMoney) 商品平均价格 from GoodsInfo +group by TypeID + +--3、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo +where GoodsColor='红色' and GoodsMoney between 300 and 600 + diff --git "a/\345\244\215\344\271\240\351\242\230/SQLQuery2.sql" "b/\345\244\215\344\271\240\351\242\230/SQLQuery2.sql" new file mode 100644 index 0000000000000000000000000000000000000000..c356bd9b5cb82daa809f1ae5c8e8ac0f40190bba --- /dev/null +++ "b/\345\244\215\344\271\240\351\242\230/SQLQuery2.sql" @@ -0,0 +1,47 @@ +create database HOUSE_DB +go +use HOUSE_DB +go + +create table HOUSE_TYPE(---房屋类型表 +type_id int primary key identity not null, ---类型编号 +type_name varchar(50) unique not null ---类型名称 +) + +create table HOUSE(---房屋信息表 +house_id int primary key identity not null, ---房屋编号 +house_name varchar(50) not null , ---房屋名称 +house_price float default 0 , ---房租 +type_id int foreign key (type_id) references HOUSE_TYPE(type_id) ---房屋类型 +) + +insert into HOUSE_TYPE(type_name) +values ('小户型'),('经济型'),('别墅') + +select * from HOUSE_TYPE + +insert into HOUSE(house_name,house_price,type_id) +values ('小新之家','5000'), +('维多利亚港','9000'), +('快乐客栈','2000') + +select * from HOUSE + +--1.查询所有房屋信息 +select * from HOUSE + +--2.使用模糊查询包含”型“字的房屋类型信息 +select * from HOUSE_TYPE +where type_name like '%型%' + +--3.查询出房屋的名称和租金,并且按照租金降序排序 +select house_name 房屋名称,house_price 租金 from HOUSE +order by house_price desc + +--4.使用连接查询,查询信息,显示房屋名称和房屋类型名称 +select house_name 房屋名称,HOUSE.type_id 房屋类型 from HOUSE +inner join HOUSE_TYPE on HOUSE_TYPE.type_id=HOUSE.type_id + +--5.查询所有房屋中月租最高的房屋,显示最高的租金和房屋名称 +select top 1 house_name 房屋名称,MAX(house_price) 租金 from HOUSE +order by house_price desc \ No newline at end of file diff --git "a/\345\244\215\344\271\240\351\242\230/SQLQuery3.sql" "b/\345\244\215\344\271\240\351\242\230/SQLQuery3.sql" new file mode 100644 index 0000000000000000000000000000000000000000..f2f2fceb6de9f091baea327d20f46f74f2c40082 --- /dev/null +++ "b/\345\244\215\344\271\240\351\242\230/SQLQuery3.sql" @@ -0,0 +1,48 @@ +create database StarManagerDB +go +use StarManagerDB +go + +create table StarType(---明星类型表 +T_NO int primary key identity(1,1) not null , ---明星类型编号 +T_NAME nvarchar(20) ---明星类型 +); + +create table StarInfo(---明星信息表 +S_NO int primary key identity(1,1) not null , ---明星编号 +S_NAME nvarchar(20) not null , ---明星姓名 +S_AGE int not null , ---明星年龄 +S_HOBBY nvarchar(20) , ---特技 +S_NATIVE nvarchar(20) default '中国大陆', ---明星籍贯 +S_T_NO int foreign key (S_T_NO) references StarType(T_NO) ---明星类型编号 +); + +insert into StarType(T_NAME) +values('体育明星'),('IT明星'),('相声演员') + +select * from StarType + +insert into StarInfo( S_NAME, S_AGE, S_HOBBY, S_NATIVE, S_T_NO) +values('梅西',30,'射门','阿根廷',1), + ('科比',35,'过人','美国',1), + ('蔡景现',40,'敲代码','中国',2), + ('马斯克',36,'造火箭','外星人',2), + ('郭德纲',50,'相声','中国',3), + ('黄铮',41,'拼多多','中国',2) + +select * from StarInfo + +--1、查询年龄最大的3个明星的姓名,特技和籍贯信息,要求使用别名显示列名。 +select top 3 S_NAME 明星姓名,S_HOBBY 特技,S_NATIVE 籍贯信息 from StarInfo +order by S_AGE desc + +--2、按明星类型编号分类查询明星人数,明星平均年龄,显示明星人数大于2的分组信息,要求使用别名显示列名。 +select count(S_NO) 明星人数,avg(S_AGE) 明星平均年龄 from StarInfo +group by S_T_NO +having count(S_NO)>2 + +--3、查询明星类型为“体育明星”中年龄最大的姓名、特技、籍贯信息,要求显示列别名。 +select top 1 S_NAME 明星姓名,S_HOBBY 特技,S_NATIVE 籍贯信息 from StarInfo +where S_T_NO=1 +order by S_AGE desc +