From 89175c469a5cb0ac25ef3bae3d6d0ee3bd245d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E9=A1=B7=E9=81=93=E9=95=BF?= <2642587822@qq.com> Date: Fri, 26 Mar 2021 15:41:58 +0800 Subject: [PATCH 001/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=2020210326=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "20210326\344\275\234\344\270\232/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20210326\344\275\234\344\270\232/.keep" diff --git "a/20210326\344\275\234\344\270\232/.keep" "b/20210326\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 9058505916fab44bcb48f6f9cfedf4df86b9d8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E9=A1=B7=E9=81=93=E9=95=BF?= <2642587822@qq.com> Date: Fri, 26 Mar 2021 15:43:46 +0800 Subject: [PATCH 002/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E5=8D=81?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A?= 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\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/.keep" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 7f6b873496ffd878586f3e1ff53867b3813800df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E9=A1=B7=E9=81=93=E9=95=BF?= <2642587822@qq.com> Date: Fri, 26 Mar 2021 15:44:05 +0800 Subject: [PATCH 003/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E5=8D=81?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E4=BD=9C=E4=B8=9A?= 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\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/.keep" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 170c1a651046b4c852a52be44196ba35163d54d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E9=A1=B7=E9=81=93=E9=95=BF?= <2642587822@qq.com> Date: Fri, 26 Mar 2021 15:44:30 +0800 Subject: [PATCH 004/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E5=8D=81?= =?UTF-8?q?=E4=B8=89=E6=AC=A1=E4=BD=9C=E4=B8=9A?= 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\345\215\201\344\270\211\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/\347\254\254\345\215\201\344\270\211\346\254\241\344\275\234\344\270\232/.keep" "b/\347\254\254\345\215\201\344\270\211\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 42e2b6df4a28a73e7d48c8d290315c649b4f8704 Mon Sep 17 00:00:00 2001 From: EoL <1179233990@qq.com> Date: Fri, 26 Mar 2021 17:02:16 +0800 Subject: [PATCH 005/195] 1 --- .../SQLQuery1.sql" | 67 +++++++++++++++++ .../SQLQuery2.sql" | 45 +++++++++++ .../SQLQuery3.sql" | 74 +++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" new file mode 100644 index 0000000..e3f238d --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" @@ -0,0 +1,67 @@ +use master +go +if exists(select * from sys.databases where name='Student') + drop database Student +create database Student +on +( + name='Student', + filename='D:\SQL\Student.mdf', + size=5MB, + maxsize=50MB, + filegrowth=10MB +) +log on +( + name='Student_log', + filename='D:\SQL\Student_log.ldf', + size=5MB, + maxsize=50MB, + filegrowth=10MB +) +go +use Student +create table StuInfo +( +stuNO char(5) primary key not null, +stuName nvarchar(20) not null, +stuAge int not null, +stuAddress nvarchar(200) not null, +stuSeat int not null, +stuSex nvarchar(1) default('0') check(StuSex='0' or StuSex='1'), +) +create table stuexam +( +examNO int primary key identity(1,1), +stuNO char(5) constraint FK_StuInfo_stuNO references StuInfo(stuNO), +writtenExam int not null, +labExam int not null +) +insert into StuInfo(stuNO,stuName,stuAge,stuAddress,stuSeat,stuSex) values +('s2501','张秋利',20,'美国硅谷',1,1), +('s2502','李斯文',18,'湖北武汉',2,0), +('s2503','马文才',22,'湖南长沙',3,1), +('s2504','欧阳俊雄',21,'湖北武汉',4,0), +('s2505','梅超风',20,'湖北武汉',5,1), +('s2506','陈旋风',19,'美国硅谷',6,1), +('s2507','陈风',20,'美国硅谷',7,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) +select * from StuInfo +select * from stuexam +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName,stuAge,writtenExam,labExam from StuInfo inner join stuexam on StuInfo.stuNO=stuexam.stuNO +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuName,stuAge,writtenExam,labExam from StuInfo inner join stuexam on StuInfo.stuNO=stuexam.stuNO where labExam>60 and writtenExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuInfo.stuNO,stuName,writtenExam,labExam from StuInfo left join stuexam on StuInfo.stuNO=stuexam.stuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName,stuAge,writtenExam,labExam from StuInfo inner join stuexam on StuINfo.stuNO=stuexam.stuNO where stuAge>=20 order by writtenExam DESC +--5.查询男女生的机试平均分 +select stuSex,AVG(labExam) from StuInfo left join stuexam on StuInfo.stuNO=stuexam.stuNO group by stuSex +--6.查询男女生的笔试总分 +select stuSex,SUM(writtenExam) from StuInfo left join stuexam on StuInfo.stuNO=stuexam.stuNO group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery2.sql" new file mode 100644 index 0000000..0d9ae05 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery2.sql" @@ -0,0 +1,45 @@ +use master +go +create database heidian +on +( +name='heidian', +filename='D:\SQL\heidian.mdf' +) +log on +( +name='heidian_log', +filename='D:\SQL\heidian_log.ldf' +) +use heidian +go +create table orders +( +orderId int primary key, +orderDate datetime +) +create table orderItem +( +ItemiD int primary key identity, +orderId int, +itemType nvarchar(4), +itemName nvarchar(8), +theNumber int, +theMoney int, +) +insert into orders values(1,'2008-1-12 00:00:00.000'),(2,'2008-2-10 00:00:00.000'),(3,'2008-2-15 00:00:00.000'),(4,'2008-3-10 00:00:00.000') +insert into orderItem values(1,'文具','笔',72,2),(1,'文具','尺',10,1),(1,'体育用品','篮球',1,56),(2,'文具','笔',36,2),(2,'文具','固体胶',20,3),(2,'日常用品','透明胶',2,1),(2,'体育用品','羽毛球',20,3),(3,'文具','订书机',20,3),(3,'文具','订书针',10,3),(3,'文具','裁纸刀',5,5),(4,'文具','笔',20,2),(4,'文具','信纸',50,1),(4,'日常用品','毛巾',4,5),(4,'日常用品','透明胶',30,1),(4,'体育用品','羽毛球',20,3) +select * from orders +select * from orderItem +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderId,orderDate,itemType,itemName from orders inner join orderItem on orders.orderId=orderItem.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderId,orderDate,itemType,itemName from orders inner join orderItem on orders.orderId=orderItem.orderId where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber*theMoney from orders inner join orderItem on orders.orderId=orderItem.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber*theMoney from orders inner join orderItem on orders.orderId=orderItem.orderId where theNumber>=50 and theMoney>=5 +--5.查询每个订单分别订购了几个产品 +select orderId,count(itemName) from orderItem group by orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量 +select orderId,itemType,count(itemType),sum(theNumber) from orderItem group by orderId,itemType order by orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery3.sql" new file mode 100644 index 0000000..b702c81 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery3.sql" @@ -0,0 +1,74 @@ +use master +go +create database bbs +on +( +name='bbs', +filename='D:\SQL\bbs.mdf' +) +log on +( +name='bbs_log', +filename='D:\SQL\bbs_log.ldf' +) +go +use bbs +go +create table bbsUsers +( +UID int primary key identity(1,1), +uName varchar(10) not null, +uSex varchar(2) not null check(uSex='男' or uSex='女'), +uAge int not null check(uAge>=15 and uAge<=40), +uPoint int not null check(uPoint>=0) +) +go +create table bbsTopic +( +tID int primary key identity(1,1), +tUID int, +tSID int, +tTitle varchar(100) not null, +tMsg text not null, +tTime datetime, +tCount int +) +go +create table bbsReply +( +rID int primary key identity(1,1), +rUID int constraint FK_bbsUsers_UID references bbsUsers(UID), +rTID int constraint FK_bbsTopic_tID references bbsTopic(tID), +rMsg text not null, +rTime datetime +) +go +create table bbsSection +( +sID int primary key identity(1,1), +sName varchar(10) not null, +sUid int, +) +go +alter table bbsTopic add constraint FK_bbsUsers1_UID foreign key(tUID) references bbsUsers(UID) +alter table bbsTopic add constraint FK_bbsSection_sID foreign key(tSID) references bbsSection(sID) +alter table bbsSection add constraint FK_bbsUsers2_UID foreign key(sUid) references bbsUsers(UID) +insert into bbsUsers(uName,uSex,uAge,uPoint) values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection(sName,sUid) values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) values(2,4,'范跑跑','谁是范跑跑','2008-7-8',1),(3,1,'.NET','与JAVA的区别是什么呀?','2008-9-1',2),(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀','2008-9-10',0) +insert into bbsReply(rMsg,rTime,rUID,rTID) values('666','2008-1-1',1,2),('666','2008-1-1',2,3),('666','2008-1-1',3,1) +select * from bbsUsers +select * from bbsTopic +select * from bbsReply +select * from bbsSection +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select UID,uName,sName from bbsUsers inner join bbsSection on bbsUsers.UID=bbsSection.sUid +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select UID,uName,tTitle,tMsg,tTime from bbsUsers inner join bbsTopic on bbsUsers.UID=bbsTopic.tUID where tTime>'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select UID,uName,sName from bbsUsers inner join bbsSection on bbsUsers.UID=bbsSection.sUid where uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select UID,uName,tTitle,tMsg,tCount from bbsUsers inner join bbsTopic on bbsUsers.UID=bbsTopic.tUID where tCount=(select MAX(tCount) from bbsTopic) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName,uName,count(tID) 发帖总数 from bbsUsers left join bbsSection on bbsUsers.UID=bbsSection.sUid left join bbsTopic on bbsUsers.UID=bbsTopic.tUID group by sName,uName -- Gitee From 6d6a8f90d14de61e77f690290eceee3344dc11c6 Mon Sep 17 00:00:00 2001 From: putar Date: Fri, 26 Mar 2021 17:04:41 +0800 Subject: [PATCH 006/195] 2021-03-26 17:04 --- .../SQLQuery1.sql" | 56 ++++++++ .../SQLQuery2.sql" | 80 +++++++++++ .../SQLQuery3.sql" | 135 ++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" new file mode 100644 index 0000000..11d0289 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" @@ -0,0 +1,56 @@ +/** +* 之前的作业1 +* 建表 +**/ + +use master +create database Student +go + +use Student +create table StuInfo +( + stuNO char(5) primary key, + stuName nchar(5), + stuAge int, + stuAddress nchar(50), + stuSeat int identity(1,1), + stuSex char(1) check(stuSex = '1' or stuSex = '0') +) +go + +use Student +create table StuExam +( + examNO int identity(1,1) primary key, + stuNO char(5) constraint FK_stuInfo_stuNO references StuInfo(stuNO), + writtenExam int check(writtenExam >= 0 and writtenExam <= 100), + labExam int check(labExam >= 0 and labExam <= 100) +) +go + +use Student +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') +go + +use Student +insert into StuExam(stuNO,writtenExam,labExam) values ('s2501','50','70'),('s2502','60','65'),('s2503','86','65'), +('s2504','40','85'),('s2505','70','90'),('s2506','85','90') +go + +use Student +go +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName,stuAge,writtenExam,labExam from StuInfo SI inner join StuExam SE on SI.stuNO = SE.stuNO +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuName,stuAge,writtenExam,labExam from StuInfo SI inner join StuExam SE on SI.stuNO = SE.stuNO where labExam > 60 and writtenExam > 60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select SI.stuNO,stuName,writtenExam,labExam from StuInfo SI left join StuExam SE on SI.stuNO = SE.stuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select SI.stuNO,stuName,writtenExam,labExam from StuInfo SI left join StuExam SE on SI.stuNO = SE.stuNO where stuAge >= 20 order by writtenExam desc +--5.查询男女生的机试平均分 +select stuSex,AVG(labExam) 平均分 from StuExam SE left join StuInfo SI on SE.stuNO = SI.stuNO group by stuSex +--6.查询男女生的笔试总分 +select stuSex,SUM(writtenExam) 总分 from StuExam SE left join StuInfo SI on SE.stuNO = SI.stuNO group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" new file mode 100644 index 0000000..7c654ae --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" @@ -0,0 +1,80 @@ +/** +* 作业2 +**/ + +use master +go + +create database store +go + +use store +go + +create table orders +( + orderID int primary key identity(1,1), + orderDate datetime +) +go + +create table orderItem +( + itemID int primary key identity, + orderID int references orders(orderID), + itemType nchar(5), + itemName nchar(20), + theNumber int, + theMoney int +) + +insert into orders values ('2008-01-12'),('2008-02-10'),('2008-02-15'),('2008-3-10') +go +insert into orderItem values (1,'文具','笔',72,2),(1,'文具','尺',10,1),(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2),(2,'文具','固体胶',20,3),(2,'日常用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3),(3,'文具','订书机',20,3),(3,'文具','订书针',10,3), +(3,'文具','裁纸刀',5,5),(4,'文具','笔',20,20),(4,'文具','信纸',50,1),(4,'日常用品','毛巾',4,5), +(4,'日常用品','透明胶',30,1),(4,'体育用品','羽毛球',20,3) +go + +use store +go +--查询所有订单订购的所有物品数量总和 +select SUM(theNumber) 所有订单物品数量和 from orderItem +--查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select SUM(theNumber) 物品数量, AVG(theMoney) 平均单价 from orderItem where orderID < 3 and theMoney < 10 +--查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select COUNT(theNumber) 物品数量,AVG(theMoney) 平均单价 from orderItem where theMoney < 10 and theNumber > 50 +--查询每种类别的产品分别订购了几次 +select itemName,COUNT(theNumber) 订购次数 from orderItem group by itemName +--查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select itemType,SUM(theNumber) 订购总数,AVG(theMoney) 平均单价 from orderItem group by itemType having SUM(theNumber) > 100 +--查询每种产品的订购次数,订购总数量和订购的平均单价 +select itemName,COUNT(itemName) 订购次数,SUM(theNumber) 订购总数,theMoney 平均单价 from orderItem group by itemName,theMoney +--使用上次作业的订单数据库,完成下列题目: +use store +go +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select O.orderID,orderDate,itemType,itemName,theNumber,theMoney from orders O left join orderItem OI on O.orderID = OI.orderID +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select O.orderID,orderDate,itemType,itemName from orders O left join orderItem OI on O.orderID = OI.orderID where theNumber > 50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select O.orderID,orderDate,itemType,itemName,theNumber,theMoney,theMoney * theNumber total from orders O left join orderItem OI on O.orderID = OI.orderID +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select O.orderID,orderDate,itemType,itemName,theNumber,theMoney,theMoney * theNumber total from orders O left join orderItem OI on O.orderID = OI.orderID where theMoney >=5 and theNumber >= 50 +/*5.查询每个订单分别订购了几个产品,例如: + 编号 订购产品数 + 1 3 + 2 4*/ +select O.orderID,SUM(theNumber)订购总数 from orders O left join orderItem OI on O.orderID = OI.orderID group by O.orderID + +/*6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + + 订单编号 产品类别 订购次数 总数量 + + 1 文具 2 82 + 1 体育用品 1 1 + 2 文具 2 56 + 2 体育用品 1 2 + 2 日常用品 1 20*/ +select O.orderID 订单编号,itemType 产品类别,COUNT(itemType)订购次数, SUM(theNumber)订购总数 from orders O inner join orderItem OI on O.orderID = OI.orderID group by O.orderID,itemType order by O.orderID \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery3.sql" new file mode 100644 index 0000000..9398561 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery3.sql" @@ -0,0 +1,135 @@ +/** +* 作业3 +* 之前的作业,因为要套用 +**/ +use master +go +create database bbs +on primary +( + name = 'bbs', + filename = 'D:\Document\MSSQLDatabase\bbs\bbs.mdf',--没有E盘,就丢这了 + size = 5MB, + Maxsize = 50MB, + filegrowth = 1MB +) +log on +( + name = 'bbs_log', + filename = 'D:\Document\MSSQLDatabase\bbs\bbs_log.ldf',--没有E盘,就丢这了 + size = 1MB, + Maxsize = 10MB, + filegrowth = 10% +) +go + +use bbs +go +create table bbsUsers +( + UID int identity(1,1), + uName varchar(10), + uSex varchar(2), + uAge int, + uPoint int +) +goto altBbsUsers +bbsTopic: + create table bbsTopic + ( + tID int primary key identity(1,1), + tUID int constraint FK_bbsTopic_UID references bbsUsers(UID), + tSID int constraint FK_bbsSection_sID references bbsSection(sID), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int + ) + goto bbsReply +bbsReply: + create table bbsReply + ( + rID int primary key identity(1,1), + rUID int constraint FK_bbsReply_UID foreign key references bbsUsers(UID), + rTID int constraint FK_bbsSection_tID references bbsTopic(tID), + rMsg text, + rTime datetime + ) + goto endCre +bbsSection: + create table bbsSection + ( + sID int identity(1,1), + sName varchar(10), + sUid int + ) + goto altBbsSection + +altBbsUsers: + alter table bbsUsers add constraint PK_UID primary key(UID) + alter table bbsUsers add constraint UQ_uName unique(uName) + alter table bbsUsers alter column uSex varchar(2) not null + alter table bbsUsers add constraint CK_uSex check(uSex = '男' or uSex = '女') + alter table bbsUsers add constraint DF_uSex default('男') for uSex + alter table bbsUsers add constraint CK_uAge check(uAge between 15 and 60) + alter table bbsUsers add constraint CK_uPoint check(uPoint >= 0) + goto bbsSection +altBbsSection: + alter table bbsSection add constraint PK_sID primary key(sID) + alter table bbsSection alter column sName varchar(10) not null + alter table bbsUsers add constraint FK_bbsUsers_UID foreign key(UID) references bbsUsers(UID) + goto bbsTopic + +endCre: + goto insTable + +insTable: + use bbs + insert into bbsUsers(uName,uSex,uAge,uPoint) values ('小雨点','女',20,0), + ('逍遥','男',18,4),('七年级生','男',19,2)--小雨点 1 逍遥 2 , 七年生 3 + goto buBbsPoint +buBbsPoint: + select uName,uPoint into bbsPoint from bbsUsers + goto startSection +startSection: + insert into bbsSection(sName,sUid) values ('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) + goto addReply +addReply: + use bbs + insert into bbsTopic(tUID,tSID,tTitle,tMSG,tTime,tCount) values (2,4,'范跑跑','谁是范跑跑','2008-07-08',1), + (3,1,'.NET','与JAVA的区别是什么啊','2008-09-01',2), + (2,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-09-10',0) + insert into bbsReply(rUID,rTID,rMsg,rTime) values (1,1,'是傻逼',getdate()), + (2,2,'平台和语言的区别',getdate()) + goto delUser +delUser: + alter table bbsReply drop constraint FK_bbsReply_UID + alter table bbsTopic drop constraint FK_bbsTopic_UID + delete from bbsUsers where uID = 2 + goto addPoint +addPoint: + insert into bbsPoint values ('小雨点',10) + update bbsUsers set uPoint += 10 where uName = '小雨点' + goto delSections +delSections: + alter table bbsTopic drop constraint FK_bbsSection_sID + delete from bbsSection where sID = 3 + goto cleReply +cleReply: + delete from bbsReply + go + + +--在论坛数据库中完成以下题目 +use bbs +go +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select UID,uName,sName from bbsSection left join bbsUsers on sUid = UID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select UID,uName,tTitle,tMsg,tTime from bbsTopic inner join bbsUsers on tUID = UID where tTime > '2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select UID,uName,sName from bbsSection inner join bbsUsers on sUid = UID where uAge < 20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select UID,uName,tTitle,tMsg,tCount from bbsUsers inner join bbsTopic on UID = tUID where tCount in (select MAX(tCount) from bbsTopic) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select UID,uName,sName,COUNT(tID)发帖总数 from bbsTopic left join bbsSection on tUID = sUid left join bbsUsers on sUID = UID group by UID,sID,sName,uName -- Gitee From 9e5e345db432542301ab72a7eb20871b1e9c4bcf Mon Sep 17 00:00:00 2001 From: putar Date: Fri, 26 Mar 2021 17:09:40 +0800 Subject: [PATCH 007/195] 2021-03-26 17:09 --- .../SQLQuery2.sql" | 15 --------------- 1 file changed, 15 deletions(-) diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" index 7c654ae..ce98944 100644 --- "a/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" +++ "b/20210326\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" @@ -37,21 +37,6 @@ insert into orderItem values (1,' (4,'日常用品','透明胶',30,1),(4,'体育用品','羽毛球',20,3) go -use store -go ---查询所有订单订购的所有物品数量总和 -select SUM(theNumber) 所有订单物品数量和 from orderItem ---查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 -select SUM(theNumber) 物品数量, AVG(theMoney) 平均单价 from orderItem where orderID < 3 and theMoney < 10 ---查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 -select COUNT(theNumber) 物品数量,AVG(theMoney) 平均单价 from orderItem where theMoney < 10 and theNumber > 50 ---查询每种类别的产品分别订购了几次 -select itemName,COUNT(theNumber) 订购次数 from orderItem group by itemName ---查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 -select itemType,SUM(theNumber) 订购总数,AVG(theMoney) 平均单价 from orderItem group by itemType having SUM(theNumber) > 100 ---查询每种产品的订购次数,订购总数量和订购的平均单价 -select itemName,COUNT(itemName) 订购次数,SUM(theNumber) 订购总数,theMoney 平均单价 from orderItem group by itemName,theMoney ---使用上次作业的订单数据库,完成下列题目: use store go --1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 -- Gitee From f8eb65074c7e5547a9a9e1216fbfbad477ad7aea Mon Sep 17 00:00:00 2001 From: lazy-scholar-cat <2220771866@qq.com> Date: Fri, 26 Mar 2021 17:09:53 +0800 Subject: [PATCH 008/195] cat --- .../SQLQuery1.sql" | 91 ++++++++++++++ .../SQLQuery2.sql" | 108 ++++++++++++++++ .../SQLQuery3.sql" | 117 ++++++++++++++++++ 3 files changed, 316 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery1.sql" new file mode 100644 index 0000000..80fa12a --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery1.sql" @@ -0,0 +1,91 @@ +create database Student +on +( + FileName='D:\Student.mdf', + Name='Student', + size=5MB, + maxsize=5MB, + filegrowth=3MB +) +log on +( + FileName='D:\Student_log.ldf', + Name='Student_log', + size=5MB, + maxsize=5MB, + filegrowth=3MB +) +go + +use Student + +go + +create table Student +( + StuNo varchar(10) primary key not null, + StuName nvarchar(10) not null, + StuAge int, + StuAddress nvarchar(20), + StuSeat int, + StuSex int check(StuSex=1 or StuSex=0) not null +) + +create table Score +( + ExamNo int primary key identity(1,1) not null, + StuNo varchar(10) not null, + WrittenExam int default(0) not null, + LabExam int not null +) + + +insert into Student values +('s2501','张秋利',20,'美国硅谷',1,1), +('s2502','李斯文',18,'湖北武汉',2,0), +('s2503','马文才',22,'湖南长沙',3,1), +('s2504','欧阳俊雄',21,'湖北武汉',4,0), +('s2505','梅超风',20,'湖北武汉',5,1), +('s2506','陈旋风',19,'美国硅谷',6,1), +('s2507','陈风',20,'美国硅谷',7,0), +('s2508','陈风',20,'美国硅谷',7,0) + + +delete from Student + +select * from Student + + +insert into Score values +('s2501',50,70), +('s2502',60,65), +('s2503',86,85), +('s2504',40,80), +('s2505',70,90), +('s2506',85,90), +('s2507',85,90) + +delete from Score + + + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from Student St inner join Score S on St.StuNo=S.StuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from Student St inner join Score S on St.StuNo=S.StuNo where WrittenExam>60 and LabExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select St.StuNO 学号,StuName 姓名,WrittenExam 笔试成绩,LabExam 机试成绩 from Student St left join Score S on St.StuNo=S.StuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from Student St inner join Score S on St.StuNo=S.StuNo where StuAge>=20 order by WrittenExam DESC + +--5.查询男女生的机试平均分 +select AVG(LabExam) from Student St inner join Score S on St.StuNo=S.StuNo + +--6.查询男女生的笔试总分 + +select sum(WrittenExam) from Student St inner join Score S on St.StuNo=S.StuNo + diff --git "a/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery2.sql" new file mode 100644 index 0000000..b3a7129 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery2.sql" @@ -0,0 +1,108 @@ +create database OrderForm +on +( + FileName='D:\OrderForm.mdf', + Name='OrderForm', + size=5MB, + Maxsize=5MB, + Filegrowth=1MB +) +log on +( + FileName='D:\OrderForm_log.ldf', + Name='OrderForm_log', + size=5MB, + Maxsize=5MB, + Filegrowth=1MB +) +go + +use OrderForm +go + +create table orders +( + orderID int primary key identity(1,1), + orderDate datetime +) + +create table orderltem +( + ltemID int identity(1,1), + orderID int , + itemType nvarchar(15), + itemName nvarchar(10), + theNumber int , + theMoney money +) + +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 orderltem values +(1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'生活用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书机',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'生活用品','毛巾',4,5), +(4,'生活用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) + + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select OS.orderID 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价 from orderltem OS inner join orders O on OS.orderID=O.orderID + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select OS.orderID 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称 from orderltem OS inner join orders O on OS.orderID=O.orderID where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select OS.orderID 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 from orderltem OS inner join orders O on OS.orderID=O.orderID + + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select OS.orderID 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 from orderltem OS inner join orders O on OS.orderID=O.orderID where theMoney>=5 and theNumber>=50 + + + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderID 订单编号,theNumber 订购产品数 from orderltem group by orderID,theNumber + + + + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日 + +select orderID 订单编号,itemType 订购产品的类别,sum(theNumber) 总数量 from orderltem group by orderID,itemType order by orderID + + +select * from orderltem + + + + + + diff --git "a/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" new file mode 100644 index 0000000..c50af9c --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" @@ -0,0 +1,117 @@ +create database bbs +on +( + fileName='D:\bbs.mdf', + Name='bbs', + size=5MB, + Maxsize=5MB, + filegrowth=1MB +) +log on +( + fileName='D:\bbs_log.ldf', + Name='bbs_log', + size=5MB, + Maxsize=5MB, + filegrowth=1MB +) +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +-- +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) +-- +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) +-- +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('男','女')) +-- +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) +-- +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) +-- + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +-- +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values +('小雨点','女',20,0), +('逍遥','男',18,4), +('七年级生','男',19,2) + + +select * into bbsPoint from bbsUsers + +insert into bbsSection values +('技术交流',1), +('读书世界',3), +('生活百科',1), +('八卦区',3) + +insert into bbsTopic values +(2,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0), +(3,1,'.NET','与JAVA的区别是什么呀?',2008-9-1,2), +(1,3,'范跑跑','谁是范跑跑',2008-7-8,1) + +insert into bbsReply values +(2,1,'不知道',2008-9-10), +(3,2,'不知道',2008-9-1), +(1,3,'不知道',2008-7-8) + + + + + + +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sID 版主编号,sName 版块名称,uName 版主姓名 from bbsSection 版主编号 inner join bbsUsers on sUid=UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID,uName,tTItle,tMsg,tTime from bbsTopic inner join bbsUsers on UID=tUID where tTime>'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sID 版主编号,uName 版主姓名,sName 版块名称 from bbsSection inner join bbsUsers on sID=UID where uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tUID 发帖人编号,uName 发帖人姓名,tTItle 主贴标题,tMsg 主贴内容,tCount 回复数量 from bbsTopic inner join bbsUsers on tUID=UID order by tCount DESC + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName 版块,uName 用户,tCount 发帖总数 from bbsTopic inner join bbsUsers on tID=UID inner join bbsSection on sID=tSID -- Gitee From d08117922d37bac6101daccee19ed554454a1ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0=E6=96=B0?= <2523868292@qq.com> Date: Fri, 26 Mar 2021 17:11:32 +0800 Subject: [PATCH 009/195] =?UTF-8?q?=E7=BD=97=E5=AE=87=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 224 ++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery1.sql" diff --git "a/20210326\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery1.sql" new file mode 100644 index 0000000..03bf8a7 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery1.sql" @@ -0,0 +1,224 @@ +use master +go + +create database Students +on +( + name='Students', + filename='D:\11\Students.mdf', + size=5, + maxsize=50, + filegrowth=10% +) +log on +( + name='Students_log', + filename='D:\11\Students_log.mdf', + size=5, + maxsize=50, + filegrowth=10% +) +go + +use Students +go + +create table StuInfo +( + StuNO varchar(5) primary key, + StuName nvarchar(50) not null, + StuAge int not null, + StuAddress nvarchar(50) not null, + StuSeat int not null, + StuSex int default(1) check(StuSex='1' or StuSex='0') +) + +insert into StuInfo values +('s2501','张秋利','20','美国硅谷','1','1'), +('s2502','李斯文','10','湖北武汉','2','0'), +('s2503','马文才','22','武汉长沙','3','1'), +('s2504','欧阳俊雄','21','湖北武汉','4','0'), +('s2505','梅超风','20','湖北武汉','5','1'), +('s2506','陈旋风','19','美国硅谷','6','1'), +('s2507','陈风','20','美国硅谷','7','0') + +create table ExamInfo +( + examNO int primary key, + StuNO varchar(5) foreign key references StuInfo(StuNO), + WittenExam int, + LabExam int +) + +insert into ExamInfo values +('1','s2501','50','70'), +('2','s2502','60','65'), +('3','s2503','86','85'), +('4','s2504','40','80'), +('5','s2505','70','90'), +('6','s2506','85','90') + +select * from StuInfo +select * from ExamInfo + + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName,StuAge,WittenExam,LabExam from StuInfo inner join ExamInfo on StuInfo.StuNO = ExamInfo.StuNO +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuInfo.StuNO,StuName,WittenExam,LabExam from StuInfo inner join ExamInfo on StuInfo.StuNO = ExamInfo.StuNO +where WittenExam>60 and LabExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select * from StuInfo left join ExamInfo on StuInfo.StuNO = ExamInfo.StuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName,StuAge,WittenExam,LabExam from StuInfo inner join ExamInfo on StuInfo.StuNO = ExamInfo.StuNO +where StuAge>20 order by WittenExam +--5.查询男女生的机试平均分 +select StuSex,AVG(LabExam)平均分 from ExamInfo inner join StuInfo on StuInfo.StuNO = ExamInfo.StuNO group by StuSex +--6.查询男女生的笔试总分 +select StuSex,AVG(WittenExam)平均分 from ExamInfo inner join StuInfo on StuInfo.StuNO = ExamInfo.StuNO group by StuSex + + +use Students +go +create table orders +( + orderId int primary key identity, + orderDate datetime, +) + +create table orderItem +( + ItemiD int primary key identity, + orderId int references orders(orderId), + itemType nvarchar(20), + itemName nvarchar(20), + theNumber int, + theMoney money +) + +insert into orders 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 values(1,'文具','笔',72,'2'), +(1,'文具','尺',10,'1'), +(1,'体育用品','篮球',1,'56'), +(2,'文具','笔',36,'2'), +(2,'文具','固体胶',20,'3'), +(2,'日常用品','透明胶',2,'1'), +(2,'体育用品','羽毛球',20,'3'), +(3,'文具','订书机',20,'3'), +(3,'文具','订书针',20,'3'), +(3,'文具','裁纸刀',5,'5'), +(4,'文具','笔',20,'2'), +(4,'文具','信封',50,'1'), +(4,'日常用品','毛巾',4,'5'), +(4,'日常用品','透明胶',30,'1'), +(4,'体育用品','羽毛球',20,'3') +select * from orders +select * from orderItem +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select * from orderItem inner join orders on orderItem.orderId=orders.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderId,orderDate,itemName,itemType from orderItem inner join orders on orderItem.orderId=orders.orderId +where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,SUM(theMoney) 订购总价 +from orderItem inner join orders on orderItem.orderId=orders.orderId +group by orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,SUM(theMoney) 订购总价 +from orderItem inner join orders on orderItem.orderId=orders.orderId where theMoney>5 and theNumber>50 +group by orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderID,sum(theNumber) 订购产品数 from orderItem group by orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 + --2 日常用品 1 20 +select * from orderItem +select orderId,itemType,count(ItemName) 订购次数,sum(theNumber) 总数量 from orderItem group by orderId,itemType + + +use Students +go +create table bbsUsers +( + uID int identity(1,1) not null , + uName nvarchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null + +) +alter table bbsUsers add constraint PK_bbsUsers_uID primary key(uID) +alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 or uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) +create table bbsSection +( + sID int identity(1,1) not null , + sName varchar(10) not null, + sUid int , + +) +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid)references bbsUsers(uID) +create table bbsTopic +( + tID int primary key identity(1,1) not null, + tUID int references bbsUsers(uID) not null , + tSID int references bbsSection(sID) , + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime not null, + tCount int not null, +) +create table bbsReply +( + rID int primary key identity(1,1) not null, + rUID int references bbsUsers(uID) , + rTID int references bbsTopic(tID) , + rMsg text not null, + rTime datetime , +) +go +use Students +go +select * from bbsSection +select * from bbsReply +select * from bbsTopic +select * from bbsUsers +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +insert into bbsSection values('技术名流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑','谁是范跑跑', 2008-7-8,1),(3,2,'.NET','与JAVA的区别是什么呀?',2008-9-1,2),(1,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0) +insert into bbsReply values(2,2,'一名地震自己先跑的教师',2008-7-8),(3,3,'不知道',2008-9-1),(1,1,'流行穿黑裙子',2008-9-10) +update bbsUsers set uPoint=30 where uName='小雨点' +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select tID,sName,uName from bbsTopic inner join bbsSection on sID=tID +inner join bbsUsers on tUID=uID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tID,uName,tTitle,tMsg,tTime from bbsTopic inner join bbsUsers on tUID=uID where tTime>'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select tID,sName,uName from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on tUID=uID +where uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tID,uName,tTitle,tMsg,tCount from bbsTopic inner join bbsUsers on tUID=uID order by tCount DESC +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select tSID 版块,tUID 用户,count(tSID) 发帖总数 from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on tUID=uID +group by tSID,tUID + -- Gitee From a08771d8e26585c3db81084e336b01a0bd96bf71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=86=E7=93=9Ca?= <1991416367@qq.com> Date: Fri, 26 Mar 2021 17:19:30 +0800 Subject: [PATCH 010/195] zy --- .../SQLQuery1.sql" | 53 +++++++++++++++ .../SQLQuery2.sql" | 67 +++++++++++++++++++ .../SQLQuery3.sql" | 16 +++++ 3 files changed, 136 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" new file mode 100644 index 0000000..dd82438 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" @@ -0,0 +1,53 @@ +use master +go +create database task +go +use task +go +create table Student +( +stuid nvarchar(10) primary key, +stuname nvarchar(5) not null , +stuage int , +stuaddress nvarchar(200), +stuseat int identity(1,1), +stusex int check(stusex=1 or stusex=0) +) +create table result +( +examn0 int primary key identity(1,1), +stuid nvarchar(10) references Student(stuid), +writtenexam int check(writtenexam>=0 or writtenexam<=100), +labexam int check(labexam>=0 or labexam<=100) +) + +insert into Student +select 's2501','张秋利','20','美国硅谷','1' union +select 's2502','李斯文','18','湖北武汉','0' union +select 's2503','马文才','22','湖南长沙','1' union +select 's2504','欧阳俊雄','21','湖北武汉','0' union +select 's2505','梅超风','20','湖北武汉','1'union +select 's2506','陈旋风','19','美国硅谷','1' union +select 's2507','陈风','20','美国硅谷','0' +select * from Student +insert into result +select 's2501','50','70' union +select 's2502','60','65' union +select 's2503','86','85' union +select 's2504','40','80' union +select 's2505','70','90' union +select 's2506','85','90' +select * from result + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuname 姓名,stuage 年龄,r.writtenexam 笔试成绩,r.labexam 机试成绩 from Student s inner join result r on s.stuid=r.stuid +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select s.stuname 姓名,s.stuid 学号 ,writtenexam 笔试成绩,labexam 机试成绩 from result r inner join Student s on s.stuid=r.stuid where writtenexam>60 and labexam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select s.stuid 学号,s.stuname 姓名, writtenexam 笔试成绩,labexam 机试成绩 from Student s left join result r on s.stuid=r.stuid +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuname 姓名,stuage 年龄,r.writtenexam 笔试成绩,r.labexam 机试成绩 from Student s inner join result r on s.stuid= r.stuid where s.stuage>=20 order by writtenexam desc +--5.查询男女生的机试平均分 +select avg(r.labexam) 机试平均分,stusex 性别 from Student s inner join result r on s.stuid=r.stuid group by stusex +--6.查询男女生的笔试总分 +select stusex 性别,sum(r.writtenexam) 笔试总分 from Student s inner join result r on s.stuid=r.stuid group by stusex diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery2.sql" new file mode 100644 index 0000000..86154bf --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery2.sql" @@ -0,0 +1,67 @@ +use master +go +create database OrderLibrary +go +use OrderLibrary +go +create table orders +( +orderId int primary key identity(1,1), +orderDate datetime +) +insert into orders +select '2008-01-12 00:00:00.000'union +select '2008-02-10 00:00:00.000'union +select '2008-02-15 00:00:00.000'union +select '2008-03-10 00:00:00.000' +select * from orders +create table orderItem +( +ItemiD int identity(1,1) primary key, +orderId int, +itemType nvarchar(20), +itemName nvarchar(10), +theNumber int, +theMoney int +) +insert into orderItem +select 1,'文具','笔',72,2 union +select 1,'文具','尺',10,1 union +select 1,'体育用品','篮球',1,56 union +select 2,'文具','笔',36,2 union +select 2,'文具','固体胶',20,3 union +select 2,'日常用品','透明胶',2,1 union +select 2,'体育用品','羽毛球',20,3 union +select 3,'文具','订书机',20,3 union +select 3,'文具','订书针',10,3 union +select 3,'文具','裁纸刀',5,5 union +select 4,'文具','笔',20,2 union +select 4,'文具','信纸',50,1 union +select 4,'日常用品','毛巾',4,5 union +select 4,'日常用品','透明胶',30,1 union +select 4,'体育用品','羽毛球',20,3 +select * from orderItem +select * from orders +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select o1.orderId 编号,o1.orderDate 订单日期,o2.itemType 类别 ,o2.itemName 名称,o2.theNumber 数量,o2.theMoney 单价 from orders o1 inner join orderItem o2 on o1.orderId=o2.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select o1.orderId 编号,o1.orderDate 订单日期,o2.itemType 类别,o2.itemName 名称 from orders o1 inner join orderItem o2 on o1.orderId=o2.orderId where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o1.orderId 编号,o1.orderDate 订单日期,o2.itemType 类别,o2.itemName 名称,o2.theNumber 数量,o2.theMoney 单价,o2.theMoney*o2.theNumber 总价 from orders o1 inner join orderItem o2 on o1.orderId=o2.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o1.orderId 编号,o1.orderDate 订单日期,o2.itemType 类别,o2.itemName 名称,o2.theNumber 数量,o2.theMoney 单价,o2.theMoney*o2.theNumber 总价 from orders o1 inner join orderItem o2 on o1.orderId=o2.orderId where o2.theMoney>=5 and o2.theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId 编号,theNumber 数量 from orderItem +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + + --订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select orderId 编号,itemType 产品类别,count(*) 次数,theNumber 总数量 from orderItem group by orderId,itemType,theNumber \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery3.sql" new file mode 100644 index 0000000..eb993fa --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery3.sql" @@ -0,0 +1,16 @@ +3 + +select * from bbsTopic +select * from bbsSection +select * from bbsUsers +select * from bbsReply +--1.查询出每个版块的版主编号 suid,版主姓名 uname和版块名称sname +select bbsSection.sUid 版主编号,bbsUsers.uName 版主姓名,bbsSection.sName 版块名称 from bbsSection inner join bbsUsers on bbsSection.sUid=bbsUsers.uuID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select bt.tUID 编号,bu.uName 姓名,bt.tTitle 标题,bt.tMsg 内容,bt.tTime 时间 from bbsTopic bt inner join bbsUsers bu on bt.tUID=bu.uuID where bt.tTime<2008-9-15 +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select bs.sUid 编号,bu.uName 名称,bs.sName 版块的名称 from bbsUsers bu inner join bbsSection bs on bs.sUid=bu.uuID where bu.uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select max(bt.tCount) ,bt.tUID,bu.uName,bt.tTitle,bt.tMsg from bbsTopic bt inner join bbsUsers bu on bt.tUID=bu.uuID group by tUID,bu.uName,tTitle,tMsg,max(bt.tCount) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select bt.tUID 用户,bu.sID 板块,count(*) 发帖总数 from bbsTopic bt inner join bbsSection bu on bt.tSID=bu.sID group by bt.tUID,bu.sID \ No newline at end of file -- Gitee From 406159ad9ae5ad85db7650eb33910d7c7cf7e9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0=E6=96=B0?= <2523868292@qq.com> Date: Fri, 26 Mar 2021 17:25:43 +0800 Subject: [PATCH 011/195] =?UTF-8?q?=E7=BD=97=E5=AE=87=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 124 +++++++++--------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git "a/20210326\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery1.sql" index 03bf8a7..d3533a7 100644 --- "a/20210326\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery1.sql" +++ "b/20210326\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery1.sql" @@ -34,13 +34,13 @@ create table StuInfo ) insert into StuInfo values -('s2501','张秋利','20','美国硅谷','1','1'), -('s2502','李斯文','10','湖北武汉','2','0'), -('s2503','马文才','22','武汉长沙','3','1'), -('s2504','欧阳俊雄','21','湖北武汉','4','0'), -('s2505','梅超风','20','湖北武汉','5','1'), -('s2506','陈旋风','19','美国硅谷','6','1'), -('s2507','陈风','20','美国硅谷','7','0') +('s2501','寮犵鍒','20','缇庡浗纭呰胺','1','1'), +('s2502','鏉庢柉鏂','10','婀栧寳姝︽眽','2','0'), +('s2503','椹枃鎵','22','姝︽眽闀挎矙','3','1'), +('s2504','娆ч槼淇婇泟','21','婀栧寳姝︽眽','4','0'), +('s2505','姊呰秴椋','20','婀栧寳姝︽眽','5','1'), +('s2506','闄堟棆椋','19','缇庡浗纭呰胺','6','1'), +('s2507','闄堥','20','缇庡浗纭呰胺','7','0') create table ExamInfo ( @@ -62,22 +62,22 @@ select * from StuInfo select * from ExamInfo ---数据如图片1,使用上次作业的数据 +--鏁版嵁濡傚浘鐗1,浣跨敤涓婃浣滀笟鐨勬暟鎹 ---1.查询学生的姓名,年龄,笔试成绩和机试成绩 +--1.鏌ヨ瀛︾敓鐨勫鍚嶏紝骞撮緞锛岀瑪璇曟垚缁╁拰鏈鸿瘯鎴愮哗 select StuName,StuAge,WittenExam,LabExam from StuInfo inner join ExamInfo on StuInfo.StuNO = ExamInfo.StuNO ---2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +--2.鏌ヨ绗旇瘯鍜屾満璇曟垚缁╅兘鍦60鍒嗕互涓婄殑瀛︾敓鐨勫鍙凤紝濮撳悕锛岀瑪璇曟垚缁╁拰鏈鸿瘯鎴愮哗 select StuInfo.StuNO,StuName,WittenExam,LabExam from StuInfo inner join ExamInfo on StuInfo.StuNO = ExamInfo.StuNO where WittenExam>60 and LabExam>60 ---3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +--3.鏌ヨ鎵鏈夊鐢熺殑瀛﹀彿锛屽鍚嶏紝绗旇瘯鎴愮哗锛屾満璇曟垚缁╋紝娌℃湁鍙傚姞鑰冭瘯鐨勫鐢熺殑鎴愮哗浠ULL鍊煎~鍏 select * from StuInfo left join ExamInfo on StuInfo.StuNO = ExamInfo.StuNO ---4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +--4.鏌ヨ骞撮緞鍦20浠ヤ笂锛堝寘鎷20锛夌殑瀛︾敓鐨勫鍚嶏紝骞撮緞锛岀瑪璇曟垚缁╁拰鏈鸿瘯鎴愮哗锛屽苟鎸夌瑪璇曟垚缁╅檷搴忔帓鍒 select StuName,StuAge,WittenExam,LabExam from StuInfo inner join ExamInfo on StuInfo.StuNO = ExamInfo.StuNO where StuAge>20 order by WittenExam ---5.查询男女生的机试平均分 -select StuSex,AVG(LabExam)平均分 from ExamInfo inner join StuInfo on StuInfo.StuNO = ExamInfo.StuNO group by StuSex ---6.查询男女生的笔试总分 -select StuSex,AVG(WittenExam)平均分 from ExamInfo inner join StuInfo on StuInfo.StuNO = ExamInfo.StuNO group by StuSex +--5.鏌ヨ鐢峰コ鐢熺殑鏈鸿瘯骞冲潎鍒 +select StuSex,AVG(LabExam)骞冲潎鍒 from ExamInfo inner join StuInfo on StuInfo.StuNO = ExamInfo.StuNO group by StuSex +--6.鏌ヨ鐢峰コ鐢熺殑绗旇瘯鎬诲垎 +select StuSex,AVG(WittenExam)骞冲潎鍒 from ExamInfo inner join StuInfo on StuInfo.StuNO = ExamInfo.StuNO group by StuSex use Students @@ -102,54 +102,54 @@ insert into orders 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 values(1,'文具','笔',72,'2'), -(1,'文具','尺',10,'1'), -(1,'体育用品','篮球',1,'56'), -(2,'文具','笔',36,'2'), -(2,'文具','固体胶',20,'3'), -(2,'日常用品','透明胶',2,'1'), -(2,'体育用品','羽毛球',20,'3'), -(3,'文具','订书机',20,'3'), -(3,'文具','订书针',20,'3'), -(3,'文具','裁纸刀',5,'5'), -(4,'文具','笔',20,'2'), -(4,'文具','信封',50,'1'), -(4,'日常用品','毛巾',4,'5'), -(4,'日常用品','透明胶',30,'1'), -(4,'体育用品','羽毛球',20,'3') +insert into orderItem values(1,'鏂囧叿','绗',72,'2'), +(1,'鏂囧叿','灏',10,'1'), +(1,'浣撹偛鐢ㄥ搧','绡悆',1,'56'), +(2,'鏂囧叿','绗',36,'2'), +(2,'鏂囧叿','鍥轰綋鑳',20,'3'), +(2,'鏃ュ父鐢ㄥ搧','閫忔槑鑳',2,'1'), +(2,'浣撹偛鐢ㄥ搧','缇芥瘺鐞',20,'3'), +(3,'鏂囧叿','璁功鏈',20,'3'), +(3,'鏂囧叿','璁功閽',20,'3'), +(3,'鏂囧叿','瑁佺焊鍒',5,'5'), +(4,'鏂囧叿','绗',20,'2'), +(4,'鏂囧叿','淇″皝',50,'1'), +(4,'鏃ュ父鐢ㄥ搧','姣涘肪',4,'5'), +(4,'鏃ュ父鐢ㄥ搧','閫忔槑鑳',30,'1'), +(4,'浣撹偛鐢ㄥ搧','缇芥瘺鐞',20,'3') select * from orders select * from orderItem ---使用上次作业的订单数据库,完成下列题目: +--浣跨敤涓婃浣滀笟鐨勮鍗曟暟鎹簱锛屽畬鎴愪笅鍒楅鐩細 ---1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +--1.鏌ヨ鎵鏈夌殑璁㈠崟鐨勮鍗曠殑缂栧彿锛岃鍗曟棩鏈燂紝璁㈣喘浜у搧鐨勭被鍒拰璁㈣喘鐨勪骇鍝佸悕绉帮紝璁㈣喘鏁伴噺鍜岃璐崟浠 select * from orderItem inner join orders on orderItem.orderId=orders.orderId ---2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +--2.鏌ヨ璁㈣喘鏁伴噺澶т簬50鐨勮鍗曠殑缂栧彿锛岃鍗曟棩鏈燂紝璁㈣喘浜у搧鐨勭被鍒拰璁㈣喘鐨勪骇鍝佸悕绉 select orders.orderId,orderDate,itemName,itemType from orderItem inner join orders on orderItem.orderId=orders.orderId where theNumber>50 ---3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 -select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,SUM(theMoney) 订购总价 +--3.鏌ヨ鎵鏈夌殑璁㈠崟鐨勮鍗曠殑缂栧彿锛岃鍗曟棩鏈燂紝璁㈣喘浜у搧鐨勭被鍒拰璁㈣喘鐨勪骇鍝佸悕绉帮紝璁㈣喘鏁伴噺鍜岃璐崟浠蜂互鍙婅璐讳环 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber * theMoney 璁㈣喘鎬讳环 from orderItem inner join orders on orderItem.orderId=orders.orderId group by orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney ---4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 -select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,SUM(theMoney) 订购总价 +--4.鏌ヨ鍗曚环澶т簬绛変簬5骞朵笖鏁伴噺澶т簬绛変簬50鐨勮鍗曠殑璁㈠崟鐨勭紪鍙凤紝璁㈠崟鏃ユ湡锛岃璐骇鍝佺殑绫诲埆鍜岃璐殑浜у搧鍚嶇О锛岃璐暟閲忓拰璁㈣喘鍗曚环浠ュ強璁㈣喘鎬讳环 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber * theMoney 璁㈣喘鎬讳环 from orderItem inner join orders on orderItem.orderId=orders.orderId where theMoney>5 and theNumber>50 group by orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney ---5.查询每个订单分别订购了几个产品,例如: --- 编号 订购产品数 +--5.鏌ヨ姣忎釜璁㈠崟鍒嗗埆璁㈣喘浜嗗嚑涓骇鍝侊紝渚嬪锛 +-- 缂栧彿 璁㈣喘浜у搧鏁 -- 1 3 -- 2 4 -select orderID,sum(theNumber) 订购产品数 from orderItem group by orderId ---6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +select orderID,sum(theNumber) 璁㈣喘浜у搧鏁 from orderItem group by orderId +--6.鏌ヨ姣忎釜璁㈠崟閲岀殑姣忎釜绫诲埆鐨勪骇鍝佸垎鍒璐簡鍑犳鍜屾绘暟閲忥紝渚嬪锛 --- 订单编号 产品类别 订购次数 总数量 +-- 璁㈠崟缂栧彿 浜у搧绫诲埆 璁㈣喘娆℃暟 鎬绘暟閲 --- 1 文具 2 82 --- 1 体育用品 1 1 --- 2 文具 2 56 --- 2 体育用品 1 2 - --2 日常用品 1 20 +-- 1 鏂囧叿 2 82 +-- 1 浣撹偛鐢ㄥ搧 1 1 +-- 2 鏂囧叿 2 56 +-- 2 浣撹偛鐢ㄥ搧 1 2 + --2 鏃ュ父鐢ㄥ搧 1 20 select * from orderItem -select orderId,itemType,count(ItemName) 订购次数,sum(theNumber) 总数量 from orderItem group by orderId,itemType +select orderId,itemType,count(ItemName) 璁㈣喘娆℃暟,sum(theNumber) 鎬绘暟閲 from orderItem group by orderId,itemType use Students @@ -165,7 +165,7 @@ create table bbsUsers ) alter table bbsUsers add constraint PK_bbsUsers_uID primary key(uID) alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) -alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='鐢' or uSex='濂') alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 or uAge<=60) alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) create table bbsSection @@ -202,23 +202,23 @@ select * from bbsSection select * from bbsReply select * from bbsTopic select * from bbsUsers -insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) -insert into bbsSection values('技术名流',1),('读书世界',3),('生活百科',1),('八卦区',3) -insert into bbsTopic values(2,4,'范跑跑','谁是范跑跑', 2008-7-8,1),(3,2,'.NET','与JAVA的区别是什么呀?',2008-9-1,2),(1,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0) -insert into bbsReply values(2,2,'一名地震自己先跑的教师',2008-7-8),(3,3,'不知道',2008-9-1),(1,1,'流行穿黑裙子',2008-9-10) -update bbsUsers set uPoint=30 where uName='小雨点' ---在论坛数据库中完成以下题目 ---1.查询出每个版块的版主编号,版主姓名和版块名称 +insert into bbsUsers values('灏忛洦鐐','濂',20,0),('閫嶉仴','鐢',18,4),('涓冨勾绾х敓','鐢',19,2) +insert into bbsSection values('鎶鏈悕娴',1),('璇讳功涓栫晫',3),('鐢熸椿鐧剧',1),('鍏崷鍖',3) +insert into bbsTopic values(2,4,'鑼冭窇璺','璋佹槸鑼冭窇璺', 2008-7-8,1),(3,2,'.NET','涓嶫AVA鐨勫尯鍒槸浠涔堝憖锛',2008-9-1,2),(1,4,'浠婂勾澶忓ぉ鏈娴佽浠涔','鏈夎皝鐭ラ亾浠婂勾澶忓ぉ鏈娴佽浠涔堝憖锛',2008-9-10,0) +insert into bbsReply values(2,2,'涓鍚嶅湴闇囪嚜宸卞厛璺戠殑鏁欏笀',2008-7-8),(3,3,'涓嶇煡閬',2008-9-1),(1,1,'娴佽绌块粦瑁欏瓙',2008-9-10) +update bbsUsers set uPoint=30 where uName='灏忛洦鐐' +--鍦ㄨ鍧涙暟鎹簱涓畬鎴愪互涓嬮鐩 +--1.鏌ヨ鍑烘瘡涓増鍧楃殑鐗堜富缂栧彿锛岀増涓诲鍚嶅拰鐗堝潡鍚嶇О select tID,sName,uName from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on tUID=uID ---2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +--2.鏌ヨ鍑轰富璐寸殑鍙戝笘鏃堕棿鍦2008-9-15浠ュ悗鐨勪富璐寸殑鍙戝笘浜虹紪鍙凤紝鍙戝笘浜哄鍚嶏紝甯栧瓙鐨勬爣棰橈紝甯栧瓙鐨勫唴瀹瑰拰鍙戝笘鏃堕棿 select tID,uName,tTitle,tMsg,tTime from bbsTopic inner join bbsUsers on tUID=uID where tTime>'2008-9-15' ---3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +--3.鏌ヨ鍑哄勾榫勫湪20浠ヤ笅鐨勭増涓荤殑缂栧彿锛岀増涓荤殑鍚嶇О鍜岀増鍧楃殑鍚嶇О select tID,sName,uName from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on tUID=uID where uAge<20 ---4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +--4.鏌ヨ鍑哄洖澶嶆暟閲忔渶澶氱殑涓昏创鐨勫彂甯栦汉缂栧彿锛屽彂甯栦汉濮撳悕锛屼富璐存爣棰橈紝涓昏创鍐呭鍜屽洖澶嶆暟閲 select top 1 tID,uName,tTitle,tMsg,tCount from bbsTopic inner join bbsUsers on tUID=uID order by tCount DESC ---5.在主贴表中查询每个版块中每个用户的发帖总数 -select tSID 版块,tUID 用户,count(tSID) 发帖总数 from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on tUID=uID +--5.鍦ㄤ富璐磋〃涓煡璇㈡瘡涓増鍧椾腑姣忎釜鐢ㄦ埛鐨勫彂甯栨绘暟 +select tSID 鐗堝潡,tUID 鐢ㄦ埛,count(tSID) 鍙戝笘鎬绘暟 from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on tUID=uID group by tSID,tUID -- Gitee From 6eeba6d8a1c3d72236c868b0cf0dd234f73c16f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E6=98=82?= <2636153719@qq.com> Date: Fri, 26 Mar 2021 17:35:43 +0800 Subject: [PATCH 012/195] =?UTF-8?q?=E8=92=B2=E6=99=93=E9=AA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 101 +++++++++++++++++ .../SQLQuery2.sql" | 77 +++++++++++++ .../SQLQuery3.sql" | 106 ++++++++++++++++++ 3 files changed, 284 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" new file mode 100644 index 0000000..4a46066 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" @@ -0,0 +1,101 @@ +use master +go + +create database Student05 +go + +use Student05 +go + +create table StuIS +( + StuNO nvarchar(10) unique not null, + StuName nvarchar(10) not null, + StuAge int not null, + StuAddress nvarchar(200) , + StuSeat nvarchar(8) not null, + StuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) + +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','张秋利','20','美国硅谷','1','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','李斯文','18','湖北武汉','2','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','马文才','22','湖南长沙','3','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','欧阳俊雄','21','湖北武汉','3','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','梅超风','20','湖北武汉','4','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','陈旋风','19','美国硅谷','5','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','陈风','20','美国硅谷','7','女') + +select *from StuIS +select 学号=StuNO ,姓名=StuName,年龄=StuAge,地址=StuAddress,座位号=StuSeat,性别=StuSex from StuIS +select Stuname,StuAge,StuAddress from StuIS +select 学号=StuNO ,姓名=StuName,地址=StuAddress,邮箱=StuName+StuAddress from StuIS +select distinct StuAddress from StuIS +select distinct StuAge as 所有年龄 from StuIS +select top 3 *from StuIS +select top 4 StuName,StuSeat from StuIS +select top 50 percent *from StuIS +select * from StuIS where StuAddress in ('湖北武汉','湖南长沙') +select * from StuIS where StuAddress='湖北武汉' or StuAddress ='湖南长沙' +select * from StuIS where StuAge is null +select * from StuIS where StuAge is not null +select * from StuIS where StuName like '张%' +select * from StuIS where StuAddress like '%湖%' +select * from StuIS where StuName like '张_' +select * from StuIS where StuName like '__俊%' +select * from StuIS order by StuAge DESC +select * from StuIS order by StuAge DESC , StuSeat ASC + + +create table Grate +( + ExamNo int primary key identity(1,1), + StuNo nvarchar(10) references StuIS(StuNO), + WExam int not null, + LabExam int not null +) +insert into Grate(StuNO,WExam,LabExam) +values('s2501','50','70') +insert into Grate(StuNO,WExam,LabExam) +values('s2502','60','65') +insert into Grate(StuNO,WExam,LabExam) +values('s2503','86','85') +insert into Grate(StuNO,WExam,LabExam) +values('s2504','40','80') +insert into Grate(StuNO,WExam,LabExam) +values('s2505','70','90') +insert into Grate(StuNO,WExam,LabExam) +values('s2506','85','90') + + +select 学号=StuNO , 笔试=WExam,机试=LabExam from Grate +select StuNo as 学号 , WExam as 笔试, LabExam as 机试 from Grate +select StuNo 学号 ,WExam 笔试,LabExam 机试 from Grate +select StuNO, WExam ,LabExam,总分=WExam+LabExam from Grate +select * from Grate where WExam<70 or WExam>90 order by WExam DESC +select top 1 * from Grate order by WExam DESC +select top 1 * from Grate order by WExam ASC + +select *from Grate +select *from StuIS +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName 姓名, StuAge 年龄,WExam 笔试成绩 ,LabExam 机试成绩 from StuIS inner join Grate on StuIS.StuNO = Grate.StuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuName 姓名, StuAge 年龄,WExam 笔试成绩 ,LabExam 机试成绩 from StuIS inner join Grate on StuIS.StuNO = Grate.StuNo where WExam >60 and LabExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuIS.StuNO 学号,StuName 姓名,WExam 笔试成绩 ,LabExam 机试成绩 from StuIS left join Grate on StuIS.StuNO = Grate.StuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName 姓名, StuAge 年龄,WExam 笔试成绩 ,LabExam 机试成绩 from StuIS inner join Grate on StuIS.StuNO = Grate.StuNo where StuAge>20 order by WExam desc + +--5.查询男女生的机试平均分 +select StuIS.StuSex, avg(LabExam) from StuIS left join Grate on StuIS.StuNO = Grate.StuNo group by StuIS.StuSex +--6.查询男女生的笔试总分 +select StuIS.StuSex, sum(WExam) from StuIS left join Grate on StuIS.StuNO = Grate.StuNo group by StuIS.StuSex + diff --git "a/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" new file mode 100644 index 0000000..6014f79 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" @@ -0,0 +1,77 @@ +--先创建如图所示表 +use master +go + +create database Sql +go + +use Sql +go +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) +create table orders +( + orderId int primary key identity, + orderDate date +) +--订购项目表(orderItem),列为: +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) +create table orderItem +( + ItemiD int identity, + orderId int , + itemType nvarchar(20), + itemName nvarchar(20), + 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 values +(1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'生活用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书机',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'生活用品','毛巾',4,5), +(4,'生活用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) +select * from orders +select * from orderItem +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderId 订单编号, orderDate 订单日期,itemType 类别, itemName 产品名称 from orders inner join orderItem on orders.orderId=orderItem.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderId 订单编号, orderDate 订单日期,itemType 类别, itemName 产品名称, theNumber 数量 from orders inner join orderItem on orders.orderId=orderItem.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId 订单编号, orderDate 订单日期,itemType 类别, itemName 产品名称 ,theNumber 数量, theMoney 订购总价, theNumber*theMoney 订购总价 +from orders inner join orderItem on orders.orderId=orderItem.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId 订单编号, orderDate 订单日期,itemType 类别, itemName 产品名称 ,theNumber 数量, theMoney 订购单价, theNumber*theMoney 订购总价 +from orders inner join orderItem on orders.orderId=orderItem.orderId where theMoney>=5 and theNumber>50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderItem.orderId , count(itemType) 订购产品数 from orders inner join orderItem on orders.orderId=orderItem.orderId group by orderItem.orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +-- 订单编号 产品类别 订购次数 总数量 +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select orderItem.orderId 订单编号,itemType 产品类别 , count(itemName) 订购次数,sum(theNumber) 总数量 from orders inner join orderItem on orders.orderId=orderItem.orderId group by orderItem.orderId,itemType order by orderItem.orderId asc diff --git "a/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery3.sql" new file mode 100644 index 0000000..e2e26f1 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery3.sql" @@ -0,0 +1,106 @@ +create database bbs +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +-- +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) +-- +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) +-- +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('男','女')) +-- +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) +-- +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) +-- + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +-- +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values +('小雨点','女',20,0), +('逍遥','男',18,4), +('七年级生','男',19,2) + + +select * into bbsPoint from bbsUsers + +insert into bbsSection values +('技术交流',1), +('读书世界',3), +('生活百科',1), +('八卦区',3) + +insert into bbsTopic values +(2,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0), +(3,1,'.NET','与JAVA的区别是什么呀?',2008-9-1,2), +(1,3,'范跑跑','谁是范跑跑',2008-7-8,1) + +insert into bbsReply values +(2,1,'不知道',2008-9-10), +(3,2,'不知道',2008-9-1), +(1,3,'不知道',2008-7-8) + +select * from bbsUsers +select * from bbsSection +select * from bbsTopic +select * from bbsReply +select * from bbsPoint + + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection inner join bbsUsers on bbsSection.sUid= bbsUsers.UID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTItle 帖子的标题,tMsg 帖子的内容,tTime 发帖时间 from bbsTopic inner join bbsUsers on bbsTopic.tUID= bbsUsers.UID where tTime>'2008-9-15 00:00:00' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称, uAge 年龄 from bbsPoint inner join bbsSection on bbsPoint.UID=bbsSection.sUid where uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tUID 发帖人编号,uName 发帖人姓名,tTItle 主贴标题,tMsg 主贴内容,uPoint 回复数量 from bbsTopic inner join bbsUsers on bbsTopic.tUID= bbsUsers.UID order by uPoint desc +--5.在主贴表中查询 每个版块中 每个用户的 发帖总数 +select sName 版块, uName 用户,count(tTItle) 发帖总数 from bbsTopic +inner join bbsSection on bbsTopic.tUID= bbsSection.sUid +inner join bbsUsers on bbsTopic.tUID= bbsUsers.UID +group by sName , uName + -- Gitee From 8a09a64a1c85e54bac6bb66bb14c45e7f30dac56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E7=A8=8B=E7=A5=A5?= <842143662@qq.com> Date: Fri, 26 Mar 2021 17:37:36 +0800 Subject: [PATCH 013/195] =?UTF-8?q?=E4=B8=87=E7=A8=8B=E7=A5=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 79 ++++++++++++ .../SQLQuery2.sql" | 88 +++++++++++++ .../SQLQuery3.sql" | 116 ++++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" new file mode 100644 index 0000000..3391fae --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" @@ -0,0 +1,79 @@ +use master +go + +create database Student05 +go + +use Student05 +go + +create table StuIS +( + StuNO nvarchar(10) unique not null, + StuName nvarchar(10) not null, + StuAge int not null, + StuAddress nvarchar(200) , + StuSeat nvarchar(8) not null, + StuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) + +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','张秋利','20','美国硅谷','1','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','李斯文','18','湖北武汉','2','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','马文才','22','湖南长沙','3','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','欧阳俊雄','21','湖北武汉','3','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','梅超风','20','湖北武汉','4','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','陈旋风','19','美国硅谷','5','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','陈风','20','美国硅谷','7','女') + +create table Grate +( + ExamNo int primary key identity(1,1), + StuNo nvarchar(10) references StuIS(StuNO), + WExam int not null, + LabExam int not null +) +insert into Grate(StuNO,WExam,LabExam) +values('s2501','50','70') +insert into Grate(StuNO,WExam,LabExam) +values('s2502','60','65') +insert into Grate(StuNO,WExam,LabExam) +values('s2503','86','85') +insert into Grate(StuNO,WExam,LabExam) +values('s2504','40','80') +insert into Grate(StuNO,WExam,LabExam) +values('s2505','70','90') +insert into Grate(StuNO,WExam,LabExam) +values('s2506','85','90') + + +--数据如图片1,使用上次作业的数据 +select * from Grate +select * from StuIS +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName,StuAge ,WExam,LabExam from StuIS +inner join Grate on StuIS.StuNO = Grate.StuNO + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuIS.StuNO ,StuName,WExam,LabExam from StuIS +inner join Grate on StuIS.StuNO = Grate.StuNO where Grate.WExam>=60 and Grate.LabExam>=60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuIS.StuNO ,StuName,WExam,LabExam from StuIS +left join Grate on StuIS.StuNO = Grate.StuNO + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName,StuAge,WExam,LabExam from StuIS +inner join Grate on StuIS.StuNo = Grate.StuNO where StuIS.StuAge>=20 order by Grate.WExam DESC +--5.查询男女生的机试平均分 +select StuSex , avg(LabExam) from StuIS +inner join Grate on StuIS.StuNO = Grate.StuNO group by StuSex +--6.查询男女生的笔试总分 +select StuSex , sum(WExam) from StuIS +inner join Grate on StuIS.StuNO = Grate.StuNO group by StuSex diff --git "a/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" new file mode 100644 index 0000000..b7b081e --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" @@ -0,0 +1,88 @@ +create database OrderIno +go + +use OrderIno +go + +create table orders +( + orderID int primary key identity(1,1), + orderDate datetime +) + +create table orderltem +( + ltemID int identity(1,1), + orderID int , + itemType nvarchar(15), + itemName nvarchar(10), + theNumber int , + theMoney money +) + +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 orderltem values +(1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'生活用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书机',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'生活用品','毛巾',4,5), +(4,'生活用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) + + +--使用上次作业的订单数据库,完成下列题目: + +select * from orders --订单表 +select * from orderltem --订购项目表 + +--订单表(orders)列为:订单编号(orderID 主键) 订购日期(orderDate) --订购项目表(orderItem),列为: --项目编号(ItemID)订单编号(orderID)产品类别(itemType) --产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderID 订单的编号 ,orderDate 订单日期, itemType 订购产品的类别,itemName 订购的产品名称 from orders +inner join orderltem on orders.orderID =orderltem.orderID + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderID 订单的编号 ,orderDate 订单日期, itemType 订购产品的类别,itemName 订购的产品名称 from orders +inner join orderltem on orders.orderID =orderltem.orderID where orderltem.theNumber >50 + + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderID 订单的编号 ,orderDate 订单日期, itemType 订购产品的类别,itemName 订购的产品名称, theNumber 订购数量 ,theMoney 订购单价 , theNumber*theMoney 订购总价 from orders +inner join orderltem on orders.orderID =orderltem.orderID + + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderID 订单的编号 ,orderDate 订单日期, itemType 订购产品的类别,itemName 订购的产品名称, theNumber 订购数量 ,theMoney 订购单价 , theNumber*theMoney 订购总价 from orders +inner join orderltem on orders.orderID =orderltem.orderID where orderltem.theMoney>=5 and orderltem.theNumber>=50 + + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderID 订单的编号 , count(*)订购产品数 from orderltem group by orderID + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +-- 订单编号 产品类别 订购次数 总数量 +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderID 订单的编号 , itemType 产品类别 ,count(*)订购次数 , sum(theNumber) 总数量 + from orderltem group by orderID,itemType order by orderID diff --git "a/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery3.sql" new file mode 100644 index 0000000..052fc54 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery3.sql" @@ -0,0 +1,116 @@ +use master +go + +create database bbs +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +-- +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) +-- +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) +-- +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('男','女')) +-- +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) +-- +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) +-- + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +-- +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values +('小雨点','女',20,0), +('逍遥','男',18,4), +('七年级生','男',19,2) + + +select * into bbsPoint from bbsUsers + +insert into bbsSection values +('技术交流',1), +('读书世界',3), +('生活百科',1), +('八卦区',3) + +insert into bbsTopic values +(2,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0), +(3,1,'.NET','与JAVA的区别是什么呀?',2008-9-1,2), +(1,3,'范跑跑','谁是范跑跑',2008-7-8,1) + +insert into bbsReply values +(2,1,'不知道',2008-9-10), +(3,2,'不知道',2008-9-1), +(1,3,'不知道',2008-7-8) + +select * from bbsReply --回帖表 +select * from bbsSection --版块表 +select * from bbsTopic --主帖表 +select * from bbsUsers --用户信息表 + +--在论坛数据库中完成以下题目 +--1.查询出 每个版块 的 版主编号, 版主姓名 和版块名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection +inner join bbsUsers on bbsUsers.UID = bbsSection.sUid + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTItle 帖子的标题 ,tMsg 帖子的内容,tTime 发帖时间 from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID where tTime>'2008-9-15' + + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection +inner join bbsUsers on bbsUsers.UID = bbsSection.sUid where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select rUID 发帖人编号 , uName 发帖人姓名 ,tTItle 主贴标题 , tMsg 主贴内容 , tCount 回复数量 from bbsReply +inner join bbsTopic on bbsTopic.tUID = bbsReply.rUID +inner join bbsUsers on bbsUsers.UID = bbsReply.rUID where tCount=(select max(tCount) from bbsTopic) + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select tSID 版块 , uName 发帖人姓名 , count(*) from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID +inner join bbsSection on bbsUsers.UID =bbsSection.sID group by tSID ,uName + -- Gitee From fdbd6a40a07c2d04a56eb7ee32de67022221d6a7 Mon Sep 17 00:00:00 2001 From: lazy-scholar-cat <2220771866@qq.com> Date: Fri, 26 Mar 2021 17:37:51 +0800 Subject: [PATCH 014/195] cat --- .../\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" index c50af9c..3e44718 100644 --- "a/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" +++ "b/20210326\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.sql" @@ -114,4 +114,4 @@ select sID select top 1 tUID 发帖人编号,uName 发帖人姓名,tTItle 主贴标题,tMsg 主贴内容,tCount 回复数量 from bbsTopic inner join bbsUsers on tUID=UID order by tCount DESC --5.在主贴表中查询每个版块中每个用户的发帖总数 -select sName 版块,uName 用户,tCount 发帖总数 from bbsTopic inner join bbsUsers on tID=UID inner join bbsSection on sID=tSID +select sName 版块,uName 用户,count(tTItle) 发帖总数 from bbsTopic inner join bbsUsers on tID=UID inner join bbsSection on sID=tSID group by sName,uName -- Gitee From 91b9dd78a4a13cf61ab385a8044d85733e25f2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Fri, 26 Mar 2021 17:37:59 +0800 Subject: [PATCH 015/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=99=88=E6=B5=A9?= =?UTF-8?q?=E5=AE=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\231\210\346\265\251\345\256\207/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" "b/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 565ed7ad7aefd8d451d81d0cad7e83a556674059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Fri, 26 Mar 2021 17:38:16 +0800 Subject: [PATCH 016/195] 1 --- .../SQLQuery9.1.sql" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.1.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.1.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.1.sql" new file mode 100644 index 0000000..afb50fc --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.1.sql" @@ -0,0 +1,64 @@ +create database Student +on +( + name='Student', + filename='D:\Student.mdf', + size=10mb, + maxsize=100mb, + filegrowth=15% +) +log on +( + name='Student_log', + filename='D:\Student_log.ldf', + size=10mb, + maxsize=100mb, + filegrowth=15% +) +go + +use Student +go + +create table StuInfo +( + stuNo char(5) primary key(stuNo), + stuName nvarchar(20), + stuAge int, + stuAddress text, + stuSeat int identity(1,1), + stuSex char(1) check(stuSex in(1,0)) +) + +create table StuExam +( + examNo int identity(1,1), + stuNo char(5), + writtenExam int check(writtenExam>=0 and writtenExam<=100), + labExam int check(labExam>=0 and labExam<=100) +) + + alter table StuExam add constraint RK_StuExam_stuNo foreign key(stuNo) references StuInfo(stuNo) + + insert into StuInfo 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 values + ('s2501',50,70),('s2502',60,65),('s2503',86,85),('s2504',40,80),('s2505',70,90),('s2506',85,90) + select * from StuInfo + select * from StuExam +select stuName,stuAge,writtenexam,labexam from StuInfo inner join StuExam on StuInfo.stuNo = StuExam.stuNo +select StuInfo.stuNo,stuName,writtenexam,labexam from StuInfo inner join StuExam on StuInfo.stuNo = StuExam.stuNo where writtenexam>60 and labexam>60 +--.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuInfo.stuNo,stuName,writtenexam,labexam from StuInfo left join StuExam on StuInfo.stuNo = StuExam.stuNo +--查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName, stuAge,writtenexam,labexam from StuInfo inner join StuExam on StuInfo.stuNo = StuExam.stuNo where stuAge>=20 order by writtenexam desc +----查询男女生的机试平均分 +select stuSex,AVG(labexam) from StuInfo inner join StuExam on StuInfo.stuNo = StuExam.stuNo group by stuSex +--6.查询男女生的笔试总分 +select stuSex,sum(writtenexam) from StuInfo inner join StuExam on StuInfo.stuNo = StuExam.stuNo group by stuSex -- Gitee From 326f38111028f876f7915320f79f76d37b20bee4 Mon Sep 17 00:00:00 2001 From: zhangyife2020 <1599857331@qq.com> Date: Fri, 26 Mar 2021 18:29:08 +0800 Subject: [PATCH 017/195] =?UTF-8?q?=E7=AC=AC3.26=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 70 ++++++++++++++ .../SQLQuery2.sql" | 70 ++++++++++++++ .../SQLQuery3.sql" | 91 +++++++++++++++++++ 3 files changed, 231 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" new file mode 100644 index 0000000..3b869f1 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" @@ -0,0 +1,70 @@ +use master +go +create database Student1 +on +( name=' Student1', + filename='D:\Student1.mdf', + size=5mb, + maxsize=5000mb, + filegrowth=15% + +) + log on +( name='Student1_log', + filename='D:\Student1_log.ldf', + size=5mb, + maxsize=5000mb, + filegrowth=15% +) +go +use Student1 +go + +create table StuInfo +( + stuNo char(5) primary key(stuNo), + stuName nvarchar(20), + stuAge int, + stuAddress text, + stuSeat int identity(1,1), + stuSex char(1) check(stuSex in(1,0)) +) + +create table StuExam +( + examNo int identity(1,1), + stuNo char(5), + writtenExam int check(writtenExam>=0 and writtenExam<=100), + labExam int check(labExam>=0 and labExam<=100) +) + + alter table StuExam add constraint RK_StuExam_stuNo foreign key(stuNo) references StuInfo(stuNo) + + insert into StuInfo 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 values + ('s2501',50,70),('s2502',60,65),('s2503',86,85),('s2504',40,80),('s2505',70,90),('s2506',85,90) + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from StuInfo SI join StuExam SE on SI.stuNo=SE.stuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from StuInfo SI join StuExam SE on SI.stuNo=SE.stuNo where writtenExam >60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from StuInfo SI left join StuExam SE on SI.stuNo=SE.stuNo +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 + select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from StuInfo join StuExam on StuInfo.stuNo=StuExam.stuNo where stuAge>=20 order by writtenExam desc +--5.查询男女生的机试平均分 + --1为男 0为女 +select stuSex,avg(labExam) 机试平均分 from StuInfo SI join StuExam SE on SI.stuNo=SE.stuNo group by stuSex +--6.查询男女生的笔试总分 +select stuSex,sum(writtenExam)from StuInfo SI join StuExam SE on SI.stuNo=SE.stuNo group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery2.sql" new file mode 100644 index 0000000..214f60f --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery2.sql" @@ -0,0 +1,70 @@ +use master +go +create database od12 +on +( name='od12', + filename='D:\test\od12.mdf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) + log on +( name='od12_log', + filename='D:\test\od12_log.ldf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +go +use od12 +go +create table orders +( orderId int primary key, + orderDate nchar(23) +) + +create table orderItem +( ItemiD int, + orderId int references orders(orderId), + itemType nchar(4) not null, + itemName nchar(4) not null, + theNumber int, + theMoney int +) +insert into orders values(1,'2008-01-12 00:00:00.000'),(2,'2008-02-10 00:00:00.000'), + (3,'2008-02-15 00:00:00.000'),(4,'2008-03-10 00:00:00.000') + +insert into orderItem values(1,1,'文具','笔',72,2),(2,1,'文具','尺',10,1),(3,1,'体育用品','篮球',1,56), + (4,2,'文具','笔',36,2),(5,2,'文具','固体胶',20,3),(6,2,'日常用品','透明胶',2,1), + (7,2,'体育用品','羽毛球',20,3),(8,3,'文具','订书机',20,3),(9,3,'文具','订书针',10,3), + (10,3,'文具','裁缝刀',5,5),(11,4,'文具','笔',20,2),(12,4,'文具','信纸',50,1), + (13,4,'日常用品','毛巾',4,5),(14,4,'日常用品','透明胶',30,1),(15,4,'体育用品','羽毛球',20,3) + + +select* from orders + +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select*from orders join orderItem on orders.orderId=orderItem.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select*from orders join orderItem on orders.orderId=orderItem.orderId where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem .orderId 订单的编号, orders.orderDate 订单日期 ,itemType 产品的类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价, theNumber*theMoney 订购总价 from orders join orderItem on orders.orderId=orderItem.orderId group by orderItem.orderId,itemType,itemName,theNumber,theMoney +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单的编号,orders.orderDate 订单日期 ,itemType 产品的类别,itemName 产品名称,theNumber 订购数量, theNumber*theMoney 订购总价 from orders join orderItem on orders.orderId=orderItem.orderId where theMoney>=5 and theNumber>=50 group by orderItem.orderId,itemType,itemName,theNumber,theMoney +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderItem.orderId 编号,count(itemType) 订购产品数 from orders join orderItem on orders.orderId=orderItem.orderId group by orderItem.orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 +select orderItem.orderId 订单编号 ,itemType 产品类别 ,count(itemType) 订购次数,sum(theNumber) 总数量 from orders join orderItem on orders.orderId=orderItem.orderId group by orderItem.orderId,itemType \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery3.sql" new file mode 100644 index 0000000..60d036f --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery3.sql" @@ -0,0 +1,91 @@ +use master +go +create database bbs1 +on +( name='bbs1', + filename='D:\test\bbs1.mdf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +log on +( name='bbs1_log', + filename='D:\test\bbs1_log.ldf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +go +use bbs1 +go +create table bbsUsers +( UID int identity(1,1), + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +select*from bbsUsers +alter table bbsUsers add constraint Pk_bbsUsers_UID primary key(UID) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex in('男','女')) +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uPoint>=0) + +create table bbsSection +( sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) + +alter table bbsSection add constraint Pk_bbsSection_sID primary key(sID) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) +select*from bbsSection + + +create table bbsTopic +( tID int primary key identity(1,1), + tUID int references bbsUsers(UID), + tSID int references bbsSection( sID ), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime , + tCount int +) + +select*from bbsTopic +create table bbsReply +( rID int primary key identity(1,1), + rUID int references bbsUsers(UID), + rTID int references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +insert into bbsTopic values + (2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'), + (3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), + (1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') +insert into bbsReply values(3,1,'谁问的谁就是范跑跑','20210316'), + (1,2,'这个更简单','20210316'), + (1,3,'今年夏天最流行内裤外穿','20210316') + +select*from bbsReply +select*from bbsSection +select*from bbsUsers + + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select UID 版主编号,uName 版主姓名,sName 版块名称 from bbsSection join bbsUsers on bbsSection.sUid=bbsUsers.UID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号, bbsUsers.UID 发帖人姓名, tTitle 帖子的标题, tMsg 帖子的内容, tTime 发帖时间 from bbsTopic join bbsUsers on bbsUsers.UID=bbsTopic.tUID where tTime >'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select bbsSection.sUid 版主的编号, bbsUsers.uName 版主的名称,bbsSection.sName 版块的名称 from bbsSection join bbsUsers on bbsUsers.UID=bbsSection.sUid where bbsUsers.uAge<=20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 bbsTopic.tUID 发帖人编号,bbsUsers.uName 用户 , tTitle 帖子的标题 , tMsg 帖子的内容 ,bbsTopic.tCount 回复数量 from bbsTopic join bbsReply on bbsTopic.tID=bbsReply.rTID join bbsUsers on bbsUsers.UID=bbsTopic.tUID order by bbsTopic.tCount desc +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select bbsSection.sName 板块名称, bbsUsers.uName 用户 , count(tUID) from bbsTopic join bbsUsers on bbsUsers.UID=bbsTopic.tUID join bbsSection on bbsSection.sUid=bbsUsers.UID group by sName,uName -- Gitee From 07409c7fe97340bec0adc71297394a7fc8093c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BB=BA=E5=B3=B0?= <357616491@qq.com> Date: Fri, 26 Mar 2021 19:09:59 +0800 Subject: [PATCH 018/195] ljf --- .../\347\273\203\344\271\240\344\270\200.sql" | 73 ++++++++++++++ .../\347\273\203\344\271\240\344\270\211.sql" | 98 +++++++++++++++++++ .../\347\273\203\344\271\240\344\272\214.sql" | 91 +++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\270\200.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\270\211.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\272\214.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\270\200.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\270\200.sql" new file mode 100644 index 0000000..0045b27 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\270\200.sql" @@ -0,0 +1,73 @@ +use master +go + +create database Student05 +go + +use Student05 +go + +create table StuIS +( + StuNO nvarchar(10) unique not null, + StuName nvarchar(10) not null, + StuAge int not null, + StuAddress nvarchar(200) , + StuSeat nvarchar(8) not null, + StuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) + +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','张秋利','20','美国硅谷','1','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','李斯文','18','湖北武汉','2','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','马文才','22','湖南长沙','3','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','欧阳俊雄','21','湖北武汉','3','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','梅超风','20','湖北武汉','4','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','陈旋风','19','美国硅谷','5','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','陈风','20','美国硅谷','7','女') + + +create table Grate +( + ExamNo int primary key identity(1,1), + StuNo nvarchar(10) references StuIS(StuNO), + WExam int not null, + LabExam int not null +) +insert into Grate(StuNO,WExam,LabExam) +values('s2501','50','70') +insert into Grate(StuNO,WExam,LabExam) +values('s2502','60','65') +insert into Grate(StuNO,WExam,LabExam) +values('s2503','86','85') +insert into Grate(StuNO,WExam,LabExam) +values('s2504','40','80') +insert into Grate(StuNO,WExam,LabExam) +values('s2505','70','90') +insert into Grate(StuNO,WExam,LabExam) +values('s2506','85','90') + +select *from StuIS +select *from Grate + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName 姓名,StuAge 年龄,WExam 笔试成绩,LabExam 机试成绩 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuIS.StuNO 学号, StuName 姓名,WExam 笔试成绩, LabExam 机试成绩 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo +where WExam>60 and LabExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuIS.StuNO 学号, StuName 姓名, WExam 笔试成绩,LabExam 机试成绩 from StuIS left join Grate on StuIS.StuNO=Grate.StuNo +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName 姓名,StuAge 年龄,WExam 笔试成绩, LabExam 机试成绩 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo +where StuAge>=20 order by WExam +--5.查询男女生的机试平均分 +select StuSex 性别,AVG(LabExam) 机试平均分 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo group by StuSex +--6.查询男女生的笔试总分 +select StuSex 性别,sum(WExam)笔试总分 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\270\211.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\270\211.sql" new file mode 100644 index 0000000..4c53e41 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\270\211.sql" @@ -0,0 +1,98 @@ +use master +go + +create database bbs +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) + +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('男','女')) +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) +insert into bbsUsers values +('小雨点','女',20,0), +('逍遥','男',18,4), +('七年级生','男',19,2) + + +insert into bbsSection values +('技术交流',1), +('读书世界',3), +('生活百科',1), +('八卦区',3) + +insert into bbsTopic values +(2,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0), +(3,1,'.NET','与JAVA的区别是什么呀?',2008-9-1,2), +(1,3,'范跑跑','谁是范跑跑',2008-7-8,1) + +insert into bbsReply values +(2,1,'不知道',2008-9-10), +(3,2,'不知道',2008-9-1), +(1,3,'不知道',2008-7-8) + + + +--1.查询出 每个版块 的 版主编号, 版主姓名 和版块名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection +inner join bbsUsers on bbsUsers.UID = bbsSection.sUid + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTItle 帖子的标题 ,tMsg 帖子的内容,tTime 发帖时间 from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID where tTime>'2008-9-15' + + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection +inner join bbsUsers on bbsUsers.UID = bbsSection.sUid where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select rUID 发帖人编号 , uName 发帖人姓名 ,tTItle 主贴标题 , tMsg 主贴内容 , tCount 回复数量 from bbsReply +inner join bbsTopic on bbsTopic.tUID = bbsReply.rUID +inner join bbsUsers on bbsUsers.UID = bbsReply.rUID where tCount=(select max(tCount) from bbsTopic) + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select tSID 版块 , uName 发帖人姓名 , count(*) from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID +inner join bbsSection on bbsUsers.UID =bbsSection.sID group by tSID ,uName \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\272\214.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\272\214.sql" new file mode 100644 index 0000000..e475baa --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\347\273\203\344\271\240\344\272\214.sql" @@ -0,0 +1,91 @@ +use master +go +create database orde +on +( +name='orde', +filename='D:\orde.mdf', +size=5mb, +filegrowth=10mb, +maxsize=10mb +) +log on +( +name='orde_log', +filename='D:\orde_log.ldf', +size=5mb, +filegrowth=10mb, +maxsize=10mb +) +go +create table orders +( +orderld int primary key identity(1,1) not null, +orderDate datetime not null +) +create table orderltem +( +ltemiD int primary key identity(1,1) not null, +orderld int not null, +itemType nvarchar(20) not null, +itemName nvarchar(20) not null, +theNumber int not null, +theMoney money not null +) + insert into orders 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 orderltem values + (1,'文具','笔','72','2'), + (1,'文具','尺','10','1'), + (1,'体育用品','篮球','1','56'), + (2,'文具','笔','36','2'), + (2,'文具','固体胶','20','3'), + (2,'日常用品','透明胶','2','1'), + (2,'体育用品','羽毛球','20','3'), + (3,'文具','订书机','20','3'), + (3,'文具','订书针','10','3'), + (3,'文具','裁纸刀','5','5'), + (4,'文具','笔','20','2'), + (4,'文具','信纸','50','1'), + (4,'日常用品','毛巾','4','5'), + (4,'日常用品','透明胶','30','1'), + (4,'体育用品','羽毛球','20','3') + + select * from orders + select * from orderltem + + + +-- 1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orders.orderld 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价 from orders inner join orderltem on orders.orderld=orderltem.orderld + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderld 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称 from orders inner join orderltem on orders.orderld=orderltem.orderld +where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderld 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,theMoney * theNumber 订购总价 from orders inner join orderltem on orders.orderld=orderltem.orderld +group by orders.orderld,orderDate,itemType,itemName,theNumber,theMoney + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderld 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价, theMoney * theNumber 订购总价 from orders inner join orderltem on orders.orderld=orderltem.orderld +where theMoney>5 and theNumber>50 group by orders.orderld,orderDate,itemType,itemName,theNumber,theMoney +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderld 订单的编号 , count(*)订购产品数 from orderltem group by orderld + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +-- 订单编号 产品类别 订购次数 总数量 +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderld 订单的编号 , itemType 产品类别 ,count(*)订购次数 , sum(theNumber) 总数量 from orderltem group by orderld,itemType order by orderld \ No newline at end of file -- Gitee From 9eff2479c80d6ae5f0be665cdfe70667ae58990c Mon Sep 17 00:00:00 2001 From: li-qingcai <2811189126@qq.com> Date: Fri, 26 Mar 2021 19:12:48 +0800 Subject: [PATCH 019/195] 3.26 --- .../SQLQuery2.sql" | 28 ++++++++++++ .../SQLQuery5.sql" | 45 +++++++++++++++++++ .../SQLQuery7.sql" | 16 +++++++ 3 files changed, 89 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery5.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery7.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery2.sql" new file mode 100644 index 0000000..c647641 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery2.sql" @@ -0,0 +1,28 @@ + +--数据如图片1,使用上次作业的数据 +select * from stuinfo +select * from StuMark +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuinfo.StuNo, StuName 姓名 ,StuAge 年龄,writtenExam 笔试成绩 ,labExam 机试成绩 +from stuinfo inner join StuMark on stuinfo.StuNo = StuMark.StuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuinfo.StuNo, StuName 姓名 ,StuAge 年龄,writtenExam 笔试成绩 ,labExam 机试成绩 +from stuinfo inner join StuMark on stuinfo.StuNo = StuMark.StuNo +where writtenExam >60 and labExam >60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuinfo.StuNo 学号, StuName 姓名 ,StuAge 年龄,writtenExam 笔试成绩 ,labExam 机试成绩 +from stuinfo left join StuMark on stuinfo.StuNo = StuMark.StuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuinfo.StuNo 学号, StuName 姓名 ,StuAge 年龄,writtenExam 笔试成绩 ,labExam 机试成绩 +from stuinfo left join StuMark on stuinfo.StuNo = StuMark.StuNo +where StuAge>=20 +order by writtenExam desc +--5.查询男女生的机试平均分 +select StuSex 性别, avg(labExam) 机试平均成绩 +from stuinfo left join StuMark on stuinfo.StuNo = StuMark.StuNo +group by StuSex +--6.查询男女生的笔试总分 +select StuSex 性别, sum(writtenExam) 笔试总分 +from stuinfo left join StuMark on stuinfo.StuNo = StuMark.StuNo +group by StuSex diff --git "a/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery5.sql" "b/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery5.sql" new file mode 100644 index 0000000..cf04b6b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery5.sql" @@ -0,0 +1,45 @@ + +--使用上次作业的订单数据库,完成下列题目: + select *from orderItem + select *from orders +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + select orderItem.orderId 编号,orderDate 订单日期,itemType 类别,itemName 名称,theNumber 数量,theMoney 单价 + from orderItem left join orders on orderItem.orderId= orders.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 + select orderItem.orderId 编号,orderDate 订单日期,itemType 类别,itemName 名称 ,theNumber 数量,theMoney 单价 + from orderItem left join orders on orderItem.orderId= orders.orderId + where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + select orderItem.orderId 编号,orderDate 订单日期,itemType 类别,itemName 名称,theNumber 数量,theMoney 单价 ,theMoney*theNumber 总价 + from orderItem left join orders on orderItem.orderId= orders.orderId group by orderItem.orderId ,orderDate,itemType,itemName ,theMoney,theNumber +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + + select orderItem.orderId 编号,orderDate 订单日期,itemType 类别,itemName 名称,theNumber 数量,theMoney 单价 ,theMoney*theNumber 总价 + from orderItem left join orders on orderItem.orderId= orders.orderId + where theNumber>= 50 and theMoney<=5 + group by orderItem.orderId ,orderDate,itemType,itemName ,theMoney,theNumber + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 + select *from orderItem + select *from orders + + + select orderId 编号 ,itemName 名称, sum(theNumber) 订购产品数 from orderItem group by orderId, itemName + --6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + select orderId 编号 ,itemType 类别 ,count(itemType)订购次数 ,sum(theNumber) 订购产品数 from orderItem group by orderId, itemType + + + + + diff --git "a/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery7.sql" "b/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery7.sql" new file mode 100644 index 0000000..dd8aaa7 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery7.sql" @@ -0,0 +1,16 @@ +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select UID 版主编号,uName 版主姓名,sName 版块名称 +from bbsSection join bbsUsers on bbsSection.sUid=bbsUsers.UID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号, bbsUsers.UID 发帖人姓名, tTitle 帖子的标题, tMsg 帖子的内容, tTime 发帖时间 +from bbsTopic join bbsUsers on bbsUsers.UID=bbsTopic.tUID where tTime >'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select bbsSection.sUid 版主的编号, bbsUsers.uName 版主的名称,bbsSection.sName 版块的名称 +from bbsSection join bbsUsers on bbsUsers.UID=bbsSection.sUid where bbsUsers.uAge<=20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 bbsTopic.tUID 发帖人编号,bbsUsers.uName 用户 , tTitle 帖子的标题 , tMsg 帖子的内容 ,bbsTopic.tCount 回复数量 +from bbsTopic join bbsReply on bbsTopic.tID=bbsReply.rTID join bbsUsers on bbsUsers.UID=bbsTopic.tUID order by bbsTopic.tCount desc +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select bbsSection.sName 板块名称, bbsUsers.uName 用户 , count(tUID) +from bbsTopic join bbsUsers on bbsUsers.UID=bbsTopic.tUID join bbsSection on bbsSection.sUid=bbsUsers.UID group by sName,uName \ No newline at end of file -- Gitee From 82ff11dd40b07493a3f91a6cf0e7317a72d2eea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E9=82=B5=E6=98=A0?= <2934277968@qq.com> Date: Fri, 26 Mar 2021 19:44:33 +0800 Subject: [PATCH 020/195] 1 --- .../zuoye1.sql" | 72 +++++++++++++++++ .../zuoye2.sql" | 81 +++++++++++++++++++ .../zuoye3.sql" | 79 ++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye3.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye1.sql" "b/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye1.sql" new file mode 100644 index 0000000..a47a3f7 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye1.sql" @@ -0,0 +1,72 @@ +use master +go + +create database aa +go + +use aa +go + +create table StuIS +( + StuNO nvarchar(10) unique not null, + StuName nvarchar(10) not null, + StuAge int not null, + StuAddress nvarchar(200) , + StuSeat nvarchar(8) not null, + StuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) + +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','张秋利','20','美国硅谷','1','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','李斯文','18','湖北武汉','2','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','马文才','22','湖南长沙','3','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','欧阳俊雄','21','湖北武汉','3','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','梅超风','20','湖北武汉','4','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','陈旋风','19','美国硅谷','5','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','陈风','20','美国硅谷','7','女') + +create table Grate +( + ExamNo int primary key identity(1,1), + StuNo nvarchar(10) references StuIS(StuNO), + WExam int not null, + LabExam int not null +) +insert into Grate(StuNO,WExam,LabExam) +values('s2501','50','70') +insert into Grate(StuNO,WExam,LabExam) +values('s2502','60','65') +insert into Grate(StuNO,WExam,LabExam) +values('s2503','86','85') +insert into Grate(StuNO,WExam,LabExam) +values('s2504','40','80') +insert into Grate(StuNO,WExam,LabExam) +values('s2505','70','90') +insert into Grate(StuNO,WExam,LabExam) +values('s2506','85','90') +select * from StuIS +select * from Grate + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName,StuAge,WExam,LabExam from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuIS.StuNo,StuName,StuAge,WExam,LabExam from StuIS + inner join Grate on StuIS.StuNO=Grate.StuNo where WExam>60 and LabExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuIS.StuNo,StuName,StuAge,WExam,LabExam from StuIS left join Grate on StuIS.StuNO=Grate.StuNo +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName,StuAge,WExam,LabExam from StuIS + inner join Grate on StuIS.StuNO=Grate.StuNo where StuAge>20 order by WExam DESC +--5.查询男女生的机试平均分 +select StuSex,avg(LabExam) 笔试平均分 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo group by StuSex +--6.查询男女生的笔试总分 +select StuSex,sum(WExam) 笔试总分 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye2.sql" "b/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye2.sql" new file mode 100644 index 0000000..394123f --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye2.sql" @@ -0,0 +1,81 @@ +use master +go + +create database Student05 +go + +use Student05 +go +create table orders +( +orderId int primary key identity (1,1), +orderDate date, + +) +go +create table orderItem +( +ItemiD int, +orderId int, +itemType nvarchar(10), +itemName nvarchar(20), +theNumber int, +theMoney money, +) + +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 values +(1,1,'文具','笔',72,2), +(2,1,'文具','尺',10,1), +(3,1,'体育用品','篮球',1,56), +(4,2,'文具','笔',36,2), +(5,2,'文具','固体胶',20,3), +(6,2,'生活用品','透明胶',2,1), +(7,2,'体育用品','羽毛球',20,3), +(8,3,'文具','订书机',20,3), +(9,3,'文具','订书机',10,3), +(10,3,'文具','裁纸刀',5,5), +(11,4,'文具','笔',20,2), +(12,4,'文具','信纸',50,1), +(13,4,'生活用品','毛巾',4,5), +(14,4,'生活用品','透明胶',30,1), +(15,4,'体育用品','羽毛球',20,3) +select* from orders +select* from orderItem +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderId,orderDate,itemType,itemName,theMoney,theMoney from orders + inner join orderItem on orders.orderId=orderItem.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderId,orderDate,itemType,itemName from orders +inner join orderItem on orders.orderId=orderItem.orderId where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId,orderDate,itemType,itemName,theMoney,theMoney from orders + inner join orderItem on orders.orderId=orderItem.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId,orderDate,itemType,itemName,theMoney,theMoney from orders + inner join orderItem on orders.orderId=orderItem.orderId where theMoney>=5 and theNumber>=50 + select* from orderItem +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderItem.orderId,count(itemName)订购产品数 from orderItem + left join orders on orderItem.orderId=orders.orderId group by orderItem.orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +select orderItem.orderId,itemType, count(theNumber)订购次数,sum(theNumber)订购数量 from orderItem + left join orders on orderItem.orderId=orders.orderId group by orderItem.orderId,itemType +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye3.sql" "b/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye3.sql" new file mode 100644 index 0000000..cd3fe75 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye3.sql" @@ -0,0 +1,79 @@ +use master +go +create database bbs +on +( +name='bbs', +filename='D:\SQL\bbs.mdf' +) +log on +( +name='bbs_log', +filename='D:\SQL\bbs_log.ldf' +) +go +use bbs +go +create table bbsUsers +( +UID int primary key identity(1,1), +uName varchar(10) not null, +uSex varchar(2) not null check(uSex='男' or uSex='女'), +uAge int not null check(uAge>=15 and uAge<=40), +uPoint int not null check(uPoint>=0) +) +go +create table bbsTopic +( +tID int primary key identity(1,1), +tUID int, +tSID int, +tTitle varchar(100) not null, +tMsg text not null, +tTime datetime, +tCount int +) +go +create table bbsReply +( +rID int primary key identity(1,1), +rUID int constraint FK_bbsUsers_UID references bbsUsers(UID), +rTID int constraint FK_bbsTopic_tID references bbsTopic(tID), +rMsg text not null, +rTime datetime +) +go +create table bbsSection +( +sID int primary key identity(1,1), +sName varchar(10) not null, +sUid int, +) +go +alter table bbsTopic add constraint FK_bbsUsers1_UID foreign key(tUID) references bbsUsers(UID) +alter table bbsTopic add constraint FK_bbsSection_sID foreign key(tSID) references bbsSection(sID) +alter table bbsSection add constraint FK_bbsUsers2_UID foreign key(sUid) references bbsUsers(UID) +insert into bbsUsers(uName,uSex,uAge,uPoint) values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection(sName,sUid) values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) values(2,4,'范跑跑','谁是范跑跑','2008-7-8',1),(3,1,'.NET','与JAVA的区别是什么呀?','2008-9-1',2),(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀','2008-9-10',0) +insert into bbsReply(rMsg,rTime,rUID,rTID) values('666','2008-1-1',1,2),('666','2008-1-1',2,3),('666','2008-1-1',3,1) +select * from bbsUsers--信 +select * from bbsTopic--主 +select * from bbsReply--回 +select * from bbsSection--版 +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select UID,sName,uName from bbsUsers inner join bbsSection on bbsUsers.UID=bbsSection.sUid +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID,uName,tTitle,tMsg,tTime from bbsTopic + inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID where tTime>2008-09-15 +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select UID,uName,sName from bbsUsers inner join bbsSection on bbsUsers.UID=bbsSection.sUid where uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 + select UID,uName,tTitle,tMsg,tCount from bbsUsers inner join bbsTopic on bbsUsers.UID=bbsTopic.tUID + where tCount=(select MAX(tCount) from bbsTopic) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName,uName,count(tID) 发帖总数 from bbsUsers +left join bbsSection on bbsUsers.UID=bbsSection.sUid +left join bbsTopic on bbsUsers.UID=bbsTopic.tUID group by sName,uName \ No newline at end of file -- Gitee From 6383824d6d99c81ec523902ebf419c57a6ba9160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=93=A6=E7=89=B9=E5=8F=91?= <3144531710@qq.com> Date: Fri, 26 Mar 2021 19:45:25 +0800 Subject: [PATCH 021/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\346\275\230\345\256\207/SQLQuery1.sql" | 71 +++++++++++ .../\346\275\230\345\256\207/SQLQuery2.sql" | 103 +++++++++++++++ .../\346\275\230\345\256\207/SQLQuery3.sql" | 118 ++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery1.sql" new file mode 100644 index 0000000..635c5d0 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery1.sql" @@ -0,0 +1,71 @@ +use master +go +create database student +on +( +name='str', +size=5, +filename='D:\str.mdf', +filegrowth=1, +maxsize=50 +) +log on +( +name='str_log', +size=5, +filename='D:\str_log.ldf', +filegrowth=1, +maxsize=50 +) +use Student +go + +create table StuInfo +( + stuNo char(5) primary key(stuNo), + stuName nvarchar(20), + stuAge int, + stuAddress text, + stuSeat int identity(1,1), + stuSex char(1) check(stuSex in(1,0)) +) +go +create table StuExam +( + examNo int identity(1,1), + stuNo char(5), + writtenExam int check(writtenExam>=0 and writtenExam<=100), + labExam int check(labExam>=0 and labExam<=100) +) + go + alter table StuExam add constraint RK_StuExam_stuNo foreign key(stuNo) references StuInfo(stuNo) + + insert into StuInfo values + ('s2501','张秋利',20,'美国硅谷',1), + ('s2502','李斯文',18,'湖北武汉',0), + ('s2503','马文才',22,'湖南长沙',1), + ('s2504','欧阳俊雄',21,'湖北武汉',0), + ('s2505','梅超风',20,'湖北武汉',1), + ('s2506','陈旋风',19,'美国硅谷',1), + ('s2507','陈风',20,'美国硅谷',0) + + delete from StuExam + + insert into StuExam values + ('s2501',50,70),('s2502',60,65),('s2503',86,85),('s2504',40,80),('s2505',70,90),('s2506',85,90),('s2507',50,40) + --数据如图片1,使用上次作业的数据 + select * from StuInfo inner join StuExam on StuExam.stuNo=StuInfo.stuNo +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select * from StuInfo +select * from StuExam +select StuExam.labExam,stuName,stuAge,writtenExam from StuInfo inner join StuExam on StuExam.stuNo=StuInfo.stuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuExam.stuNo,labExam,stuName,writtenExam from StuExam inner join StuInfo on StuExam.stuNo=StuInfo.stuNo WHERE StuExam.labExam>60 and writtenExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuExam.stuNo,labExam,stuName,writtenExam from StuExam right join StuInfo on StuExam.stuNo=StuInfo.stuNo +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuInfo.stuAge,labExam,stuName,writtenExam from StuExam inner join StuInfo on StuExam.stuNo=StuInfo.stuNo where stuAge>=20 order by labExam +--5.查询男女生的机试平均分 +select stuSex,avg(labExam) from StuInfo inner join StuExam on StuExam.stuNo=StuInfo.stuNo group by stuSex +--6.查询男女生的笔试总分 +select stuSex,avg(writtenExam) from StuInfo inner join StuExam on StuExam.stuNo=StuInfo.stuNo group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" new file mode 100644 index 0000000..2e4d077 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" @@ -0,0 +1,103 @@ +use master +go +create database Aa +on +( + name='Aa', + filename='E:\Aa.mdf' +) +log on +( + name='Aa_log', + filename='E:\Aa_log.ldf' +) +go + +use Aa +go +--drop table orderItem +create table orders +( + orderId int primary key, + orderDate date +) +go +create table orderItem +( + ItemiD int identity(1,1) primary key, + orderId int references orders(orderId), + itemType varchar(12), + itemName varchar(12), + theNumber int, + theMoney money +) +go +insert into orders values + (1,'2008-01-12'), + (2,'2008-02-10'), + (3,'2008-02-15'), + (4,'2008-03-10') +insert into orderItem values + (1,'文具','笔',72,2), + (1,'文具','尺',10,1), + (1,'体育用品','篮球',1,56), + (2,'文具','笔',36,2), + (2,'文具','固体胶',20,3), + (2,'日常用品','透明胶',2,1), + (2,'体育用品','羽毛球',20,3), + (3,'文具','订书机',20,3), + (3,'文具','订书针',10,3), + (3,'文具','裁纸刀',5,5), + (4,'文具','笔',20,2), + (4,'文具','信纸',50,1), + (4,'日常用品','毛巾',4,5), + (4,'日常用品','透明胶',30,1), + (4,'体育用品','羽毛球',20,3) +--1.查询所有订单订购的所有物品数量总和 +select sum(theNumber) '订购物品总量' from orderItem +--2.查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select orderId,sum(theNumber) '订购物品总量',avg(theMoney) '平均单价' from orderItem group by orderId +having orderId<3 and avg(theMoney)<10 +--3.查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select orderId,sum(theNumber) '订购物品总量',avg(theMoney) '平均单价' from orderItem group by orderId +having avg(theMoney)>10 and sum(theNumber)>50 +--4.查询每种类别的产品分别订购了几次,例如: +-- 文具 9 +-- 体育用品 3 +-- 日常用品 3 +select itemType '类别',count(*) '分别订购了几次' from orderItem group by itemType +--5.查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select itemType '类别',sum(theNumber) '订购物品总量',avg(theMoney) '平均单价' from orderItem +group by itemType having sum(theNumber)>50 +--6.查询每种产品的订购次数,订购总数量和订购的平均单价,例如: +select itemName '产品名称',count(*) '订购次数',sum(theNumber) '订购物品总量',avg(theMoney) '平均单价' from orderItem +group by itemName +-- 产品名称 订购次数 总数量 平均单价 +-- 笔 3 120 2 +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select * from orders +select * from orderItem +select orders.orderId,orderDate,itemType,itemName from orderItem inner join orders on orderItem.orderId=orders.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId,orderDate,itemType,itemName from orders inner join orderItem on orderItem.orderId=orders.orderId where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId,orderDate,itemType,itemName,theMoney,theMoney*theNumber from orders inner join orderItem on orders.orderId=orderItem.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.theMoney,theNumber from orders inner join orderItem on orders.orderId=orderItem.orderId where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId,sum(theNumber) from orderItem group by orderId +--6.查询每个订单里 的每个类别 的产品分别订购了几次 和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select orderItem.orderId,itemType,count(theNumber) from orderItem inner join orders on orderItem.orderId=orders.orderId order by orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery3.sql" new file mode 100644 index 0000000..0b72f24 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery3.sql" @@ -0,0 +1,118 @@ +use master +go +create database bbs1 +on +( name='bbs1', + filename='D:\bbs1.mdf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +log on +( name='bbs1_log', + filename='D:\bbs1_log.ldf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +go +use bbs1 +go +create table bbsUsers +( UID int identity(1,1), + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +select*from bbsUsers +alter table bbsUsers add constraint Pk_bbsUsers_UID primary key(UID) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex in('男','女')) +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uPoint>=0) + +create table bbsSection +( sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +alter table bbsSection add constraint Pk_bbsSection_sID primary key(sID) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + +select*from bbsSection + + +create table bbsTopic +( tID int primary key identity(1,1), + tUID int references bbsUsers(UID), + tSID int references bbsSection( sID ), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime , + tCount int +) + +select*from bbsTopic +create table bbsReply +( rID int primary key identity(1,1), + rUID int references bbsUsers(UID), + rTID int references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +--1.现在有3个会员注册成功,请用一次插入多行数据的方法向bbsUsers表种插入3行记录,记录值如下: +-- 小雨点 女 20 0 +-- 逍遥 男 18 4 +-- 七年级生 男 19 2 + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) + + +-- 2.将bbsUsers表中的用户名和积分两列备份到新表bbsPoint表中,提示查询部分列:select 列名1,列名2 from 表名 + +select uName, upoint into bbsPoint from bbsUsers + + +-- 3.给论坛开设4个板块 + 名称 版主名 + 技术交流 小雨点 + 读书世界 七年级生 + 生活百科 小雨点 + 八卦区 七年级生 +-- 4.向主贴和回帖表中添加几条记录 +insert into bbsTopic values + (2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'), + (3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), + (1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') + +--人数不够,外键有约束 +update bbsTopic set tSID=3 where tSID=1 + +select*from bbsUsers +select*from bbsTopic +-- 回帖: +-- 分别给上面三个主贴添加对应的回帖,回帖的内容,时间,回帖人自定 + +insert into bbsReply values(3,1,'谁问的谁就是范跑跑','20210316'), + (1,2,'这个更简单','20210316'), + (1,3,'今年夏天最流行内裤外穿','20210316') +select*from bbsReply +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select * from bbsUsers +select * from bbsSection +select * from bbsTopic +select * from bbsReply +select UID,uName,sName from bbsUsers inner join bbsSection on bbsUsers.UID=bbsSection.sUid +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select UID,uName,tTitle,tMsg,tTime from bbsUsers inner join bbsTopic on bbsUsers.UID=bbsTopic.tUID where tTime>'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +SELECT bbsUsers.uAge,sID,sName,sUid FROM bbsUsers INNER JOIN bbsSection ON bbsUsers.UID=bbsSection.sid WHERE uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select UID,uName,tTitle,tMsg,tCount from bbsUsers inner join bbsTopic on bbsUsers.UID=bbsTopic.tUID where tCount=(select MAX(tCount) from bbsTopic) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName,uName,count(tID) 发帖总数 from bbsUsers left join bbsSection on bbsUsers.UID=bbsSection.sUid left join bbsTopic on bbsUsers.UID=bbsTopic.tUID group by sName,uName -- Gitee From 0c2c3cc48a02e69d49f9d238112d1becc4304c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=BF=E6=A3=AE?= <2287431003@qq.com> Date: Fri, 26 Mar 2021 19:47:08 +0800 Subject: [PATCH 022/195] sql --- .../\346\273\225\351\221\253/SQLQuery1.sql" | 47 ++++++++++++ .../\346\273\225\351\221\253/SQLQuery2.sql" | 46 ++++++++++++ .../\346\273\225\351\221\253/SQLQuery3.sql" | 75 +++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" new file mode 100644 index 0000000..b823254 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" @@ -0,0 +1,47 @@ +create database Student +on +( + name='Student', + filename='D:\Student.mdf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='Student_log', + filename='D:\Student_log.ldf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +go +use Student +go +create table stuinfo +( + stuNO nvarchar(10) unique not null, + stuName nvarchar(10) not null, + stuAge int not null, + stuAddress nvarchar(200) , + stuSeat nvarchar(10) not null, + stuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) +create table stuexam +( + examNO int primary key identity(1,1), + stuno nvarchar(10) , + writtenexam int not null, + labexam int not null +) +insert into stuinfo(stuNO,stuName,stuAge,stuAddress,stuSeat,stuSex) +values('s2501','张秋利','20','美国硅谷','1','男'),('s2502','李斯文','18','湖北武汉','2','女'),('s2503','马文才','22','湖南长沙','3','男'), +('s2504','欧阳俊雄','21','湖北武汉','4','女'),('s2505','梅超风','20','湖北武汉','5','男'),('s2506','陈旋风','19','美国硅谷','6','男'),('s2507','陈风','20','美国硅谷','7','女') +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') + +select stuName 姓名,stuAge 年龄,writtenexam 笔试,labexam 机试 from stuinfo t left join stuexam x on t.stuNo=x.stuNo +select stuName 姓名,stuAge 年龄,writtenexam 笔试,labexam 机试 from stuinfo t left join stuexam x on t.stuNo=x.stuNo where writtenexam>60 and labexam>60 +select stuName 姓名,stuAge 年龄,writtenexam 笔试,labexam 机试 from stuinfo t left join stuexam x on t.stuNo=x.stuNo +select stuName 姓名,stuAge 年龄,writtenexam 笔试,labexam 机试 from stuinfo t left join stuexam x on t.stuNo=x.stuNo where stuAge>=20 order by writtenexam desc +select count(stuSex) 性别,avg(labexam) 机试平均分 from stuinfo t left join stuexam x on t.stuNo=x.stuNo group by stuSex +select count(stuSex) 性别,sum(writtenexam) 笔试总分 from stuinfo t left join stuexam x on t.stuNo=x.stuNo group by stuSex diff --git "a/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" new file mode 100644 index 0000000..fb087b2 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" @@ -0,0 +1,46 @@ +create database tx +on +( + name='tx', + size=10, + filename='D:\tx.mdf', + maxsize=100, + filegrowth=10 +) +log on +( + name='tx_log', + size=10, + filename='D:\tx_log.ldf', + maxsize=100, + filegrowth=10 +) +go +use tx +go +create table orders +( + orderId int primary key identity not null, + orderDate datetime default(getdate()) +) +create table orderItem +( + ItemiD int primary key identity not null, + orderId int, + itemType nvarchar(20), + itemName nvarchar(20), + theNumber int, + theMoney money +) +insert into orderItem values (1,'文具','笔',72,2),(1,'文具','尺',10,1),(1,'体育用品','篮球',1,56),(2,'文具','笔',36,2),(2,'文具','固体胶',20,3), +(2,'日常用品','透明胶',2,1),(2,'体育用品','羽毛球',20,3),(3,'文具','订书机',20,3),(3,'文具','订书钉',10,3),(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2),(4,'文具','信纸',50,1),(4,'日常用品','毛巾',4,5),(4,'日常用品','透明胶',30,1),(4,'体育用品','羽毛球',20,3) +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 +select * from orderItem +select t.orderId 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价 from orderItem t left join orders x on t.orderId=x.orderId +select t.orderId 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称 from orderItem t left join orders x on t.orderId=x.orderId where theNumber>50 +select t.orderId 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 from orderItem t left join orders x on t.orderId=x.orderId +select t.orderId 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 from orderItem t left join orders x on t.orderId=x.orderId where theMoney>=5 and theNumber>=50 +select t.orderId 订单的编号,count(itemType) 订购产品数 from orderItem t left join orders x on t.orderId=x.orderId group by t.orderId +select t.orderId 订单的编号,itemType 订购产品数,count(itemType) 订购次数,sum(theNumber)总数量 from orderItem t left join orders x on t.orderId=x.orderId group by t.orderId,itemType order by t.orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery3.sql" new file mode 100644 index 0000000..3fdf386 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery3.sql" @@ -0,0 +1,75 @@ +create database bbs +on +( + name='bbs', + filename='D:\bbs.mdf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='D:\bbs_log.ldf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +go +use bbs +go +create table bbsUsers +( + UIDD int identity, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +create table bbsSection +( + sIDD int identity, + sName varchar(10) not null, + sUid int +) + +alter table bbsUsers add constraint Pk_bbsUsers_UIDD primary key(UIDD) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uPoint check(uPoint>=0) + +alter table bbsSection add constraint Pk_bbsSection_sIDD primary key(sIDD) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UIDD) + +create table bbsTopic +( + tID int identity primary key, + tUID int foreign key references bbsUsers(UIDD), + tSID int foreign key references bbsSection(sIDD), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int identity primary key, + rUID int foreign key references bbsUsers(UIDD), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'),(3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), +(1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') +insert into bbsReply values(3,2,'不就是你嘛','2008-7-8'),(1,1,'面对对象','2008-7-8'),(1,3,'拖鞋','2008-7-8') + +select sIDD,uName,sName from bbsSection t left join bbsUsers x on t.sIDD=x.UIDD +select tUID,uName,tTitle,tMsg,tTime from bbsTopic t left join bbsUsers x on t.tID=x.UIDD where tTime > '2008-09-15' +select sIDD,uName,sName from bbsSection t left join bbsUsers x on t.sIDD=x.UIDD where uAge<20 +select top 1 tUID,uName,tTitle,tMsg,tCount from bbsUsers t left join bbsTopic x on t.UIDD=x.tID order by tCount desc +select sName,uName,count(tTitle)发帖总数 from bbsTopic t left join bbsSection x on t.tID=x.sIDD left join bbsUsers a on x.sIDD=a.UIDD group by uName,sName \ No newline at end of file -- Gitee From c42ef9720999957df2d4f33941868b1f3d51f9dc Mon Sep 17 00:00:00 2001 From: yang-wenrong <956352682@qq.com> Date: Fri, 26 Mar 2021 19:49:55 +0800 Subject: [PATCH 023/195] 2021.3.26 --- .../SQLQuery1.sql" | 107 ++++++++++++++++ .../SQLQuery2.sql" | 112 ++++++++++++++++ .../SQLQuery3.sql" | 121 ++++++++++++++++++ 3 files changed, 340 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" new file mode 100644 index 0000000..ed8287a --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" @@ -0,0 +1,107 @@ +use master +go +create database StuScore +on +( + name='StuScore', + filename='D:\StuScore.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='StuScore_log', + filename='D:\StuScore_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go +use StuScore +go +Create table stuinfo +( + stuNO varchar(20) primary key not null, + stuName nvarchar(20) check(len(StuName)>=2), + stuAge int check(StuAge>=0 AND StuAge<200) default(18) not null, + stuAddress varchar(20) not null, + stuSeat int identity(1,1), + stuSex char(1) check(stuSex='1'or stuSex='0') +) +insert into stuinfo +select 's2501','张秋利','20','美国硅谷','1' union +select 's2502','李斯文','18','湖北武汉','0' union +select 's2503','马文才','22','湖南长沙','1' union +select 's2504','欧阳俊雄','21','湖北武汉','0' union +select 's2505','梅超风','20','湖北武汉','1'union +select 's2506','陈旋风','19','美国硅谷','1' union +select 's2507','陈风','20','美国硅谷','0' +select * from stuinfo + + +Create table stuexam +( + examNO int primary key identity(1,1), + stuNO varchar(20) constraint FK_stuexam_stuNO references stuinfo(stuNO), + writtenExam int check(writtenExam>=0 AND writtenExam<=100), + labExam int check(labExam>=0 AND labExam<=100) +) +insert into stuexam +select 's2501','50','70' union +select 's2502','60','65' union +select 's2503','86','85' union +select 's2504','40','80' union +select 's2505','70','90' union +select 's2506','85','90' +select * from stuexam + + +select * from stuinfo +select 学生学号=stuNO,学生姓名=stuName,学生年龄=stuAge,学生地址=stuAddress,学生座位=stuSeat,学生性别=stuSex from stuinfo +select stuName,stuAge,stuAddress from stuinfo +select stuNO,writtenExam,labExam from stuexam +select 学号=stuNO,笔试=writtenExam,机试=labExam from stuexam +select stuNO 学号,writtenExam 笔试,labExam 机试 from stuexam +select stuNO as 学号,writtenExam as 笔试,labExam as 机试 from stuexam +select stuNO,stuName,stuAddress from stuInfo +select stuName+'@'+stuAddress 邮箱 from stuinfo +select stuNO 学号,writtenExam 笔试,labExam 机试,writtenExam+labExam 总分 from stuexam +select distinct stuAddress from stuInfo +select distinct stuAge 所有年龄 from stuInfo +select top 3 * from stuInfo +select top 4 stuName,stuSeat from stuInfo +select top 30 percent * from stuInfo +select * from stuInfo where stuAddress in ('湖北武汉') and stuAge in (20) +select * from stuExam where labExam>=60 and labExam<=80 order by labExam DESC +select * from stuInfo where stuAddress in ('湖北武汉') or stuAddress in ('湖南长沙') +select * from stuInfo where stuAddress in ('湖北武汉','湖南长沙') +select * from stuExam where not writtenExam>=70 and writtenExam<=90 order by writtenExam ASC +select * from stuInfo where stuAge is null or stuAge='' +select * from stuInfo where stuAge is not null or not stuAge='' +select * from stuInfo where stuName like '张%' +select * from stuInfo where stuAddress like '%湖%' +select * from stuInfo where stuName like '张_' +select * from stuInfo where stuName like '__俊%' +select * from stuInfo order by stuAge DESC +select * from stuInfo order by stuAge DESC,stuSeat ASC +select top 1 * from stuExam order by writtenExam DESC +select top 1 * from stuExam order by labExam ASC + + +--1.查询学生的 姓名 , 年龄 ,笔试成绩 和 机试成绩 +select * from stuinfo --姓名和年龄 +select * from stuexam--笔试和机试 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from stuinfo inner join stuexam on stuinfo.stuNO=stuexam.stuNO +--2.查询 笔试和机试成绩都在60分以上的 学生 的 学号,姓名,笔试成绩和机试成绩 +select stuinfo.stuNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from stuinfo inner join stuexam on stuinfo.stuNO=stuexam.stuNO where stuexam.writtenExam>60 and stuexam.labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuinfo.stuNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from stuinfo left join stuexam on stuinfo.stuNO=stuexam.stuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuinfo.stuNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from stuinfo left join stuexam on stuinfo.stuNO=stuexam.stuNO +where stuAge>=20 order by writtenExam DESC + +--5.查询男女生的机试平均分 +select stuName 姓名,stuSex 性别,avg(labExam) 机试平均分 from stuinfo left join stuexam on stuinfo.stuNO=stuexam.stuNO group by stuName,stuSex +--6.查询男女生的笔试总分 +select stuSex 性别,sum(writtenExam) 笔试平均分 from stuinfo left join stuexam on stuinfo.stuNO=stuexam.stuNO group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery2.sql" new file mode 100644 index 0000000..fcd2bff --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery2.sql" @@ -0,0 +1,112 @@ +use master +go +--先创建如图所示表 +create database OrderShop +on +( + name='OrderShop', + filename='D:\OrderShop.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='OrderShop_log', + filename='D:\OrderShop_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go +use OrderShop +go + +create table orders +( + orderId int primary key identity(1,1), + orderDate datetime +) + +create table orderItem +( + ItemId int primary key identity(1,1), + orderId int foreign key references orders(orderId), + itemType nvarchar(20), + itemName nvarchar(20), + theNumer int, + theMoney int, +) +insert into orders values +('2008-01-12'),('2008-02-10'),('2008-02-15'),('2008-03-10') + +insert into orderItem values +(1,'文具','笔','72','2'), +(1,'文具','尺','10','1'), +(1,'体育用品','篮球','1','56'), +(2,'文具','笔','36','2'), +(2,'文具','固体胶','20','3'), +(2,'日常用品','透明胶','2','1'), +(2,'体育用品','羽毛球','20','3'), +(3,'文具','订书机','20','3'), +(3,'文具','订书针','10','3'), +(3,'文具','裁纸刀','5','5'), +(4,'文具','笔','20','2'), +(4,'文具','信纸','50','1'), +(4,'日常用品','毛巾','4','5'), +(4,'日常用品','透明胶','30','1'), +(4,'体育用品','羽毛球','20','3') + + +--1.查询所有订单订购的所有物品数量总和 +select sum(theNumer) 所有物品数量总和 from orderItem +--2.查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select sum(theNumer) 所有物品的数量,avg(theMoney) 平均单价 from orderItem group by orderId having orderId<3 and avg(theMoney)<10 +--3.查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select sum(theNumer) 所有物品的数量,avg(theMoney) 平均单价 from orderItem group by orderId having sum(theNumer)>50 and avg(theMoney)<10 +--4.查询每种类别的产品分别订购了几次,例如: +-- 文具 9 +-- 体育用品 3 +-- 日常用品 3 +select itemType,count(*) 订购次数 from orderItem group by itemType +--5.查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select sum(theNumer)订购总数量 ,avg(theMoney) 平均单价 from orderItem group by itemType having sum(theNumer)>100 +--6.查询每种产品的订购次数,订购总数量和订购的平均单价,例如: + +-- 产品名称 订购次数 总数量 平均单价 +-- 笔 3 120 2 + + + +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的 订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select * from orderItem +select * from orders + +select orderItem.orderId 订单的编号,orderDate 订单日期,itemType 类别,itemName 产品名称,theNumer 订购数量,theMoney 订购单价 from orderItem inner join orders on orderItem.orderId=orders.orderId +--2.查询订购数量大于50 的 订单的编号, 订单日期, 订购产品的类别 和 订购的产品名称 +select orderItem.orderId 订单的编号,orderDate 订单日期,itemType 类别,itemName 产品名称 from orderItem inner join orders on orderItem.orderId=orders.orderId +group by orderItem.orderId,orderDate,itemType,itemName having sum(theNumer)>50 +--3.查询 所有的订单的订单的编号, 订单日期, 订购产品的类别和 订购的产品名称,订购数量 和订购单价 以及订购总价 +select orderItem.orderId 订单的编号,orderDate 订单日期,itemType 类别,itemName 产品名称,theNumer 订购数量,theMoney 订购单价,sum(theMoney*theNumer) 订购总价 from orderItem inner join orders on orderItem.orderId=orders.orderId +group by orderItem.orderId,orderDate,itemType,itemName,theNumer,theMoney +--4.查询单价大于等于5并且数量大于等于50的订单的 订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单的编号,orderDate 订单日期,itemType 类别,itemName 产品名称,theNumer 订购数量,theMoney 订购单价,sum(theMoney*theNumer) 订购总价 from orderItem inner join orders on orderItem.orderId=orders.orderId +where theMoney>=5 and theNumer>=50 +group by orderItem.orderId,orderDate,itemType,itemName,theNumer,theMoney +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId,count(*) 订购产品数 from orderItem group by orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +select orderId,itemType,count(*) 订购次数,sum(theNumer) 总数量 from orderItem group by orderId,itemType +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery3.sql" new file mode 100644 index 0000000..b2e7fb2 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery3.sql" @@ -0,0 +1,121 @@ +use master +go +create database bbs +on +( + name='bbs', + filename='D:\bbs.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='bbs_log', + filename='D:\bbs_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go +use bbs +go + +create table bbsUsers +( + UID int identity(1,1), + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null, +) + +alter table bbsUsers add constraint PK_bbsUsers_UID primary key (UID) +alter table bbsUsers add constraint UQ_bbsUsers_uName unique (uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_upoint check(uPoint>=0) + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int, +) +alter table bbsSection add constraint PK_bbsSection_sID primary key (sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key (sUid) references bbsUsers(UID) + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int constraint FK_bbsTopic_tUID references bbsUsers(UID), + tSID int constraint FK_bbsTopic_tSID references bbsSection(sID), + tTitle varchar(100) not null, + tMsg nvarchar(200) not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int primary key identity(1,1), + rUID int constraint FK_bbsReply_rUID references bbsUsers(UID), + rTID int constraint FK_bbsReply_rTID references bbsTopic(tID), + rMsg nvarchar(200) not null, + rTime datetime +) + +insert into bbsUsers +select '小雨点','女','20', '0'union +select'逍遥', '男', '18', '4'union +select '七年级生','男','19', '2' +select uName,uPoint into bbsPoint from bbsUsers + +insert into bbsSection +select '技术交流',1 union +select '读书世界',3 union +select '生活百科',1 union +select' 八卦区',3 + +insert into bbsTopic +select 2,4,'范跑跑','谁是范跑跑',' 2008-7-8',1 union +select 3,1,'.NET','与JAVA的区别是什么呀?','2008-9-1',2 union +select 1,3,'今年夏天最流行什么',' 有谁知道今年夏天最流行什么呀?',' 2008-9-10',0 +insert into bbsReply +select 1,1,'随便','2020-12-01' union +select 2,2,'随便','2020-12-01' union +select 3,3,'随便','2020-12-01' + +alter table bbsTopic drop FK_bbsTopic_tUID +alter table bbsReply drop FK_bbsReply_rUID +alter table bbsSection drop FK_bbsSection_sUid +delete bbsUsers where uName='逍遥' + +update bbsUsers set uPoint=10 where uName='小雨点' + +alter table bbsTopic drop FK_bbsTopic_tSID +delete bbsSection where sName='生活百科' + +truncate table bbsReply + +select * from bbsPoint +select * from bbsReply +select * from bbsSection +select * from bbsTopic +select * from bbsUsers + + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sID 版主编号,uName 版主姓名,sName 版块名称 from bbsSection bS inner join bbsUsers bU on bS.sID=bU.UID +--2.查询出主贴的 发帖时间在2008-9-15以后的主贴的 发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTitle 标题,tMsg 内容,tTime 发帖时间 from bbsTopic inner join bbsUsers on bbsTopic.tID=bbsUsers.UID where tTime>'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sID 版主编号,uName 版主姓名,sName 版块名称 from bbsSection bS inner join bbsUsers bU on bS.sID=bU.UID where uAge<20 +--4.查询出 回复数量最多的主贴的 发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select tUID 发帖人编号,uName 发帖人姓名,tTitle 主贴标题,tMsg 主贴内容,tCount 回复数量 from bbsTopic inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID +where tCount=(select max(tCount) from bbsTopic) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName 版块,uName 用户,count(*)发帖总数 from bbsTopic +left join bbsUsers on bbsTopic.tUID=bbsUsers.UID +left join bbsSection on bbsTopic.tUID=bbsSection.sUid +group by sName,uName \ No newline at end of file -- Gitee From ab2d2cd57bafd93b6d84e1cbc40365d00a6533bc Mon Sep 17 00:00:00 2001 From: yu-sijie <1609873552@qq.com> Date: Fri, 26 Mar 2021 19:51:48 +0800 Subject: [PATCH 024/195] =?UTF-8?q?SQL=E7=AC=AC=E5=8D=81=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\275\234\344\270\232\344\270\200.sql" | 102 +++++++++++ .../\344\275\234\344\270\232\344\270\211.sql" | 158 ++++++++++++++++++ .../\344\275\234\344\270\232\344\272\214.sql" | 107 ++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\270\200.sql" create mode 100644 "20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\270\211.sql" create mode 100644 "20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\272\214.sql" diff --git "a/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\270\200.sql" "b/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\270\200.sql" new file mode 100644 index 0000000..0a1164f --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\270\200.sql" @@ -0,0 +1,102 @@ +use master +go + +create database Student2 +on +( + name='Student2', + filename='D:\SQL作业\SQL作业4\Student2.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='Student2_log', + filename='D:\SQL作业\SQL作业4\Student2_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use Student2 +go +create table StuInfo +( + StuNo varchar(20) primary key , + StuName nchar(20) not null, + StuAge int not null, + StuAdress varchar(20) not null, + StuSeat int not null, + StuSex char(2) not null +) +go + +insert into StuInfo(StuNo,StuName,StuAge,StuAdress,StuSeat,StuSex) values +('s2501','张秋利',20,'美国硅谷',1,'女'),('s2502','李斯文',18,'湖北武汉',2,'男'), +('s2503','马文才',22,'湖南长沙',3,'女'),('s2504','欧阳俊雄',21,'湖北武汉',4,'男'), +('s2505','梅超风',20,'湖北武汉',5,'女'),('s2506','陈旋风',19,'美国硅谷',6,'女'), +('s2507','陈风',20,'美国硅谷',7,'男') +go + +insert into StuInfo(StuNo,StuName,StuAge,StuAdress,StuSeat,StuSex) values +('s2508','张三',25,'福建南平',3,'男'),('s2509','李四',18,'福建龙岩',2,'男'), +('s2510','王五',22,'湖南长沙',3,'男') +go + +select * from StuInfo + + +use Student2 +go +create table Score +( + ExamNo int primary key identity(1,1), + StuNO varchar(20) not null, + WrittenExam int not null, + LabExam int not null +) +go + +insert into Score(StuNo,WrittenExam,LabExam) values +('s2501',50,70),('s2502',60,65),('s2503',86,85), +('s2504',40,80),('s2505',70,90),('s2506',85,90) +go + +select * from Score +select * from StuInfo + + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from +StuInfo inner join Score on StuInfo.StuNo = Score.StuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuInfo.StuNo 学号,StuName 姓名,WrittenExam 笔试成绩,LabExam 机试成绩 from StuInfo +inner join Score on StuInfo.StuNo = Score.StuNo where WrittenExam>60 and LabExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuInfo.StuNo 学号,StuName 姓名,WrittenExam 笔试成绩,LabExam 机试成绩 from StuInfo +left join Score on StuInfo.StuNo = Score.StuNo + + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from StuInfo inner join Score on +StuInfo.StuNo = Score.StuNo where StuAge>20 order by WrittenExam desc + +--5.查询男女生的机试平均分 +select StuSex 性别,avg(LabExam)机试平均分 from StuInfo inner join Score on StuInfo.StuNo = Score.StuNo group by StuSex + + +--6.查询男女生的笔试总分 +select StuSex 性别,sum(WrittenExam)笔试总分 from StuInfo inner join Score on StuInfo.StuNo = Score.StuNo group by StuSex + + + + +select * from Score +select * from StuInfo \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\270\211.sql" "b/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\270\211.sql" new file mode 100644 index 0000000..c0ed109 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\270\211.sql" @@ -0,0 +1,158 @@ +use master +go +create database bbs +on +( + name='bbs', + filename='D:\SQL作业\SQL作业6\bbs.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='bbs_log', + filename='D:\SQL作业\SQL作业6\bbs_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use bbs +create table bbsUsers +( + UID int identity(1,1), + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +go + +alter table bbsUsers add constraint PK_bbsUsers_UID primary key (UID) +alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) + + +use bbs +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) +go + +alter table bbsSection add constraint PK_bbsSection_sID primary key (sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + +use bbs +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int constraint FK_bbsUsers_UID references bbsUsers(UID), + tSID int constraint FK_bbsSection_sID references bbsSection(sID), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +go + +use bbs +create table bbsReply +( + rID int primary key identity(1,1), + rUID int constraint FK_bbsReply_rUID references bbsUsers(UID), + rTID int constraint FK_bbsTopic_tID references bbsTopic(tID), + rMsg text not null, + rTime datetime +) +go + + +--1.现在有3个会员注册成功,请用一次插入多行数据的方法向bbsUsers表种插入3行记录,记录值如下: +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +--2.将bbsUsers表中的用户名和积分两列备份到新表bbsPoint表中,提示查询部分列:select 列名1,列名2 from 表名 +select uName,uPoint into bbsPoint from bbsUsers +--3.给论坛开设4个板块 +-- 名称 版主名 +-- 技术交流 小雨点 +-- 读书世界 七年级生 +-- 生活百科 小雨点 +-- 八卦区 七年级生 +insert into bbsSection values ('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) + +select * from bbsUsers +--4.向主贴和回帖表中添加几条记录 + +-- 主贴: + +-- 发帖人 板块名 帖子标题 帖子内容 发帖时间 回复数量 +-- 逍遥 八卦区 范跑跑 谁是范跑跑 2008-7-8 1 +-- 七年级生 技术交流 .NET 与JAVA的区别是什么呀? 2008-9-1 2 +-- 小雨点 生活百科 今年夏天最流行什么 有谁知道今年夏天最流行 2008-9-10 0 +-- 什么呀? + +-- 回帖: +-- 分别给上面三个主贴添加对应的回帖,回帖的内容,时间,回帖人自定 +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) values +(2,2,'范跑跑','谁是范跑跑','2008-7-8',1),(3,3,'.NET','与JAVA的区别是什么呀?','2008-9-1',2), +(1,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10',0) +--5.因为会员“逍遥”发表了非法帖子,现将其从论坛中除掉,即删除该用户,请用语句实现(注意主外键,要删除主键,先要将引用了该主键的外键数据行删除) +alter table bbsTopic drop constraint FK_bbsUsers_UID +delete from bbsUsers where uName='逍遥' +--6.因为小雨点发帖较多,将其积分增加10分 +update bbsUsers set uPoint=10 where uName='小雨点' +--7.因为板块“生活百科”灌水的人太少,现决定取消该板块,即删除(注意主外键) +alter table bbsTopic drop constraint FK_bbsSection_sID +delete from bbsSection where sName='生活百科' +--8.因回帖积累太多,现需要将所有的回帖删除 +delete from bbsReply + + +select * from bbsTopic +select * from bbsSection +select * from bbsUsers +select * from bbsReply + + + + + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select UID 版主编号,uName 版主姓名,sName 板块名称 from bbsUsers inner join bbsSection +on bbsUsers.UID = bbsSection.sUid + + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select UID 编号,uName 姓名,tTitle 标题,tMsg 内容,tTime 时间 from bbsUsers inner join bbsTopic +on bbsUsers.UID = bbsTopic.tUID where tTime>'2008-9-15' + + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select UID 版主编号,uName 板主名称,sName 板块名称 from bbsUsers inner join bbsSection +on bbsUsers.UID = bbsSection.sUid where uAge<20 + + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 UID 发帖人编号,uName 姓名,tTitle 标题,tMsg 内容,tCount 回复数量 from bbsUsers inner join bbsTopic +on bbsUsers.UID = bbsTopic.tUID order by tCount desc + + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select UID 发帖人编号,uName 用户名称,sName 板块名称,count(tID) 发帖总数 from bbsTopic inner join bbsUsers +on bbsTopic.tUID = bbsUsers.UID inner join bbsSection +on bbsTopic.tUID = bbsSection.sUid group by UID,uName,sName + + + +select * from bbsTopic +select * from bbsSection +select * from bbsUsers +select * from bbsReply \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\272\214.sql" "b/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\272\214.sql" new file mode 100644 index 0000000..24ef465 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/\344\275\234\344\270\232\344\272\214.sql" @@ -0,0 +1,107 @@ +use master +go + +create database order1 +on +( + name='order1', + filename='D:\SQL作业\SQL作业8\order1.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='order1_log', + filename='D:\SQL作业\SQL作业8\order1_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use order1 +go +create table orders +( + orderId int primary key identity(1,1), + orderDate date +) +go + +insert into orders 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--订单表 + + +use order1 +go +create table orderItem +( + ItemiD int, + orderId int constraint FK_orderItem_orderId foreign key references orders(orderId), + itemType nchar(15), + itemName char(20), + theNumber int, + theMoney money +) +go + +insert into orderItem values +(1,1,'文具','笔',72,2),(2,1,'文具','尺',10,1),(3,1,'体育用品','篮球',1,56),(4,2,'文具','笔',36,2), +(5,2,'文具','固体胶',20,3),(6,2,'日常用品','透明胶',2,1),(7,2,'体育用品','羽毛球',20,3),(8,3,'文具','订书机',20,3), +(9,3,'文具','订书针',10,3),(10,3,'文具','裁纸刀',5,5),(11,4,'文具','笔',20,2),(12,4,'文具','信纸',50,1), +(13,4,'日常用品','毛巾',4,5),(14,1,'日常用品','透明胶',30,1),(15,4,'体育用品','羽毛球',20,3) + + + +select * from orderItem +select * from orders + + + +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orderItem.orderId 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 数量,theMoney 单价 + from orderItem inner join orders on orderItem.orderId = orders.orderId + + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称 from orderItem inner +join orders on orderItem.orderId = orders.orderId where theNumber>50 + + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量, +theMoney 订购单价,theMoney*theNumber 订购总价 from orderItem inner join orders on +orderItem.orderId = orders.orderId group by orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量, +theMoney 订购单价,theNumber*theMoney 订购总价 from orderItem inner join orders +on orderItem.orderId = orders.orderId where theMoney>=5 and theNumber>=50 + + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 + +select orderId 编号,count(*)订购产品数 from orderItem group by orderId + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderId 订单编号,itemType 产品类别,count(*)订购次数,sum(theNumber)总数量 +from orderItem group by orderId,itemType order by orderId \ No newline at end of file -- Gitee From 0036d394dd797f5ecfb6149e5035551fb0579a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=84=E4=B8=BA?= <2608359793@qq.com> Date: Fri, 26 Mar 2021 20:00:16 +0800 Subject: [PATCH 025/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 133 ++++++++++++++++++ .../SQLQuery2.sql" | 101 +++++++++++++ .../SQLQuery3.sql" | 123 ++++++++++++++++ 3 files changed, 357 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery1.sql" new file mode 100644 index 0000000..707af6d --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery1.sql" @@ -0,0 +1,133 @@ +create database Student2 + +on +( + name='Student2', + filename='D:\Student2.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='Student2_log', + filename='D:\Student2_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +use student2 +go + +create table StuInfo +( + sTUNO varchar(15), + stuName nvarchar(20), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') +) + +insert into Stuinfo values ('2501','张秋利','20','美国硅谷','1','女') +insert into Stuinfo values ('2502','李斯文','18','湖北武汉','2','女') +insert into Stuinfo values ('2503','马文才','22','湖南长沙','3','男') +insert into Stuinfo values ('2504','欧阳俊雄','21','湖北武汉','4','男') +insert into Stuinfo values ('2505','梅超风','20','湖北武汉','5','女') +insert into Stuinfo values ('2506','陈旋风','19','美国硅谷','6','男') +insert into Stuinfo values ('2507','陈风','20','美国硅谷','7','男') + +create table Stuexam2 +( + examNO int, + stuNO varchar(15), + writtenExam varchar(200), + labExam varchar(200) +) + +insert into Stuexam2 values ('1','2501','50','70') +insert into Stuexam2 values ('2','2502','60','65') +insert into Stuexam2 values ('3','2503','86','85') +insert into Stuexam2 values ('4','2504','40','80') +insert into Stuexam2 values ('5','2505','70','90') +insert into Stuexam2 values ('6','2506','85','90') + +select sTUNO as 学号 , stuName as 姓名 , stuAge as 年龄 , stuAddress as 地址 , stuSeat as 座号, stuSex as 性别 from Stuinfo +select sTUNO 学号,stuName as 姓名 , stuAge as 年龄 , stuAddress as 地址 , stuSeat as 座号, stuSex as 性别 from Stuinfo +select 学号=sTUNO , 姓名=stuName , 年龄=stuAge , 地址=stuAddress , 座号= stuSeat, 性别= stuSex from Stuinfo + +select stuName , stuAge , stuAddress from Stuinfo + +select examNO as 考号 , stuNO as 学号 , writtenExam as 笔试成绩 , labExam as 机试成绩 from Stuexam2 +select examNO 考号,stuNO as 学号 , writtenExam as 笔试成绩 , labExam as 机试成绩 from Stuexam2 +select 考号=examNO , 学号=stuNO , 笔试成绩=writtenExam , 机试成绩= labExam from Stuexam2 + +select stuName+stuAddress+'@'+stuAddress as 邮箱 from Stuinfo + +select stuNO as 学号,writtenExam as 笔试 ,labExam as 机试, writtenExam+labExam as 总分 from Stuexam2 + +select stuName ,stuAddress from Stuinfo + +select stuAge as 所有年龄 from Stuinfo + +select top 3 * from Stuinfo + +select top 4 * from Stuinfo + +select top 50 percent * from Stuinfo + +select * from Stuinfo where stuAddress = '湖北武汉' and stuAge = 20 + +select * from Stuexam2 where labExam >=60 and labExam <= 80 order by labExam DESC + +select * from Stuinfo where stuAddress = '湖北武汉' or stuAddress='湖南长沙' + +select * from Stuexam2 where writtenExam >=70 and labExam <= 90 order by labExam ASC + +select * from Stuinfo where stuAge is null + +select * from Stuinfo where stuAge is not null + +select * from Stuinfo where stuName like '张%' + +select * from Stuinfo where stuName like '%胡%' + +select * from Stuinfo where stuName like '__俊%' + +select * from Stuinfo order by stuAge DESC + +select * from Stuinfo order by stuAge DESC , stuSeat ASC + +select top 1 * from Stuexam2 order by writtenExam desc + +select top 1 * from Stuexam2 order by writtenExam asc + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 + +select stuName 姓名,stuAge 年龄,writtenExam 笔试, labExam 机试 from StuInfo inner join Stuexam2 on StuInfo.sTUNO = Stuexam2.stuNO + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 + +select StuInfo.sTUNO 学号,stuName 姓名 , writtenExam 笔试, labExam 机试 from StuInfo inner join Stuexam2 on StuInfo.sTUNO = Stuexam2.stuNO where labExam>60 and writtenExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 + +select StuInfo.sTUNO 学号,stuName 姓名,writtenExam 笔试,labExam 机试 from StuInfo left join Stuexam2 on StuInfo.sTUNO =Stuexam2.stuNO + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 + +select stuName 姓名, stuAge 年龄, writtenExam 笔试 , labExam 机试 from StuInfo inner join Stuexam2 on StuInfo.sTUNO = Stuexam2.stuNO where stuAge>=20 + +--5.查询男女生的机试平均分 + +select stuSex 性别 , AVG(labExam) 平均分 from Stuexam2 inner join StuInfo on Stuexam2.stuNO=StuInfo.sTUNO group by stuSex + +--6.查询男女生的笔试总分 + +select stuSex 性别 , sum(writtenExam) 总分 from Stuexam2 inner join StuInfo on Stuexam2.stuNO=StuInfo.sTUNO group by stuSex + +alter table Stuexam2 alter column labExam int + +alter table Stuexam2 alter column writtenExam int \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery2.sql" new file mode 100644 index 0000000..a9918ea --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery2.sql" @@ -0,0 +1,101 @@ +use master +go + +create database order1 +on +( +name='order1', +filename='D:\sql.mdf', +size=5MB, +filegrowth=10MB, +maxsize=50MB +) +log on +( +name='order1_log', +filename='D:\sql.ldf', +size=5MB, +filegrowth=10MB, +maxsize=50MB +) +go + +use order1 +go + +create table orders +( +orderID int primary key identity(1,1) not null, +orderDate datetime not null +) + +create table orderItem +( +itemID int primary key identity(1,1) not null, +orderid int not null, +itemType varchar(20) not null, +itemName varchar(20) not null, +theNumber int not null, +theMoney money not null +) + +insert into orders values ('2008-01-12 00:00.000'), +('2008-02-10 00:00.000'),('2008-02-15 00:00.000'), +('2008-03-10 00:00.000') + +insert into orderItem values(1,'文具','笔','72','2'), +(1,'文具','尺','10','1'),(1,'体育用品','篮球','1','56'), +(2,'文具','笔','36','2'),(2,'文具','固体胶','20','3'), +(2,'日常用品','透明胶','2','1'),(2,'体育用品','羽毛球','20','3'), +(3,'文具','订书机','20','3'),(3,'文具','订书针','10','3'), +(3,'文具','裁纸刀','5','5'),(4,'文具','笔','20','2'), +(4,'文具','信纸','50','1'),(4,'日常用品','毛巾','4','5'), +(4,'日常用品','透明胶','30','1'),(4,'体育用品','羽毛球','20','3') + +select sum(theNumber) from orderItem + +select orderid 订单编号,theNumber 所有物品数量,AVG(theMoney) 平均单价 from orderItem group by orderid,theNumber having orderid<3 and AVG(theMoney)<10 order by orderid asc + +select theNumber 所有物品数量,AVG(theMoney) 平均单价 from orderItem group by theNumber having theNumber>50 and AVG(theMoney)<10 + +select itemType 商品类别 , theNumber 订购次数 from orderItem group by itemType,theNumber + +select itemType 物品类别 , sum(theNumber) 总数量 ,AVG(theMoney) 平均单价 from orderItem group by itemType having sum(theNumber)>100 + +select itemName 产品名称 , count(theNumber) 订购次数, sum(theNumber) 总数量 , AVG(theMoney) 平均单价 from orderItem group by itemName + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orderItem.orderid 编号,orderDate 日期,itemType 类别 , itemName 名称, theNumber 数量,theMoney 单价 from orderItem inner join orders on orderItem.orderid=orders.orderID + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 + +select orderItem.orderid 编号, orderDate 日期,itemType 类别,itemName 名称 from orderItem inner join orders on orderItem.orderid=orders.orderID where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orderItem.orderid 编号, orderDate 日期, itemType 类别, itemName 名称, theNumber 数量,theNumber* theMoney 总价 from orderItem inner join orders on orderItem.orderid=orders.orderID group by orderItem.orderid,orderDate,itemType,itemName,theNumber,theMoney + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orderItem.orderid 编号,orderDate 日期,itemType 类别 , itemName 名称, theNumber 数量,theMoney 单价,theNumber*theMoney 总价 from orderItem inner join orders on orderItem.orderid=orders.orderID where theMoney>=5 and theNumber>=50 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 + +select orderid 编号,theNumber 产品数 from orderItem group by orderid,theNumber + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderid 编号,itemType 类别, count(theNumber) 次数 ,theNumber 总数量 from orderItem group by orderid,itemType, theNumber \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery3.sql" new file mode 100644 index 0000000..abd6e28 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery3.sql" @@ -0,0 +1,123 @@ +create database bbs +on +( +name='bbs', +filename='D:\sql4.mdf', +size=5mb, +maxsize=50mb, +filegrowth=10mb +) +log on +( +name='bbs_log', +filename='D:\sql4.ldf', +size=5mb, +maxsize=50mb, +filegrowth=10mb +) +go + +use bbs +go + +create table bbsUsers +( +UID int identity(1,1), +uName varchar(10) not null, +uSex varchar(2) not null, +uAge int not null, +uPoint int not null +) + +alter table bbsUsers add constraint PK_UID primary key(UID) +alter table bbsUsers add constraint uName unique(uName) +alter table bbsUsers add constraint uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint uPoint check(uPoint>=0) + +create table bbsTopic +( +tID int primary key identity(1,1), +tUID int foreign key references bbsUsers(UID), +tSID int foreign key references bbsSection(sID), +tTitle varchar(100) not null, +tMsg text not null, +tTime datetime , +tCount int +) + +create table bbsReply +( +rID int primary key identity(1,1), +rUID int foreign key references bbsUsers(UID), +rTID int foreign key references bbsTopic(tID), +rMsg text not null, +rTime datetime +) + +create table bbsSection +( +sID int identity(1,1), +sName varchar(10) not null, +sUid int +) + +alter table bbsSection add constraint Pk_sID primary key (sID) +alter table bbsSection add constraint CK_sUid foreign key (sUid) references bbsUsers(UID) + +insert into bbsUsers values('小雨点','女','20','0') +insert into bbsUsers values('逍遥','男','18','4') +insert into bbsUsers values('七年级生','男','19','2') + +select uName,uSex from bbsUsers + +select uName,uPoint into bbsPoint from bbsUsers + +select * from bbsSection + +insert into bbsSection (sName,sUid) +values('技术交流',1), + ('读书世界',3), + ('生活百科',1), + ('八卦区',3) + +insert into bbsTopic( tUID,tSID,tTitle,tMsg,tTime,tCount ) +values (2,4,'范跑跑','谁是范跑跑','2008-7-8','1'),(3,1,'.NET','与JAVA的区别是什么','2008-9-1','2'), +(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10','0') + +insert into bbsReply(rMsg,rTime,rUID) values +('他是范跑跑','2008-7-9',1), +('不知道','2008-9-2',2), +('不知道','2008-9-11',3) + +alter table bbsReply drop constraint FK__bbsReply__rUID__30F848ED +alter table bbsTopic drop constraint FK__bbsTopic__tUID__2D27B809 +delete bbsUsers where uName='逍遥' + +update bbsUsers set upoint =12 where uName='小雨点' + +alter table bbsTopic drop constraint FK__bbsTopic__tSID__2E1BDC42 +delete bbsSection where sName = '生活百科' + +delete bbsReply + + +--1.查询出每个版块的版主编号,版主姓名和版块名称 + +select UID 版主编号,uName 姓名,sName 名称 from bbsSection inner join bbsUsers on bbsSection.sUid=bbsUsers.UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 + +select tUID 版主编号,uName 姓名,tTitle 标题,tMsg 内容,tTime 时间 from bbsTopic inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 + +select tID 编号,sName 名称,uName 姓名 from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 + +select top 1 tID 发帖人编号,uName 姓名,tTitle 标题,tMsg 内容,tCount 数量 from bbsTopic inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID order by tCount DESC + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select tSID 版块,tUID 用户,count(tSID) 发帖总数 from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID group by tSID,tUID \ No newline at end of file -- Gitee From 33e7ba79295397083bd23a8ba36913d2e84b64b2 Mon Sep 17 00:00:00 2001 From: unknown <1926162199@qq.com> Date: Fri, 26 Mar 2021 20:09:59 +0800 Subject: [PATCH 026/195] 3.26 --- .../SQLQuery1.sql" | 26 +++++++++++++++ .../SQLQuery2.sql" | 32 +++++++++++++++++++ .../SQLQuery5.sql" | 18 +++++++++++ 3 files changed, 76 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery5.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" new file mode 100644 index 0000000..aadb084 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" @@ -0,0 +1,26 @@ + + select*from bbsPoint + select*from bbsReply + select*from bbsSection + select*from bbsTopic + select*from bbsUsers +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select suid 版主编号, uName 版主姓名,sName 版块名称 from bbsSection join bbsUsers on bbsSection.sUid=bbsUsers.uID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select rID 发帖人编号, rUID 发帖人姓名, tTitle 帖子的标题 ,tMsg 帖子的内容, rTime 发帖时间 from bbsReply join bbsTopic on bbsReply.rUID=bbsTopic.tUID where rTime>2008-9-15 +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select suid 版主编号, uName 版主姓名,sName 版块名称, uAge 年龄 from bbsSection join bbsUsers on bbsSection.sUid=bbsUsers.uID where uAge<20 +select suid 版主编号, uName 版主姓名,sName 版块名称, uAge 年龄 from bbsSection join bbsUsers on bbsSection.sUid=bbsUsers.uID where uAge<=20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select tCount from bbsTopic +select rID 发帖人编号, rUID 发帖人姓名, tTitle 主贴标题, tMsg 主贴内容 ,tCOunt 回复数量 from bbsReply join bbsTopic on bbsReply.rUID=bbsTopic.tUID where tCOunt=2 +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName 板块,tUid 用户,count(tID) 发帖总数 from bbsTopic join bbsSection on bbsSection.sUid =bbsTopic.tUID +group by sName,tUid + + + + + diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery2.sql" new file mode 100644 index 0000000..d6096bd --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery2.sql" @@ -0,0 +1,32 @@ +select *from orders +select*from orderItem +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orderItem.orderid 订单编号,itemType 产品类别, itemName 产品名称 ,orderdate 订单日期,theNumber 数量, theMoney 单价 from orderItem inner join orders on orderItem.orderid=orders.orderid + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderid 订单编号,itemType 产品类别, itemName 产品名称 ,orderdate 订单日期 from orderItem inner join orders on orderItem.orderid=orders.orderid where orderItem.theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderid 订单编号,itemType 产品类别, itemName 产品名称 ,orderdate 订单日期,theNumber 数量, theMoney 单价 , theMoney*theNumber 总价 +from orderItem left join orders on orderItem.orderid =orders.orderid group by orderItem.orderid,itemType,itemName,orderdate,theNumber,theMoney +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderid 订单编号,orderdate 订单日期,itemType 产品类别, itemName 产品名称,theNumber 数量, theMoney 单价 , theMoney*theNumber 总价 +from orderItem left join orders on orderItem.orderid =orders.orderid where theNumber>=50 and theMoney>=5 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- +select orderid 编号,count(theNumber) 订购产品数 from orderItem group by orderid 2 4 + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderItem. orderid 编号,itemType 产品类别,count(*)订购次数 ,sum(theNumber)总数量 from orderItem left join orders on orderItem.orderid=orders.orderid group by itemType,orderItem.orderid \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery5.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery5.sql" new file mode 100644 index 0000000..2ed2cce --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery5.sql" @@ -0,0 +1,18 @@ + + +--数据如图片1,使用上次作业的数据 +select *from StuMark +select *from stuinfo +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 + +select stuinfo.stuno , StuName 姓名,StuAge 年龄,writtenExam 笔试, labexam 机试 from stuinfo left join StuMark on stuinfo.stuno=StuMark.stuno +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuinfo.stuno ,StuSeat 学号 ,StuName 姓名, writtenExam 笔试, labexam 机试 from stuinfo inner join StuMark on stuinfo.stuno=StuMark.stuno where writtenExam>60 and labexam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuSeat 学号 ,StuName 姓名, writtenExam 笔试, labexam 机试 from stuinfo inner join StuMark on stuinfo.stuno =StuMark.stuno +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName 姓名, writtenExam 笔试, labexam 机试,StuAge 年龄 from stuinfo inner join StuMark on stuinfo.stuno =StuMark.stuno where StuAge>20 order by writtenExam desc +--5.查询男女生的机试平均分 +select stusex 性别, avg(labexam)平均 from stuinfo inner join StuMark on stuinfo.stuno = StuMark.stuno group by stusex +--6.查询男女生的笔试总分 +select stusex 性别, sum(writtenExam)总分 from stuinfo inner join StuMark on stuinfo.stuno = StuMark.stuno group by stusex \ No newline at end of file -- Gitee From cdf9befa304b1bc65ed838b36e4e797cd18d7edc Mon Sep 17 00:00:00 2001 From: wang-jiawen-rjjs <2903977615@qq.com> Date: Fri, 26 Mar 2021 20:21:16 +0800 Subject: [PATCH 027/195] =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\234\253\344\275\234\344\270\232wjw 1.sql" | 63 ++++++++++++++ ...\234\253\344\275\234\344\270\232wjw 2.sql" | 72 +++++++++++++++ ...\234\253\344\275\234\344\270\232wjw 3.sql" | 87 +++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 3.sql" diff --git "a/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 1.sql" "b/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 1.sql" new file mode 100644 index 0000000..bf8ee0b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 1.sql" @@ -0,0 +1,63 @@ +use master +go +create database Student +on( + name='Student', + filename='C:\text\student.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +log on( + name='Student_log', + filename='C:\text\student_log.ldf', + size=5, + maxsize=100, + filegrowth=10% +) +go +use Student +go +create table stuInfo +( + stuNO varchar(10) primary key, + stuName nvarchar(10), + stuAge int , + stuAddress nvarchar(50), + stuSeat int, + stuSex int , +) +create table Score +( + examNO int primary key identity(1,1), + stuNO varchar(10) references stuInfo(stuNO), + writtenExam int, + labExam int, +) +select * from stuInfo +select * from Score +insert into stuInfo values('s2501','张秋利',20,'美国硅谷',1,1),('s2502','李斯文',18,'湖北武汉',2,0),('s2503','马文才',22,'湖南长沙',3,1), +('s2504','欧阳俊雄',21,'湖北武汉',4,0),('s2505','梅超风',20,'湖北武汉',5,1),('s2506','陈旋风',19,'美国硅谷',6,1), +('s2507','陈风',20,'美国硅谷',7,0) +insert into Score values('s2501',50,70),('s2502',60,65),('s2503',86,85),('s2504',40,80), +('s2505',70,90),('s2506',85,90) +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuInfo.stuNO 学号,stuName 姓名,stuAge 年龄,Score.writtenExam 笔试成绩,Score.labExam 机试成绩 from stuInfo +inner join Score on stuInfo.stuNO=Score.stuNO +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuInfo.stuNO 学号 ,stuInfo.stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from Score +inner join stuInfo on stuInfo.stuNO=Score.stuNO where writtenExam>60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuInfo.stuNO 学号,stuName 姓名,stuAge 年龄,Score.writtenExam 笔试成绩,Score.labExam 机试成绩 from stuInfo +left join Score on stuInfo.stuNO=Score.stuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuInfo.stuNO 学号 ,stuInfo.stuName 姓名,stuInfo.stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from Score +inner join stuInfo on stuInfo.stuNO=Score.stuNO where stuAge>=20 order by writtenExam DESC + +--5.查询男女生的机试平均分 +select stuInfo.stuSex 性别,AVG(labExam) 平均分 from Score +inner join stuInfo on stuInfo.stuNO=Score.stuNO group by stuInfo.stuSex + +--6.查询男女生的笔试总分 +select stuInfo.stuSex 性别,sum(writtenExam) 总分 from Score +inner join stuInfo on stuInfo.stuNO=Score.stuNO group by stuInfo.stuSex diff --git "a/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 2.sql" "b/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 2.sql" new file mode 100644 index 0000000..1fa6259 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 2.sql" @@ -0,0 +1,72 @@ +use master +go +create database Demo_01 +on( + name='Demo_01', + filename='C:\text\Demo_01.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +log on( + name='Demo_01_log', + filename='C:\text\Demo_01_log.ldf', + size=5, + maxsize=100, + filegrowth=10% +) +go +use Demo_01 +go +create table orders +( + orderId int primary key identity not null, + orderDate datetime not null, +) +create table orderItem +( + ItemiD int primary key identity not null, + orderId int references orders(orderId) not null, + itemType nvarchar(10) not null, + itemName nvarchar(10) not null, + theNumber int not null, + theMoney int not null, +) +select * from orders +select * from orderItem +insert into orders values('2008-01-12'),('2008-02-10'),('2008-02-15'),('2008-03-10') +insert into orderItem values(1,'文具','笔',72,2),(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56),(2,'文具','笔',36,2),(2,'文具','固体胶',20,3),(2,'日常用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3),(3,'文具','订书机',20,3),(3,'文具','订书针',10,3),(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2),(4,'文具','信纸',50,1),(4,'日常用品','毛巾',4,5),(4,'日常用品','透明胶',30,1),(4,'体育用品','羽毛球',20,3) + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderId 订单编号,orders.orderDate 订单日期, orderItem.itemType 订购产品的类别,orderItem.itemName 订购的产品名称,orderItem.theNumber 订购数量,orderItem.theMoney 订购单价 from orders +inner join orderItem on orders.orderId=orderItem.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderId 订单编号,orders.orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量 from orderItem +inner join orders on orders.orderId= orderItem.orderId where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId 订单编号,orders.orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,sum(theNumber*theMoney)订购总价 from orderItem +inner join orders on orders.orderId= orderItem.orderId group by orders.orderId,orders.orderDate,itemType,itemName ,theNumber,theMoney +--4.查询单价大于等于5 并且 数量大于等于50的订单的 订单的编号,订单日期,订购产品的类别 和 订购的产品名称,订购数量 和 订购单价以及 订购总价 +select orders.orderId 订单编号,orders.orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,sum(theNumber*theMoney)订购总价 from orderItem +inner join orders on orders.orderId= orderItem.orderId where theMoney>=5 and theNumber>=50 group by orders.orderId,orders.orderDate,itemType,itemName ,theNumber,theMoney +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orders.orderId 订单编号,count(*)订购产品数 from orders + inner join orderItem on orders.orderId=orderItem.orderId group by orders.orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select orders.orderId 订单编号,itemType 产品类别,count(*)订购次数,sum(theNumber) from orderItem +inner join orders on orders.orderId=orderItem.orderId group by itemType,orders.orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 3.sql" "b/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 3.sql" new file mode 100644 index 0000000..669898a --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\345\221\250\346\234\253\344\275\234\344\270\232wjw 3.sql" @@ -0,0 +1,87 @@ +use master +go +create database bbs +on( + name='bbs', + filename='C:\text\bbs.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +log on( + name='bbs_log', + filename='C:\text\bbs_log.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +go +use bbs +go +create table bbsUsers +( + uID int identity(1,1) not null , + uName nvarchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null, + +) +alter table bbsUsers add constraint PK_bbsUsers_uID primary key(uID) +alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 or uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) +create table bbsSection +( + sID int identity(1,1) not null , + sName varchar(10) not null, + sUid int , + +) +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid)references bbsUsers(uID) +create table bbsTopic +( + tID int primary key identity(1,1) not null, + tUID int references bbsUsers(uID) not null , + tSID int references bbsSection(sID) , + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime not null, + tCount int not null, +) +create table bbsReply +( + rID int primary key identity(1,1) not null, + rUID int references bbsUsers(uID) , + rTID int references bbsTopic(tID) , + rMsg text not null, + rTime datetime , +) +select * from bbsReply +select * from bbsSection +select * from bbsTopic +select * from bbsUsers +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint_backup from bbsUsers +insert into bbsSection values('技术名流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑!','谁是范跑跑!', '2008-7-8',1),(3,2,'.NET!','与JAVA的区别是什么呀?','2008-9-1',2),(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10',0) +insert into bbsReply values(3,1,'一名地震自己先跑的教师','2008-7-8'),(1,2,'不知道','2008-9-15'),(2,2,'Java更难','2008-9-20') +update bbsUsers set uPoint=30 where uName='小雨点' +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select bbsUsers.uID 版主编号,bbsUsers.uName 版主姓名,sName 板块名称 from bbsSection +right join bbsUsers on bbsUsers.uID=bbsSection.sUid +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tID 发帖人编号,bbsUsers.uName 发帖人姓名,tTitle 帖子标题,tMsg 帖子内容,tTime 发帖时间 from bbsTopic +inner join bbsUsers on bbsTopic.tUID=bbsUsers.uID where tTime>'2008-09-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select uID 版主编号,uName 版主名称,bbsSection.sName 板块名称 from bbsUsers +left join bbsSection on uID=sUid where uAge<20 +--4.查询出 回复数量最多的主贴 的 发帖人编号, 发帖人姓名, 主贴标题, 主贴内容和 回复数量 +select top 1 tUID 发帖人编号,bbsUsers.uName 发帖人姓名,tTitle 主帖标题,tMsg 主贴内容, tCount 回复数量 from bbsTopic +inner join bbsUsers on uID=tUID order by tCount DESC +--5.在主贴表中查询 每个版块 中 每个用户的 发帖总数 +select bbsSection.sName 板块名称,uID 发帖人编号,SUM(tID)发帖总数 from bbsTopic +right join bbsSection on sID=tSID +left join bbsUsers on uID=tUID group by bbsSection.sName,uID \ No newline at end of file -- Gitee From c2d632dd6af47ed4da804490d775a95aeb1f272a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Fri, 26 Mar 2021 20:30:34 +0800 Subject: [PATCH 028/195] 1 --- .../SQLQuery9.2.sql" | 82 +++++++++++ .../SQLQuery9.3.sql" | 135 ++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.3.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.2.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.2.sql" new file mode 100644 index 0000000..47c83e1 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.2.sql" @@ -0,0 +1,82 @@ +create database paid +on +( + name='paid', + filename='D:\pan\paid.mdf', + size=10mb, + maxsize=100mb, + filegrowth=15% +) +log on +( + name='paid_log', + filename='D:\pan\paid_log.ldf', + size=10mb, + maxsize=100mb, + filegrowth=15% +) +go + +use paid +go +--drop table orderItem +create table orders +( + orderId int primary key, + orderDate date +) + +create table orderItem +( + ItemiD int identity(1,1) primary key, + orderId int references orders(orderId), + itemType varchar(12), + itemName varchar(12), + theNumber int, + theMoney money +) +insert into orders values + (1,'2008-01-12'), + (2,'2008-02-10'), + (3,'2008-02-15'), + (4,'2008-03-10') +insert into orderItem values + (1,'文具','笔',72,2), + (1,'文具','尺',10,1), + (1,'体育用品','篮球',1,56), + (2,'文具','笔',36,2), + (2,'文具','固体胶',20,3), + (2,'日常用品','透明胶',2,1), + (2,'体育用品','羽毛球',20,3), + (3,'文具','订书机',20,3), + (3,'文具','订书针',10,3), + (3,'文具','裁纸刀',5,5), + (4,'文具','笔',20,2), + (4,'文具','信纸',50,1), + (4,'日常用品','毛巾',4,5), + (4,'日常用品','透明胶',30,1), + (4,'体育用品','羽毛球',20,3) + select * from orders + select * from orderItem + --1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + select orderitem.orderId 订单的编号,orderdate 订单日期,itemtype 订购产品的类别,itemname 订购的产品名称,thenumber 订购数量,themoney 订购单价 from orderItem inner join orders on orderItem.orderId = orders.orderId + --2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 + select orderitem.orderId 订单的编号,orderdate 订单日期,itemtype 订购产品的类别,itemname 订购的产品名称 from orderItem inner join orders on orderItem.orderId = orders.orderId where theMoney>50 + --3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + select orderitem.orderId 订单的编号,orderdate 订单日期,itemtype 订购产品的类别,itemname 订购的产品名称,thenumber 订购数量,themoney 订购单价 ,theNumber*theMoney 订购总价 from orderItem inner join orders on orderItem.orderId = orders.orderId + --4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + select orderitem.orderId 订单的编号,orderdate 订单日期,itemtype 订购产品的类别,itemname 订购的产品名称,thenumber 订购数量,themoney 订购单价 ,theNumber*theMoney 订购总价 from orderItem inner join orders on orderItem.orderId = orders.orderId where theMoney>=5 and theMoney>=50 + --5.查询每个订单分别订购了几个产品,例如: + -- 编号 订购产品数 + -- 1 3 + --2 4 + select orderitem.orderId 订单的编号,count(thenumber)订购产品数 from orderItem inner join orders on orderItem.orderId = orders.orderId group by orderitem.orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + -- 1 文具 2 82 + -- 1 体育用品 1 1 + --2 文具 2 56 + --2 体育用品 1 2 + --2 日常用品 1 20 + select orderitem.orderId 订单的编号,itemtype 订购产品的类别,count(itemtype)订购次数 ,sum(thenumber)总数量 from orderItem inner join orders on orderItem.orderId = orders.orderId group by orderitem.orderId,itemtype order by orderitem.orderId asc \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.3.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.3.sql" new file mode 100644 index 0000000..e5e26b4 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery9.3.sql" @@ -0,0 +1,135 @@ +use master +go + +create database bbs +on +( + name='bbs', + filename='D:\SQL\bbs.mdf', + size=5MB, + maxsize=100MB, + filegrowth=10% + +) +, +( + name='bbs2_DATA', + filename='D:\SQL\bbs2_DATA.Ndf', + size=1MB, + maxsize=100MB, + filegrowth=10% +) +log on +( + name='bbs_ldf', + filename='D:\SQL\bbs_log.ldf', + size=5MB, + maxsize=100MB, + filegrowth=10% +) +go + +use bbs +go + +create table bbsUsers +( + UID int primary key identity(1,1), + uName varchar(10) unique not null, + uSex varchar(2) not null check (uSex='男' or uSex='女'), + uAge int not null check(uAge>=15 and uAge<=60), + uPoint int not null check(uPoint>=0) +) +select *from bbsUsers +create table bbsSection +( + sID int identity(1,1) primary key, + sName varchar(10) not null, + sUid int foreign key references bbsUsers(UID) +) + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTitle varchar(100) not null, + rMsg text not null, + rTime datetime , + tCount int +) + + +create table bbsReply +( + rID int primary key identity(1,1), + rUID INT foreign key references bbsUsers(UID), + rTID INT foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) +select * from bbsUsers +select * from bbsSection +select *from bbsTopic +select * from bbsReply + +insert into bbsUsers(uName, uSex,uAge,uPoint) +values ('小雨点','女',20,0) +insert into bbsUsers(uName, uSex,uAge,uPoint) +values ('逍遥','男',18,4) +insert into bbsUsers(uName, uSex,uAge,uPoint) +values ('七年级生','男',19,2) + +insert into bbsSection(sName , sUid) +values('技术交流',1) +insert into bbsSection(sName , sUid) +values('读书世界',3) +insert into bbsSection(sName , sUid) +values('生活百科',1) +insert into bbsSection(sName , sUid) +values('八卦区',3) + +insert into bbsTopic(tUID ,tSID,tTitle,rMsg,rTime,tCount) +values (2,5,'范跑跑','谁是范跑跑','2008-7-8',1) +insert into bbsTopic(tUID ,tSID,tTitle,rMsg,rTime,tCount) +values (3,2,'.NET','与JAVA的区别是什么','2008-9-1',2) +insert into bbsTopic(tUID ,tSID,tTitle,rMsg,rTime,tCount) +values (1,4,'今年夏天流行什么','有谁知道今年夏天流行什么呀?','2008-9-10',0) + +insert into bbsReply(rUID,rTID,rMsg,rTime) +values(1,3,'范跑跑','2008-10-2') +insert into bbsReply(rUID,rTID,rMsg,rTime) +values(2,2,'区别不大','2008-10-2') +insert into bbsReply(rUID,rTID,rMsg,rTime) +values(3,1,'蓝色','2008-10-2') + +select uName,uPoint into bbsPoint from bbsUsers --备份uName uPoint 到新表bbsPoint + +alter table bbsTopic drop constraint FK__bbsTopic__tUID__2D27B809 +alter table bbsReply drop constraint FK__bbsReply__rUID__30F848ED +delete from bbsUsers where uName='逍遥' +update bbsUsers set upoint=10 where uName='小雨点' + +alter table bbsTopic drop FK__bbsTopic__tSID__2E1BDC42 +delete bbsSection where sName='生活百科' + +truncate table bbsReply + + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的 UID版主编号,uName版主姓名和 sName版块名称 +select UID 版主编号,uName 版主姓名,sName 版块名称 from bbsUsers +inner join bbsSection on bbsUsers.UID = bbsSection.sUId +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,ttitle 帖子的标题,rMsg 帖子的内容,rTime 发帖时间 from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID where rTime>'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select UID 版主编号,uName 版主姓名,sName 版块名称 from bbsUsers +inner join bbsSection on bbsUsers.UID = bbsSection.sUId where uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select tUID 发帖人编号,uName 发帖人姓名,ttitle 主贴标题,rMsg 主贴内容,tcount 回复数量 from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID where tCount = (select max(tCount) from bbsTopic) +--5.在主贴表中查询 每个版块中 每个用户的发帖总数 +select bbsSection.sName 板块名称,uID 发帖人编号,SUM(tID)发帖总数 from bbsTopic +right join bbsSection on sID=tSID +left join bbsUsers on uID=tUID group by bbsSection.sName,uID \ No newline at end of file -- Gitee From f385637f01b92f9a9ff4f70406f74d79e890c220 Mon Sep 17 00:00:00 2001 From: EoL <1179233990@qq.com> Date: Fri, 26 Mar 2021 20:38:30 +0800 Subject: [PATCH 029/195] 1 --- .../SQLQuery3.sql" | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git "a/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery3.sql" index b702c81..cb2b28a 100644 --- "a/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery3.sql" +++ "b/20210326\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery3.sql" @@ -18,7 +18,7 @@ create table bbsUsers ( UID int primary key identity(1,1), uName varchar(10) not null, -uSex varchar(2) not null check(uSex='男' or uSex='女'), +uSex varchar(2) not null check(uSex='鐢' or uSex='濂'), uAge int not null check(uAge>=15 and uAge<=40), uPoint int not null check(uPoint>=0) ) @@ -53,22 +53,22 @@ go alter table bbsTopic add constraint FK_bbsUsers1_UID foreign key(tUID) references bbsUsers(UID) alter table bbsTopic add constraint FK_bbsSection_sID foreign key(tSID) references bbsSection(sID) alter table bbsSection add constraint FK_bbsUsers2_UID foreign key(sUid) references bbsUsers(UID) -insert into bbsUsers(uName,uSex,uAge,uPoint) values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +insert into bbsUsers(uName,uSex,uAge,uPoint) values('灏忛洦鐐','濂',20,0),('閫嶉仴','鐢',18,4),('涓冨勾绾х敓','鐢',19,2) select uName,uPoint into bbsPoint from bbsUsers -insert into bbsSection(sName,sUid) values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) -insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) values(2,4,'范跑跑','谁是范跑跑','2008-7-8',1),(3,1,'.NET','与JAVA的区别是什么呀?','2008-9-1',2),(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀','2008-9-10',0) +insert into bbsSection(sName,sUid) values('鎶鏈氦娴',1),('璇讳功涓栫晫',3),('鐢熸椿鐧剧',1),('鍏崷鍖',3) +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) values(2,4,'鑼冭窇璺','璋佹槸鑼冭窇璺','2008-7-8',1),(3,1,'.NET','涓嶫AVA鐨勫尯鍒槸浠涔堝憖锛','2008-9-1',2),(1,3,'浠婂勾澶忓ぉ鏈娴佽浠涔','鏈夎皝鐭ラ亾浠婂勾澶忓ぉ鏈娴佽浠涔堝憖','2008-9-10',0) insert into bbsReply(rMsg,rTime,rUID,rTID) values('666','2008-1-1',1,2),('666','2008-1-1',2,3),('666','2008-1-1',3,1) select * from bbsUsers select * from bbsTopic select * from bbsReply select * from bbsSection ---1.查询出每个版块的版主编号,版主姓名和版块名称 +--1.鏌ヨ鍑烘瘡涓増鍧楃殑鐗堜富缂栧彿锛岀増涓诲鍚嶅拰鐗堝潡鍚嶇О select UID,uName,sName from bbsUsers inner join bbsSection on bbsUsers.UID=bbsSection.sUid ---2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +--2.鏌ヨ鍑轰富璐寸殑鍙戝笘鏃堕棿鍦2008-9-15浠ュ悗鐨勪富璐寸殑鍙戝笘浜虹紪鍙凤紝鍙戝笘浜哄鍚嶏紝甯栧瓙鐨勬爣棰橈紝甯栧瓙鐨勫唴瀹瑰拰鍙戝笘鏃堕棿 select UID,uName,tTitle,tMsg,tTime from bbsUsers inner join bbsTopic on bbsUsers.UID=bbsTopic.tUID where tTime>'2008-9-15' ---3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +--3.鏌ヨ鍑哄勾榫勫湪20浠ヤ笅鐨勭増涓荤殑缂栧彿锛岀増涓荤殑鍚嶇О鍜岀増鍧楃殑鍚嶇О select UID,uName,sName from bbsUsers inner join bbsSection on bbsUsers.UID=bbsSection.sUid where uAge<20 ---4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +--4.鏌ヨ鍑哄洖澶嶆暟閲忔渶澶氱殑涓昏创鐨勫彂甯栦汉缂栧彿锛屽彂甯栦汉濮撳悕锛屼富璐存爣棰橈紝涓昏创鍐呭鍜屽洖澶嶆暟閲 select UID,uName,tTitle,tMsg,tCount from bbsUsers inner join bbsTopic on bbsUsers.UID=bbsTopic.tUID where tCount=(select MAX(tCount) from bbsTopic) ---5.在主贴表中查询每个版块中每个用户的发帖总数 -select sName,uName,count(tID) 发帖总数 from bbsUsers left join bbsSection on bbsUsers.UID=bbsSection.sUid left join bbsTopic on bbsUsers.UID=bbsTopic.tUID group by sName,uName +--5.鍦ㄤ富璐磋〃涓煡璇㈡瘡涓増鍧椾腑姣忎釜鐢ㄦ埛鐨勫彂甯栨绘暟 +select sName,uName,count(tID) 鍙戝笘鎬绘暟 from bbsTopic left join bbsSection on bbsTopic.tUID=bbsSection.sUid left join bbsUsers on bbsSection.sUid=bbsUsers.UID group by sName,uName -- Gitee From 2a8e747e4890caf5cf3f85e4eab5faa58510b1a8 Mon Sep 17 00:00:00 2001 From: zyq520lcx <2642587822@qq.com> Date: Fri, 26 Mar 2021 21:37:39 +0800 Subject: [PATCH 030/195] frist commit --- .../\344\275\234\344\270\2321.sql" | 73 +++++++++ .../\344\275\234\344\270\2322.sql" | 83 ++++++++++ .../\344\275\234\344\270\2323.sql" | 155 ++++++++++++++++++ 3 files changed, 311 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2321.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2322.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2323.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2321.sql" "b/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..c921a1b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2321.sql" @@ -0,0 +1,73 @@ +use master +go +create database studen +go +use studen +go + +drop table stuifno +drop table soceifno +create table stuifno +( + stuno nvarchar(20) primary key not null, + stuname nvarchar(20) not null , + stuage nvarchar(20) not null, + stuaddress nvarchar(200) not null, + stuseat int not null, + stusex char(2) default('男') check(stusex='男' or stusex='女') +) +create table soceifno +( + examno int primary key identity(1,1), + stuno nvarchar(20) references stuifno(stuno) not null, + writtenexam int not null, + labexam int not null +) +truncate table stuifno +truncate table soceifno + +insert into stuifno +select 's2501','张秋利','20','美国硅谷',1,'男' union +select 's2502','李斯文','18','湖北武汉',2,'女' union +select 's2503','马文才','22','湖南长沙',3,'男' union +select 's2504','欧阳俊雄','21','湖北武汉',4,'女' union +select 's2505','梅超风','20','湖北武汉',5,'男' union +select 's2506','陈旋风','19','美国硅谷',6,'男'union +select 's2507','陈风','20','美国硅谷',7,'女' + +insert into soceifno +select 's2501','50','70' union +select 's2502','60','65' union +select 's2503','86','85' union +select 's2504','40','80' union +select 's2505','70','90' union +select 's2506','85','90' + +select * from stuifno +select * from soceifno + +--数据如图片1,使用上次作业的数据 + +--1.查询 学生的姓名, 年龄, 笔试成绩和 机试成绩 +select stuname 姓名 ,stuage 年龄,writtenexam 笔试成绩,labexam 机试成绩 from soceifno,stuifno where soceifno.stuno=stuifno.stuno + + +--2.查询 笔试 和 机试成绩 都在60分以上 的学生的学号 ,姓名, 笔试成绩 和 机试成绩 +select soceifno.stuno 学号,stuname 姓名, writtenexam 笔试成绩,labexam 机试成绩 from soceifno +inner join stuifno on soceifno.stuno=stuifno.stuno where writtenexam>60 and labexam>60 + +--3.查询 所有学生 的学号,姓名,笔试成绩,机试成绩, 没有参加考试的学生的成绩以NULL值填充 +select stuifno.stuno 学号,stuname 姓名, writtenexam 笔试成绩 , labexam 机试成绩 from stuifno +left join soceifno on soceifno.stuno=stuifno.stuno + +--4.查询 年龄在20以上(包括20)的学生的 姓名, 年龄, 笔试成绩 和机试成绩,并按笔试成绩降序排列 +select stuname 姓名,stuage 年龄,writtenexam 笔试成绩 , labexam 机试成绩 from stuifno +inner join soceifno on soceifno.stuno=stuifno.stuno where stuage>=20 order by writtenexam desc + +--5.查询 男女生的 机试平均分 +select stusex 性别,avg(labexam) 机试平均分 from stuifno +inner join soceifno on soceifno.stuno=stuifno.stuno group by stusex + +--6.查询男女生的笔试总分 +select stusex 性别,sum(writtenexam) 笔试总分 from stuifno +inner join soceifno on soceifno.stuno=stuifno.stuno group by stusex diff --git "a/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2322.sql" "b/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..9ebdd0b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2322.sql" @@ -0,0 +1,83 @@ +use master +go +create database ordersad +go +use ordersad +go + +create table orders +( + orderId int primary key identity(1,1), + orderDate datetime not null +) + +create table orderItem +( + ItemiD int primary key identity(1,1), + orderId int references orders(orderId) not null, + itemType nvarchar(20) not null, + itemName nvarchar(20) not null, + theNumber int not null, + theMoney int not null +) +drop table orderItem +insert into orders +select('2008-01-12 00:00:00.000') union +select('2008-02-10 00:00:00.000') union +select('2008-02-15 00:00:00.000') union +select('2008-03-10 00:00:00.000') + +insert into orderItem +select 1,'文具','笔','72','2' union +select 1,'文具','尺','10','1' union +select 1,'体育用品','篮球','1','56' union +select 2,'文具','笔','36','2' union +select 2,'文具','固体胶','20','3' union +select 2,'日常用品','透明胶','2','1' union +select 2,'体育用品','羽毛球','20','3' union +select 3,'文具','订书机','20','3' union +select 3,'文具','订书针','10','3' union +select 3,'文具','裁纸刀','5','5' union +select 4,'文具','笔','20','2' union +select 4,'文具','信纸','50','1' union +select 4,'日常用品','毛巾','4','5' union +select 4,'日常用品','透明胶','30','1' union +select 4,'体育用品','羽毛球','20','3' + + +select * from orderItem +select * from orders +--使用上次作业的订单数据库,完成下列题目: + +--1.查询 所有的订单的 订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orderItem.orderId 订单编号, orderDate 订单日期,itemType 类别,itemName 产品名称,theNumber 订购数量, theMoney 订购单价 from orderItem + inner join orders on orderItem.orderId=orders.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId 订单编号, orderDate 订单日期,itemType 类别,itemName 产品名称 ,theNumber 订购数量 from orderItem +inner join orders on orderItem.orderId=orders.orderId where theNumber>50 +--3.查询所有的订单的 订单的编号, 订单日期,订购产品的 类别和订购的 产品名称, 订购数量 和 订购单价 以及 订购总价 +select orderItem.orderId 订单编号, orderDate 订单日期,itemType 类别,itemName 产品名称 ,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 总价 from orderItem +inner join orders on orderItem.orderId=orders.orderId + + +--4.查询单价大于等于5并且数量大于等于50的 订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号, orderDate 订单日期,itemType 类别,itemName 产品名称 ,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 总价 from orderItem +inner join orders on orderItem.orderId=orders.orderId where theMoney>=5 and theNumber>=50 + +--5.查询 每个订单分别订购了 几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId 编号,count(theNumber) 订购产品数 from orderItem group by orderID + +--6.查询 每个订单里的 每个类别的 产品分别订购了几次 和 总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select orderId 订单编号 ,itemType 产品类别 ,count(itemType)订购次数 ,sum(theNumber) 总数量 from orderItem group by orderId ,itemType order by orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2323.sql" "b/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2323.sql" new file mode 100644 index 0000000..9eb0251 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2323.sql" @@ -0,0 +1,155 @@ +use master +go + +create database bbs +on +( + name='bbs', + filename='F:\bbs.mdf', + size=10mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='F:\bbs_log.ldf', + size=10mb, + maxsize=100mb, + filegrowth=10mb +) +go + +use bbs +go + +create table bbsUsers +( + UID int not null, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +go +use bbs +go +select * from bbsUsers +alter table bbsUsers add constraint PK primary key (UID) +alter table bbsUsers add constraint FK unique (uName) +alter table bbsUsers add constraint CK check(uSex='男' or uSex='女') +alter table bbsUsers add constraint DK check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint UK check(uPoint>=0) + +create table bbsSection +( + sID int not null, + sName varchar(10) not null, + sUid int not null +) +go +use bbs +go + +alter table bbsSection add constraint BK primary key(sID) +alter table bbsSection add constraint NK foreign key (sUid) references bbsUsers( UID) + +go +use bbs +go +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int references bbsUsers(UID), + tSID int references bbsSection(sID), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int primary key identity(1,1), + rUID int references bbsUsers(UID), + rTID int references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers(UID,uName,uSex,uAge,uPoint) +values(1,'小雨点','女','20','0') +insert into bbsUsers(UID,uName,uSex,uAge,uPoint) +values(2,'逍遥','男','18','4') +insert into bbsUsers(UID,uName,uSex,uAge,uPoint) +values(3,'七年级生','男','19','2') + +go +use bbs +go + +select * from bbsReply + +select uName,uPoint into bbsPoint from bbsUsers + +insert into bbsSection(sID,sName,sUid) +values(5,'技术交流',1) +insert into bbsSection(sID,sName,sUid) +values(6,'读书世界',3) +insert into bbsSection(sID,sName,sUid) +values(7,'生活百科',1) +insert into bbsSection(sID,sName,sUid) +values(8,'八卦区',3) + +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) +values(2,8,'范跑跑','谁是范跑跑','2008-7-8',1) +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) +values(3,5,'.NET','与JAVA的区别是什么呀?','2008-9-1',2) +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) +values(1,7,'今年夏天最流行什么 ','有谁知道今年夏天最流行什么呀?','2008-9-10',0) + +drop table bbsReply +select * from bbsReply +insert into bbsReply +select 3 , 2 , '范跑跑' , '2008-7-8' union +select 1 , 3 , 'java是代码', '2008-9-4' union +select 2 , 3 , '.NET是什么', '2008-9-4' union +select 2 , 1 , '不穿衣服' , '2008-9-20' + +select * from bbsUsers +delete bbsUsers where uName ='逍遥' +alter table bbsSection drop NK +alter table bbsTopic drop FK__bbsTopic__tUID__1920BF5C +update bbsUsers set uPoint ='10' where uName='小雨点' + +select * from bbsSection +delete bbsSection where sName='生活百科' + +select * from bbsReply +delete bbsReply + +use bbs +go + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的 版主编号, 版主姓名和 版块名称 +select * from bbsSection +select sUid 版主编, uName 版主姓名,sName 板块名称 from bbsSection inner join bbsUsers on bbsSection.sUid=bbsUsers.UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的 发帖人编号 ,发帖人姓名, 帖子的标题 ,帖子的内容 和发帖时间 +select * from bbsTopic +select tUID 发帖人编号, uName 发帖人姓名, tTitle 帖子标题,tMsg 帖子内容, tTime 发帖时间 from bbsTopic +inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID where tTime>'2008-9-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select UID 版主编号,uAge 年龄, uName 版主名称 ,sName 版块名称 from bbsUsers +inner join bbsSection on bbsSection.sUid=bbsUsers.UID where uAge<20 + +--4.查询出回复数量最多的主贴的 发帖人编号, 发帖人姓名, 主贴标题, 主贴内容和 回复数量 +select TOP 1 tUID 发帖人编号, uName 发帖人姓名, tTitle 帖子标题,tMsg 帖子内容, tCount 回复数量 from bbsTopic +inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID order by tCount DESC + + +--5.在主贴表 中查询 每个版块中 每个用户的 发帖总数 +select * from bbsTopic +select tUID 用户, count(tSID) 发帖总数 from bbsTopic group by tUID + -- Gitee From 50fecadc65f82aa23d5dab8dfb54397dde4048d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=BC=E7=9D=80=E5=A5=B6=E7=93=B6=E5=8E=BB=E6=89=93?= =?UTF-8?q?=E8=99=8E?= <1348328020@qq.com> Date: Fri, 26 Mar 2021 21:46:09 +0800 Subject: [PATCH 031/195] zy --- .../\347\273\203\344\271\2401.sql" | 66 +++++++++++++++ .../\347\273\203\344\271\2402.sql" | 84 +++++++++++++++++++ .../\347\273\203\344\271\2403.sql" | 20 +++++ 3 files changed, 170 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2401.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2402.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2403.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2401.sql" "b/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2401.sql" new file mode 100644 index 0000000..0f538c0 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2401.sql" @@ -0,0 +1,66 @@ +create database Student +on +( + name='Student', + filename='D:\SQL\Student.mdf' +) +log on +( + name='Student_log', + filename='D:\SQL\Student_log.ldf' +) +go + +create table StuInfo +( + stuNo char(5) primary key(stuNo), + stuName nvarchar(20), + stuAge int, + stuAddress text, + stuSeat int identity(1,1), + stuSex char(1) check(stuSex in(1,0)) +) + +create table StuExam +( + examNo int identity(1,1), + stuNo char(5), + writtenExam int check(writtenExam>=0 and writtenExam<=100), + labExam int check(labExam>=0 and labExam<=100) +) + + alter table StuExam add constraint RK_StuExam_stuNo foreign key(stuNo) references StuInfo(stuNo) + + insert into StuInfo 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 values + ('s2501',50,70),('s2502',60,65),('s2503',86,85),('s2504',40,80),('s2505',70,90),('s2506',85,90) + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select i.stuNo 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuInfo i left join StuExam e +on i.stuNo=e.stuNo where writtenExam>60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i left join StuExam e on i.stuNo=e.stuNo +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +where stuAge>=20 order by writtenExam DESC +--5.查询男女生的机试平均分 +select stuSex 性别,avg(labExam) 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +where stuAge>=20 group by stuSex +--6.查询男女生的笔试总分 +select stuSex 性别,sum(writtenExam) 笔试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2402.sql" "b/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2402.sql" new file mode 100644 index 0000000..59a3de1 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2402.sql" @@ -0,0 +1,84 @@ +create database Assignment +on +( + name='Assignment', + filename='D:\SQL\Assignment.mdf' +) +log on +( + name='Assignment_log', + filename='D:\SQL\Assignment_log.ldf' +) +go + +use Assignment +go +--drop table orderItem +create table orders +( + orderId int primary key, + orderDate date +) + +create table orderItem +( + ItemiD int identity(1,1) primary key, + orderId int references orders(orderId), + itemType varchar(12), + itemName varchar(12), + theNumber int, + theMoney money +) +insert into orders values + (1,'2008-01-12'), + (2,'2008-02-10'), + (3,'2008-02-15'), + (4,'2008-03-10') +insert into orderItem values + (1,'文具','笔',72,2), + (1,'文具','尺',10,1), + (1,'体育用品','篮球',1,56), + (2,'文具','笔',36,2), + (2,'文具','固体胶',20,3), + (2,'日常用品','透明胶',2,1), + (2,'体育用品','羽毛球',20,3), + (3,'文具','订书机',20,3), + (3,'文具','订书针',10,3), + (3,'文具','裁纸刀',5,5), + (4,'文具','笔',20,2), + (4,'文具','信纸',50,1), + (4,'日常用品','毛巾',4,5), + (4,'日常用品','透明胶',30,1), + (4,'体育用品','羽毛球',20,3) +-- 使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价 +from orders o inner join orderItem i on o.orderId=i.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称 +from orders o inner join orderItem i on o.orderId=i.orderId +where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 +from orders o inner join orderItem i on o.orderId=i.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 +from orders o inner join orderItem i on o.orderId=i.orderId +where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select o.orderId 订单编号,count(*) from orders o inner join orderItem i on o.orderId=i.orderId group by o.orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select o.orderId 订单编号,itemType 订购类别,count(*) 订购次数,sum(theNumber) 总数量 +from orders o inner join orderItem i on o.orderId=i.orderId group by o.orderId,itemType order by o.orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2403.sql" "b/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2403.sql" new file mode 100644 index 0000000..46670cb --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\347\273\203\344\271\2403.sql" @@ -0,0 +1,20 @@ +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 +from bbsSection bs inner join bbsUsers bu +on sUid=bu.UID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTitle 贴子的标题,tMsg 帖子的内容,tTime 发帖时间 +from bbsTopic bs inner join bbsUsers bu +on tUID=bu.UID where tTime>'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 +from bbsSection bs inner join bbsUsers bu +on sUid=bu.UID where uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select tUID 发帖人编号,uName 发帖人姓名,tTitle 贴子的标题,tMsg 帖子的内容,tCount 回复数量 +from bbsTopic bs inner join bbsUsers bu +on tUID=bu.UID where tCount=(select max(tCount) from bbsTopic) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName,uName 用户名,count(tUID ) 发帖总数 +from bbsSection S left join bbsUsers U on sUid =UID left join bbsTopic T on sID =tUID group by sName,uName -- Gitee From 1b9a593c768559f5efdda7c81420e2a69e89e9af Mon Sep 17 00:00:00 2001 From: BMxhd796815 <2396054158@qq.com> Date: Fri, 26 Mar 2021 22:08:11 +0800 Subject: [PATCH 032/195] first commit --- .../\344\275\234\344\270\2321.sql" | 98 ++++++++++++++ .../\344\275\234\344\270\2322.sql" | 104 +++++++++++++++ .../\344\275\234\344\270\2323.sql" | 121 ++++++++++++++++++ 3 files changed, 323 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2321.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2322.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2323.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2321.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..d90e1cf --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2321.sql" @@ -0,0 +1,98 @@ +use master +go +create database STU +on +( +name='STU', +filename='C:\SQL\STU.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='STU_log', +filename='C:\SQL\STU_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use STU +go +create table StuInfo +( +StuNO nvarchar(10) unique not null, +StuName nvarchar(10) not null, +StuAge int not null, +StuAddress nvarchar(200) , +StuSeat nvarchar(8) not null, +StuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) + +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','张秋利','20','美国硅谷','1','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','李斯文','18','湖北武汉','2','男') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','马文才','22','湖南长沙','3','男') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','欧阳俊雄','21','湖北武汉','4','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','梅超风','20','湖北武汉','5','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','陈旋风','19','美国硅谷','6','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','陈风','20','美国硅谷','7','女') + +create table Chengji +( +ExamNo int primary key identity(1,1), +StuNo nvarchar(10) references StuInfo(StuNO), +WittenExam int not null, +LabExam int not null +) +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2501','50','70') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2502','60','65') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2503','86','85') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2504','40','80') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2505','70','90') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2506','85','90') + + +--练习1 +--数据如图片1,使用上次作业的数据 +select * from StuInfo +select * from Chengji +--1.查询学生的姓名(StuName),年龄(StuAge),笔试成绩(WittenExam)和机试成绩(LabExam) +select StuInfo.StuNO,StuInfo.StuName 姓名,StuInfo.StuAge 年龄,Chengji.WittenExam 笔试成绩,Chengji.LabExam 机试成绩 +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号(StuNO),姓名(StuName),笔试成绩(WittenExam)和机试成绩(LabExam) +select StuInfo.StuNO 学号,StuInfo.StuName 姓名,Chengji.WittenExam 笔试成绩,Chengji.LabExam 机试成绩 +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo +where Chengji.WittenExam>60 and Chengji.LabExam>60 + +--3.查询所有学生的学号(StuNO),姓名(StuName),笔试成绩(WittenExam),机试成绩(LabExam),没有参加考试的学生的成绩以NULL值填充 +select StuInfo.StuNO 学号,StuInfo.StuName 姓名,Chengji.WittenExam 笔试成绩,Chengji.LabExam 机试成绩 +from StuInfo left join Chengji on StuInfo.StuNO=Chengji.StuNo + +--4.查询年龄(StuAge)在20以上(包括20)的学生的姓名(StuName),年龄(StuAge),笔试成绩(WittenExam)和机试成绩(LabExam),并按笔试成绩降序排列 +select StuInfo.StuNO 学号,StuInfo.StuName 姓名,StuInfo.StuAge 年龄,Chengji.WittenExam 笔试成绩,Chengji.LabExam 机试成绩 +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo +where StuInfo.StuAge>=20 order by WittenExam DESC + +--5.查询 男女生的 机试(LabExam)平均分 +select StuInfo.StuSex 性别, avg(LabExam) +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo +group by StuSex +--6.查询男女生的笔试(WittenExam)总分 +select StuInfo.StuSex 性别, sum(WittenExam) +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo +group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2322.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..6156fb3 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2322.sql" @@ -0,0 +1,104 @@ +use master +go +create database ORD +on +( +name='ORD', +filename='C:\SQL\ORD.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='ORD_log', +filename='C:\SQL\ORD_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use ORD +go +create table Orders +( +OrderID int primary key not null, +OrderDate datetime +) +go +use ORD +go +create table Orderltem +( +ItemID int primary key not null, +OrderID int references Orders(OrderID) not null, +ItemType varchar(8) not null, +ItemName varchar(6) not null, +TheNumber int not null, +TheMoney int not null +) +go +insert into Orders (OrderID,OrderDate) values(1,'2008-01-12') +insert into Orders (OrderID,OrderDate) values(2,'2008-02-10') +insert into Orders (OrderID,OrderDate) values(3,'2008-02-15') +insert into Orders (OrderID,OrderDate) values(4,'2008-03-10') + +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(1,1,'文具','笔','72','2') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(2,1,'文具','尺','10','1') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(3,1,'体育用具','篮球','1','56') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(4,2,'文具','笔','36','2') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(5,2,'文具','固体胶','20','3') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(6,2,'日常用品','透明胶','2','1') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(7,2,'体育用品','羽毛球','20','3') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(8,3,'文具','订书机','20','3') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(9,3,'文具','订书机','10','3') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(10,3,'文具','裁纸刀','5','5') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(11,4,'文具','笔','20','2') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(12,4,'文具','信纸','50','1' ) +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(13,4,'日常用品','毛巾','4','5') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(14,4,'日常用品','透明胶','30','1') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(15,4,'体育用品','羽毛球','20','3') + + +--练习2 +--使用上次作业的订单数据库,完成下列题目: +select * from Orders +select * from Orderltem +--1.查询所有的订单的订单的编号(OrderID),订单日期(OrderDate),订购产品的类别(ItemType)和订购的产品名称(ItemName),订购数量(TheNumber)和订购单价(TheMoney) +select Orders.OrderID 编号,Orders.OrderDate 日期,Orderltem.ItemType 类别,Orderltem.ItemName 名称,Orderltem.TheNumber 数量,Orderltem.TheMoney 单价 +from Orders inner join Orderltem on Orders.OrderID=Orderltem.OrderID + +--2.查询订购数量(TheNumber)大于50的订单的编号(OrderID),订单日期(OrderDate),订购产品的类别(ItemType)和订购的产品名称(ItemName) +select Orders.OrderID 编号,Orders.OrderDate 日期,Orderltem.ItemType 类别,Orderltem.ItemName 名称,Orderltem.TheNumber 数量 +from Orders inner join Orderltem on Orders.OrderID=Orderltem.OrderID +where Orderltem.TheNumber>50 + +--3.查询所有的订单的订单的编号(OrderID),订单日期(OrderDate),订购产品的类别(ItemType)和订购的产品名称(ItemName),订购数量(TheNumber)和订购单价(TheMoney)以及订购总价 +select Orders.OrderID 编号,Orders.OrderDate 日期,Orderltem.ItemType 类别,Orderltem.ItemName 名称,Orderltem.TheNumber 数量,Orderltem.TheMoney 单价, sum(Orderltem.TheNumber*Orderltem.TheMoney) 总价 +from Orders inner join Orderltem on Orders.OrderID=Orderltem.OrderID +group by Orders.OrderID,OrderDate,ItemType,ItemName,TheNumber,TheMoney + +--4.查询单价(TheMoney)大于等于5 并且 数量(TheNumber)大于等于50的订单 的订单的编号(OrderID),订单日期(OrderDate),订购产品的类别(ItemType)和订购的产品名称(ItemName),订购数量(TheNumber)和订购单价(TheMoney)以及订购总价 +select Orders.OrderID 编号,Orders.OrderDate 日期,Orderltem.ItemType 类别,Orderltem.ItemName 名称,Orderltem.TheNumber 数量,Orderltem.TheMoney 单价, sum(Orderltem.TheNumber*Orderltem.TheMoney) 总价 +from Orders inner join Orderltem on Orders.OrderID=Orderltem.OrderID +where Orderltem.TheMoney>=5 and Orderltem.TheNumber>=50 +group by Orders.OrderID,OrderDate,ItemType,ItemName,TheNumber,TheMoney + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号(OrderID) 订购产品数 +-- 1 3 +-- 2 4 +select Orders.OrderID 编号,count(*)订购产品数 +from Orderltem inner join Orders on Orders.OrderID=Orderltem.OrderID +group by Orders.OrderID + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +-- 订单编号(OrderID) 产品类别(ItemType) 订购次数 总数量 +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select Orders.OrderID 编号,Orderltem.ItemType 类别,count(*)订购次数,sum(TheNumber) 总数量 +from Orderltem inner join Orders on Orders.OrderID=Orderltem.OrderID +group by Orders.OrderID,ItemType diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2323.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2323.sql" new file mode 100644 index 0000000..9279915 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/\344\275\234\344\270\2323.sql" @@ -0,0 +1,121 @@ +use master +go +create database BBS +on +( +name='BBS', +filename='C:\SQL\BBS.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='BBS_log', +filename='C:\SQL\BBS_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use BBS +go +create table BBSUsers--用户信息表 +( +UID int not null, +UName varchar(10) not null, +USex varchar(2) not null, +UAge int not null, +UPoint int not null +) +alter table BBSUsers add constraint PK_BBSUsers_UID primary key(UID) +alter table BBSUsers add constraint UK_BBSUsers_UName unique(UName) +alter table BBSUsers add constraint CK_BBSUsers_USex check(USex='男' or USex='女') +alter table BBSUsers add constraint CK_BBSUsers_UAge check(UAge>=15 and UAge<=60) +alter table BBSUsers add constraint CK_BBSUsers_UPoint check(UPoint>=0) + +go +use BBS +go +create table BBSSection--回帖表 +( +SID int not null, +SName varchar(10) not null, +SUID int not null +) +alter table BBSSection add constraint PK_BBSSection_SID primary key(SID) +alter table BBSSection add constraint FK_BBSSection_SUID foreign key (SUID) references BBSUsers(UID) + +go +use BBS +go +create table BBSTopic--主贴表 +( +TID int primary key identity(1,1) not null, +TUID int references BBSUsers(UID) not null, +TSID int references BBSSection(SID) not null, +TTitle varchar(100) not null, +TMsg text not null, +TTime datetime , +Tcount int , +) +go +use BBS +go +create table BBSReply--版块表 +( +RID int primary key identity(1,1) not null, +RUID int references BBSUsers(UID) not null, +RTID int references BBSTopic(TID) not null, +RMsg text , +RTime datetime , +) +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(1,'小雨点','女','20','0') +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(2,'逍遥','男','18','4') +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(3,'七年级生','男','19','2') + +select UName,UPoint into BBSPoint from BBSUsers + +insert into BBSSection (SID,SName,SUID) values(4,'技术交流',1) +insert into BBSSection (SID,SName,SUID) values(5,'读书世界',3) +insert into BBSSection (SID,SName,SUID) values(6,'生活八卦',1) +insert into BBSSection (SID,SName,SUID) values(7,'八卦区',3) + +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(2,7,'范跑跑','谁是范跑跑','2008-7-8',1) +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(3,4,'.NET','与JAVA的区别是什么','2008-9-1',2) +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(1,6,'今夏最流行什么','有谁知道今夏最流行什么','2008-9-10',0) +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(2,7,'今夏最流行什么','今夏最流行阿巴阿巴阿巴','2008-7-8',1) + +insert into BBSReply (RUID,RMsg,RTime,RTID) values(1,'范跑跑是什么人。。。','2008-10-1',1) +insert into BBSReply (RUID,RMsg,RTime,RTID) values(2,'它们的区别是什么。。。','2008-11-1',2) +insert into BBSReply (RUID,RMsg,RTime,RTID) values(3,'最流行什么。。。','2008-11-20',3) + + +--练习3 +--在论坛数据库中完成以下题目 +select * from BBSUsers--用户信息表 +select * from BBSSection--版块表 +select * from BBSTopic--主贴表 +select * from BBSReply--回帖表 +--1.查询出每个版块的版主编号(RID),版主姓名(UName)和版块名称(RMsg) +select BBSReply.RID 编号,BBSUsers.UName 姓名,BBSReply.RMsg 版块名称 +from BBSReply inner join BBSUsers on BBSReply.RID=BBSUsers.UID + +--2.查询出主贴的发帖时间(TTime)在2008-9-15以后的主贴的发帖人编号(UID),发帖人姓名(UName),帖子的标题(TTitle),帖子的内容(TMsg)和发帖时间(TTime) +select BBSTopic.TID,BBSUsers.UID 发帖人编号,BBSUsers.UName 姓名,BBSTopic.TTitle 帖子的标题,BBSTopic.TMsg 帖子的内容,BBSTopic.TTime 发帖时间 +from BBSTopic inner join BBSUsers on BBSTopic.TID=BBSUsers.UID where TTime>'2008-9-15' + + +--3.查询出年龄在20以下的版主的编号(RID),版主的名称(UName)和版块的名称(RMsg) +select BBSReply.RID 编号,BBSUsers.UName 姓名,BBSReply.RMsg 版块名称,BBSUsers.UAge 年龄 +from BBSReply inner join BBSUsers on BBSReply.RID=BBSUsers.UID +where BBSUsers.UAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号(UID),发帖人姓名(UName),主贴标题(TTitle),主贴内容(TMsg)和回复数量 +select top 1 TUID 发帖人编号,BBSUsers.UName 姓名,BBSTopic.TTitle 帖子的标题,BBSTopic.TMsg 帖子的内容,Tcount 回复数量 +from BBSTopic inner join BBSUsers on BBSTopic.TID=BBSUsers.UID +order by Tcount desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select * from BBSTopic +select TUID 用户编号, count(TSID) 发帖总数 from BBSTopic group by TUID \ No newline at end of file -- Gitee From 30b8dce2dbcebba05ac8ea58f8622b0ae229bab8 Mon Sep 17 00:00:00 2001 From: meng-lingkun <1725116698@qq.com> Date: Fri, 26 Mar 2021 22:25:09 +0800 Subject: [PATCH 033/195] xxx --- .../\344\277\241\346\201\257\350\241\250.sql" | 139 ++++++++++++++++ .../\346\226\207\345\205\267\350\241\250.sql" | 127 ++++++++++++++ ...2\345\235\233\344\275\234\344\270\232.sql" | 156 ++++++++++++++++++ 3 files changed, 422 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\344\277\241\346\201\257\350\241\250.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\346\226\207\345\205\267\350\241\250.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\350\256\272\345\235\233\344\275\234\344\270\232.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\344\277\241\346\201\257\350\241\250.sql" "b/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\344\277\241\346\201\257\350\241\250.sql" new file mode 100644 index 0000000..f7ca264 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\344\277\241\346\201\257\350\241\250.sql" @@ -0,0 +1,139 @@ +use master +go + +create database Stundents + +on +( + name='Stundents', + filename='D:\TEXT\Stundents.mdf', + size=5MB, + maxsize=50MB, + filegrowth=10% +) +log on +( + name='Stundents_loig', + filename='D:\TEXT\Stundents_log.ldf', + size=5MB, + maxsize=50MB, + filegrowth=10% +) +go +use Stundents + +go + +create table StuInfo +( + StuNO char(5) primary key, + StuName nchar(5), + StuAge int, + StuAddress nchar(50), + StuSeat int identity(1,1), + StuSex char(1) check(stuSex = '1' or stuSex = '0') +) +go + +use Stundents +go +create table StuExam +( + ExamNO int identity(1,1) primary key, + StuNO char(5) constraint FK_stuInfo_stuNO references StuInfo(stuNO), + WrittenExam int check(WrittenExam >= 0 and WrittenExam <= 100), + LabExam int check(LabExam >= 0 and LabExam <= 100) +) +go + +use Stundents +go +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') +go + +use Stundents +go +insert into StuExam(StuNO,WrittenExam,LabExam) values ('s2501','50','70'),('s2502','60','65'),('s2503','86','65'), +('s2504','40','85'),('s2505','70','90'),('s2506','85','90') +go + +select StuNo 学号,StuName 姓名, StuAge 年龄, StuAddress 地址,StuSeat 座位号,StuSex 性别 from StuInfo + +select StuName,StuAge,StuAddress from StuInfo + +select StuNO 学号,笔试 = WrittenExam,LabExam as 机试 from StuExam + +select StuNo,stuName,StuAddress,邮箱 = StuName + '@' + StuAddress from StuInfo + +select StuNo,WrittenExam,LabExam,总分 = WrittenExam + LabExam from StuExam +select distinct StuAddress from StuInfo + +select stuAge, count(*) 所有年龄 from StuInfo group by StuAge + +select top 3 * from StuInfo + +select top 4 StuName,StuSeat from StuInfo + +select top 50 percent * from StuInfo + +select * from StuInfo where StuAddress = '湖北武汉' and StuAge = 20 + +select * from StuExam where LabExam >= 60 and LabExam <= 80 order by LabExam desc + +select * from StuInfo where StuAddress = '湖北武汉' or StuAddress = '湖南长沙' +select * from StuInfo where StuAddress in ('湖北武汉' , '湖南长沙') + +select * from StuExam where WrittenExam < 70 or WrittenExam > 90 order by WrittenExam asc + +select * from StuInfo where StuAge is null + +select * from StuInfo where StuAge is not null + +select * from StuInfo where StuName like '张%' + +select * from StuInfo where StuAddress like'%湖%' + +select * from StuInfo where StuName like '张_' + +select * from StuInfo where StuName like '__俊%' + +select * from StuInfo order by StuAge desc + +select * from StuInfo order by StuAge desc, stuSeat asc + +select top 1 * from StuExam order by WrittenExam desc + +select top 1 * from StuExam order by LabExam asc + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 + +select StuExam.StuNO 学号,stuName 姓名,StuAge 年龄,WrittenExam 笔试,LabExam 机试 +from StuInfo inner join StuExam on StuExam.StuNO = StuInfo.StuNO + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 + +select StuExam.StuNO 学号,StuName 姓名,WrittenExam 笔试,LabExam 机试 +from StuInfo inner join StuExam on StuExam.StuNO = StuInfo.StuNO where WrittenExam > 60 and LabExam > 60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 + +select StuExam.StuNO 学号,StuName 姓名,WrittenExam 笔试,LabExam 机试 +from StuInfo left join StuExam on StuExam.StuNO = StuInfo.StuNO + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 + +select StuExam.StuNO 学号,StuName 姓名,StuAge 年龄,WrittenExam 笔试,LabExam 机试 +from StuInfo inner join StuExam on StuExam.StuNO = StuInfo.StuNO where StuAge >= 20 order by WrittenExam desc + +--5.查询男女生的机试平均分 + +select StuSex 性别,COUNT(*) 人数,AVG(LabExam) 平均分 +from StuInfo inner join StuExam on StuExam.StuNO = StuInfo.StuNO group by StuSex + +--6.查询男女生的笔试总分 + +select StuSex 性别,COUNT(*)人数,sum(WrittenExam) 笔试总分 +from StuInfo inner join StuExam on StuExam.StuNO = StuInfo.StuNO group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\346\226\207\345\205\267\350\241\250.sql" "b/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\346\226\207\345\205\267\350\241\250.sql" new file mode 100644 index 0000000..0ace4b5 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\346\226\207\345\205\267\350\241\250.sql" @@ -0,0 +1,127 @@ +use master + +go + +create database TEXT + +go +use TEXT + +go + +create table orders +( + orderID int primary key identity(1,1), + orderDate date +) + +go +use TEXT +go + +create table orderItem +( + ItemiD int primary key identity(1,1), + orderId int, + itemType nvarchar(20), + itemName nvarchar(20), + theNumber int, + theMoney money +) +go +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') +go +insert into orderItem values(1,'文具','笔',72,2),(1,'文具','尺',10,1),(1,'体育用品','篮球',1,56),(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3),(2,'日常用品','透明胶',2,1),(2,'体育用品','羽毛球',20,3),(3,'文具','订书机',20,3),(3,'文具','订书针',10,3), +(3,'文具','裁纸机',5,5),(4,'文具','笔',20,2),(4,'文具','信纸',50,1),(4,'日常用品','毛巾',4,5),(4,'日常用品','透明胶',30,1),(4,'体育用品','羽毛球',20,3) + +select * from orderItem + +--1.查询所有订单订购的所有物品数量总和 + +select sum(theNumber)数量 from orderItem + +--2.查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 + +select orderId 订单编号,avg(theMoney)平均单价,theNumber 物品数量 from orderItem where orderId<3 group by orderId,theMoney,theNumber having +avg(theMoney)<10 + +--3.查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 + +select avg(theMoney) 平均单价,sum(theNumber) 数量总和 from orderItem group by theMoney,theNumber having avg(theMoney)<10 and sum(theNumber)>50 + +--4.查询每种类别的产品分别订购了几次,例如: +-- 文具 9 +-- 体育用品 3 +-- 日常用品 3 + +select itemType 类别, COUNT(*) 订购次数 from orderItem group by itemType + +--5.查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 + +select itemType 类别,sum(theNumber) 总数量,avg(theMoney) 平均单价 from orderItem group by itemType having sum(theNumber)>100 + +--6.查询每种产品的订购次数,订购总数量和订购的平均单价,例如: + +-- 产品名称 订购次数 总数量 平均单价 +-- 笔 3 120 2 + +select itemName 名称, COUNT(*) 订购次数, SUM(theNumber)总数量,avg(theMoney) 平均单价 from orderItem group by itemName + + + + + + + + + + + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orders.orderID,orderDate,itemType,itemName,theNumber,theMoney from orderItem inner join orders on orders.orderID = orderItem.orderId + + +--2.查询 订购数量 大于50的 订单的编号,订单日期,订购产品的类别和订购的产品名称 + +select orders.orderID 编号,theNumber 数量,orderDate 日期,itemType 类别,itemName 名称 +from orderItem inner join orders on orders.orderID = orderItem.orderId where theNumber > 50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量 和订购单价以及 订购总价 +--select OI.orderID,orderDate,itemType,itemName,theNumber,theMoney,theNumber*theMoney 订购总价 +--from orderItem OI left join orders O on OI.orderId=O.orderID + +select orders.orderID 编号,orderDate 日期,itemType 类别,itemName 名称,theNumber 数量,theMoney 单价,theNumber*theMoney 订购总价 +from orderItem left join orders on orders.orderID = orderItem.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orders.orderID 编号,orderDate 日期,itemType 类别,itemName 名称,theNumber 数量,theMoney 单价,theMoney*theNumber 总价 +from orderItem left join orders on orders.orderID = orderItem.orderId where theNumber >= 50 and theMoney >= 5 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 + +select orders.orderID 编号,itemType 类别 from orderItem inner join orders on orders.orderID = orderItem.orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select * from orderItem +select orders.orderID 编号,itemType 产品类别,orderItem.orderId 订购次数,theNumber 数量,orderItem.orderId*theNumber 总数量 +from orderItem inner join orders on orders.orderID = orderItem.orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\350\256\272\345\235\233\344\275\234\344\270\232.sql" "b/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\350\256\272\345\235\233\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..a421f52 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\350\256\272\345\235\233\344\275\234\344\270\232.sql" @@ -0,0 +1,156 @@ +use master +go + +create database bbs +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +-- +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) +-- +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) +-- +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('男','女')) +-- +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) +-- +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) +-- + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +-- +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values +('小雨点','女',20,0), +('逍遥','男',18,4), +('七年级生','男',19,2) + + +select * into bbsPoint from bbsUsers + +insert into bbsSection values +('技术交流',1), +('读书世界',3), +('生活百科',1), +('八卦区',3) + +insert into bbsTopic values +(2,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0), +(3,1,'.NET','与JAVA的区别是什么呀?',2008-9-1,2), +(1,3,'范跑跑','谁是范跑跑',2008-7-8,1) + +insert into bbsReply values +(2,1,'不知道',2008-9-10), +(3,2,'不知道',2008-9-1), +(1,3,'不知道',2008-7-8) + +select * from bbsReply --回帖表 +select * from bbsSection --版块表 +select * from bbsTopic --主帖表 +select * from bbsUsers --用户信息表 + +--用户信息表(bbsUsers) +-- 用户编号 UID int 主键 标识列 +-- 用户名 uName varchar(10) 唯一约束 不能为空 +-- 性别 uSex varchar(2) 不能为空 只能是男或女 +-- 年龄 uAge int 不能为空 范围15-60 +-- 积分 uPoint int 不能为空 范围 >= 0 + +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select bbsUsers.UID 版主编号,uName 姓名,sName 版块名称 +from bbsSection inner join bbsUsers on bbsUsers.UID = bbsSection.sUid + +-- 版块表(bbsSection) +-- 版块编号 sID int 标识列 主键 +-- 版块名称 sName varchar(10) 不能为空 +-- 版主编号 sUid int 外键 引用用户信息表的用户编号 + + + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 + +select bbsUsers.UID 编号,uName 姓名,tTitle 标题,tMsg 内容,tTime 时间 +from bbsTopic inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID where tTime > '2008-9-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select bbsUsers.UID 编号,uName 姓名,sName 版块名称,uAge 年龄 +from bbsSection inner join bbsUsers on bbsUsers.UID = bbsSection.sUid where uAge < 20 + + +--+ 主贴表(bbsTopic) +-- 主贴编号 tID int 主键 标识列, +-- 发帖人编号 tUID int 外键 引用用户信息表的用户编号 +-- 版块编号 tSID int 外键 引用版块表的版块编号 (标明该贴子属于哪个版块) +-- 贴子的标题 tTitle varchar(100) 不能为空 +-- 帖子的内容 tMsg text 不能为空 +-- 发帖时间 tTime datetime +-- 回复数量 tCount int + + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select bbsUsers.UID 编号,uName 姓名,tTitle 标题,tMsg 内容,tCount 回复数量 +from bbsTopic inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID where tCount = (select MAX(tCount) from bbsTopic) + +---5.在主贴表中查询每个版块中每个用户的发帖总数 +select sID 版块,uName 姓名,COUNT(*)总数 from bbsSection inner join bbsUsers on bbsUsers.UID = bbsSection.sUid +inner join bbsTopic on bbsTopic.tUID = bbsUsers.UID group by sID,uName + +--+ 回帖表(bbsReply) +-- 回贴编号 rID int 主键 标识列, +-- 回帖人编号 rUID int 外键 引用用户信息表的用户编号 +-- 对应主贴编号 rTID int 外键 引用主贴表的主贴编号 (标明该贴子属于哪个主贴) +-- 回帖的内容 rMsg text 不能为空 +-- 回帖时间 rTime datetime + + + + + + + + + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + + -- Gitee From 345db773bc31046e73988d9bca1ad4edae8b4f1c Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 26 Mar 2021 23:11:52 +0800 Subject: [PATCH 034/195] 789 --- .../\344\275\234\344\270\2321.sql" | 76 +++++++++++++ .../\344\275\234\344\270\2322.sql" | 97 ++++++++++++++++ .../\344\275\234\344\270\2323.sql" | 104 ++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2321.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2322.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2323.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2321.sql" "b/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..1d6c82e --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2321.sql" @@ -0,0 +1,76 @@ +create database Studentinfo +on +( + name='Studentinfo', + filename='D:\Studentinfo.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='Studentinfo_log', + filename='D:\Studentinfo_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +use Studentinfo +go +create table StuDent +( + sTUNO varchar(15), + stuName nvarchar(20), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') +) + +insert into StuDent(sTUNO,stuName,stuAge,stuAddress,stuSeat,stuSex) +select 's2501','张秋里',20,'美国硅谷',1,'男' union +select 's2502','李斯文',18,'湖北武汉',2,'女' union +select 's2503','马文才',22,'湖南长沙',3,'男' union +select 's2504','欧阳俊雄',21,'湖北武汉',4,'女' union +select 's2505','梅超风',20,'湖北武汉',5,'男' union +select 's2506','陈旋风',19,'美国硅谷',6,'男' union +select 's2507','陈风',20,'美国硅谷',7,'女' + + +create table Score +( + examNO int, + stuNO varchar(15), + writtenExam int, + labExam int +) + + +insert into Score(examNO,stuNO,writtenExam,labExam) +select 1,'s2501','50','70' union +select 2,'s2502','60','65' union +select 3,'s2503','86','85' union +select 4,'s2504','40','80' union +select 5,'s2505','70','90' union +select 6,'s2506','85','90' + + + + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试,labExam 机试 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuDent.sTUNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO where writtenExam>60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuDent.sTUNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuDent left join Score on StuDent.sTUNO=Score.stuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO where stuAge>=20 order by writtenExam desc +--5.查询男女生的机试平均分 +select stuSex,avg(labExam)平均分 from Score left join StuDent on Score.stuNO=StuDent.sTUNO group by stuSex +--6.查询男女生的笔试总分 +select stuSex,sum(writtenExam)总分 from Score left join StuDent on Score.stuNO=StuDent.sTUNO group by stuSex + +select * from Score +select * from StuDent diff --git "a/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2322.sql" "b/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..223d80b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2322.sql" @@ -0,0 +1,97 @@ +create database cc +on +( + name='cc', + filename='D:\cc.mdf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) +log on +( + name='cc_log', + filename='D:\cc.ldf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) +go +use cc +go +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) + +create table orders +( + orderId int primary key, + orderDate datetime +) +--插入表1数据 +insert into orders(orderId,orderDate) +select 1,'2008-01-12' union +select 2,'2008-02-10' union +select 3,'2008-02-15' union +select 4,'2008-03-10' +select * from orders +--订购项目表(orderItem),列为: +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) +create table orderItem +( + ItemiD int primary key identity(1,1), + orderId int, + itemType varchar(20), + itemName varchar(20), + theNumber int , + theMoney int +) +--添加表二的外键约束 关联表一的order id +alter table orderItem add constraint FK foreign key (orderId) references orders(orderId) +--插入表2数据 +insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) +select 1,'文具','笔',72,2 union +select 1,'文具','尺',10,1 union +select 1,'体育用品','篮球',1,56 union +select 2,'文具','笔',36,2 union +select 2,'文具','固体胶',20,3 union +select 2,'日常用品','透明胶',2,1 union +select 2,'体育用品','羽毛球',20,3 union +select 3,'文具','订书机',20,3 union +select 3,'文具','订书针',10,3 union +select 3,'文具','裁纸刀',5,5 union +select 4,'文具','笔',20,2 union +select 4,'文具','信纸',50,1 union +select 4,'日常用品','毛巾',4,5 union +select 4,'日常用品','透明胶',30,1 union +select 4,'体育用品','羽毛球',20,3 + +--使用上次作业的订单数据库,完成下列题目: +--订单表(orders) 订购项目表(orderItem) +select * from orders +select * from orderItem +--1.查询所有的订单的 订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orderItem.orderId 订单编号,orders.orderDate 日期,itemType 类别,itemName 产品名称,theNumber 数量,theMoney 单价 from orderItem inner join orders on orderItem.orderId=orders.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId 订单编号,theNumber 数量,orders.orderDate 日期,itemType 类别,itemName 产品名称 from orderItem inner join orders on orderItem.orderId=orders.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orders.orderDate 日期,itemName 产品名称,theNumber 数量,theMoney 单价 ,theMoney*theNumber 订购总价 +from orderItem inner join orders on orderItem.orderId=orders.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orderDate 日期,itemType 类别,itemName 产品名称,theNumber 数量,theMoney 单价 ,theMoney*theNumber 订购总价 + from orderItem inner join orders on orderItem.orderId=orders.orderId where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId 编号 ,count(itemName)订购产品数 from orderItem group by orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +select orderId,itemType 类别,count(itemType)次数,sum(theNumber)总数量 from orderItem group by orderId,itemType order by orderId asc +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2323.sql" "b/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2323.sql" new file mode 100644 index 0000000..8277e7b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\220\264\347\205\214/\344\275\234\344\270\2323.sql" @@ -0,0 +1,104 @@ +create database bbs + +on +( + name='bbs', + filename='D:\bbs.mdf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='D:\bbs_log.ldf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +go +use bbs +go +create table bbsUsers +( + UIDD int identity, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +create table bbsSection +( + sIDD int identity, + sName varchar(10) not null, + sUid int +) + +alter table bbsUsers add constraint Pk_bbsUsers_UIDD primary key(UIDD) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uPoint check(uPoint>=0) + +alter table bbsSection add constraint Pk_bbsSection_sIDD primary key(sIDD) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UIDD) + +create table bbsTopic +( + tID int identity primary key, + tUID int foreign key references bbsUsers(UIDD), + tSID int foreign key references bbsSection(sIDD), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int identity primary key, + rUID int foreign key references bbsUsers(UIDD), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'),(3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), +(1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') + +insert into bbsReply values(3,2,'八嘎','2008-7-8'),(1,1,'python','2008-7-8'),(1,3,'上海','2008-7-8') + +--据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sIDD,uName,sName from bbsSection left join bbsUsers on sIDD=UIDD + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID,uName,tTitle,tMsg,tTime from bbsTopic left join bbsUsers on tID=UIDD where tTime > '2008-09-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sIDD,uName,sName,uAge from bbsSection left join bbsUsers on sIDD=UIDD where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tUID,uName,tTitle,tMsg,tCount from bbsUsers t left join bbsTopic x on t.UIDD=x.tID order by tCount desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select uName 用户名,sName 版块名称,count(*)发帖总数 from bbsTopic + inner join bbsUsers on bbsTopic.tUID = bbsUsers.UIDD + inner join bbsSection on bbsUsers.UIDD= bbsSection.sUid group by uName,sName + + + + +select * from bbsReply --回帖表 +select * from bbsSection --版块表 +select * from bbsTopic --主帖表 +select * from bbsUsers --用户信息表 + + + + + + -- Gitee From a605b34a79da78f8469feb39ae91de653cf09d8c Mon Sep 17 00:00:00 2001 From: linghuanye <1271919148@qq.com> Date: Sat, 27 Mar 2021 12:41:16 +0800 Subject: [PATCH 035/195] first commit --- .../\344\275\234\344\270\2321.sql" | 108 ++++++++++++++ .../\344\275\234\344\270\2322.sql" | 110 ++++++++++++++ .../\344\275\234\344\270\2323.sql" | 134 ++++++++++++++++++ 3 files changed, 352 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2321.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2322.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2323.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2321.sql" "b/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..16968f5 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2321.sql" @@ -0,0 +1,108 @@ +use master +go + +create database Student05 +go + +use Student05 +go + +create table StuIS +( + StuNO nvarchar(10) unique not null, + StuName nvarchar(10) not null, + StuAge int not null, + StuAddress nvarchar(200) , + StuSeat nvarchar(8) not null, + StuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) + +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','张秋利','20','美国硅谷','1','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','李斯文','18','湖北武汉','2','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','马文才','22','湖南长沙','3','男') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','欧阳俊雄','21','湖北武汉','3','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','梅超风','20','湖北武汉','4','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','陈旋风','19','美国硅谷','5','女') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','陈风','20','美国硅谷','7','女') + +select *from StuIS +select 学号=StuNO ,姓名=StuName,年龄=StuAge,地址=StuAddress,座位号=StuSeat,性别=StuSex from StuIS +select Stuname,StuAge,StuAddress from StuIS +select 学号=StuNO ,姓名=StuName,地址=StuAddress,邮箱=StuName+StuAddress from StuIS +select distinct StuAddress from StuIS +select distinct StuAge as 所有年龄 from StuIS +select top 3 *from StuIS +select top 4 StuName,StuSeat from StuIS +select top 50 percent *from StuIS +select * from StuIS where StuAddress in ('湖北武汉','湖南长沙') +select * from StuIS where StuAddress='湖北武汉' or StuAddress ='湖南长沙' +select * from StuIS where StuAge is null +select * from StuIS where StuAge is not null +select * from StuIS where StuName like '张%' +select * from StuIS where StuAddress like '%湖%' +select * from StuIS where StuName like '张_' +select * from StuIS where StuName like '__俊%' +select * from StuIS order by StuAge DESC +select * from StuIS order by StuAge DESC , StuSeat ASC + + +create table Grate +( + ExamNo int primary key identity(1,1), + StuNo nvarchar(10) references StuIS(StuNO), + WExam int not null, + LabExam int not null +) +insert into Grate(StuNO,WExam,LabExam) +values('s2501','50','70') +insert into Grate(StuNO,WExam,LabExam) +values('s2502','60','65') +insert into Grate(StuNO,WExam,LabExam) +values('s2503','86','85') +insert into Grate(StuNO,WExam,LabExam) +values('s2504','40','80') +insert into Grate(StuNO,WExam,LabExam) +values('s2505','70','90') +insert into Grate(StuNO,WExam,LabExam) +values('s2506','85','90') + +select *from Grate +select 学号=StuNO , 笔试=WExam,机试=LabExam from Grate +select StuNo as 学号 , WExam as 笔试, LabExam as 机试 from Grate +select StuNo 学号 ,WExam 笔试,LabExam 机试 from Grate +select StuNO, WExam ,LabExam,总分=WExam+LabExam from Grate +select * from Grate where WExam<70 or WExam>90 order by WExam DESC +select top 1 * from Grate order by WExam DESC +select top 1 * from Grate order by WExam ASC + +select * from StuIS +select * from Grate + + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName 姓名,StuAge 年龄,WExam 笔试成绩,LabExam 机试成绩 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuIS.StuNO,StuName,WExam,LabExam from StuIS left join Grate on StuIS.StuNO=Grate.StuNo where WExam>60 and LabExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuName 姓名,WExam 笔试成绩,LabExam 机试成绩 from StuIS left join Grate on StuIS.StuNO=Grate.StuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName 姓名,StuAge 年龄, WExam 笔试成绩,LabExam 机试成绩 from StuIS + inner join Grate on StuIS.StuNO=Grate.StuNo where StuAge>=20 order by WExam DESC + +--5.查询男女生的机试平均分 +select StuSex,AVG(LabExam)机试平均分 from StuIS inner join Grate on StuIS.StuNO= Grate.StuNo group by StuSex + +--6.查询男女生的笔试总分 +select StuSex,sum(WExam)笔试总分 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2322.sql" "b/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..2b17333 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2322.sql" @@ -0,0 +1,110 @@ +use master +go + +create database ordersystem +on +( + name='ordersystem', + filename='D:\数据库\ordersystem.mdf', + size=5mb, + maxsize=100mb, + filegrowth=15% +) + +log on +( + name='bank_log', + filename='D:\数据库\ordersystem_log.ldf', + size=5mb, + maxsize=100mb, + filegrowth=15% +) + +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) +use ordersystem +go + + create table orders + ( + orderId int primary key identity(1,1), + orderDate datetime + ) + +--订购项目表(orderItem),列为: +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) +create table orderItem +( + ItemiD int primary key identity, + orderId nchar(10), + itemType nvarchar(8), + itemName varchar(10), + theNumber int, + theMoney int +) + + +select * from orders +insert into orders values +('2008-01-02 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 orderItem +insert into orderItem values +('1','文具','笔','72','2'), +('1','文具','笔','10','1'), +('1','体育用品','篮球','1','56'), +('2','文具','笔','36','2'), +('2','文具','固体胶','20','3'), +('2','日常用品','透明胶','2','1'), +('2','体育用品','羽毛球','20','3'), +('3','文具','订书机','20','3'), +('3','文具','订书针','10','3'), +('3','文具','裁纸刀','5','5'), +('4','文具','笔','20','2'), +('4','文具','信纸','50','1'), +('4','日常用品','毛巾','4','5'), +('4','日常用品','透明胶','30','1'), +('4','体育用品','羽毛球','30','3') + + +--使用上次作业的订单数据库,完成下列题目: + +select * from orders--订单表 +select * from orderItem--订购项目表 + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney from orderItem left join +orders on orderItem.orderId=orders.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId,orderDate,itemType,itemName from orderItem inner join + orders on orderItem.orderId=orders.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber*theMoney 订购总价 +from orderItem left join orders on orderItem.orderId=orders.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber*theMoney 订购总价 +from orderItem left join orders on orderItem.orderId=orders.orderId where theMoney>5 and theNumber>50 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId,COUNT(theNumber)产品数 from orderItem group by orderId + +---6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +--订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderId,itemType,COUNT(theNumber)订购次数,sum(theNumber)总数量 from orderItem +group by orderId,itemType order by orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2323.sql" "b/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2323.sql" new file mode 100644 index 0000000..34dbdcd --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2323.sql" @@ -0,0 +1,134 @@ +use master +go + +create database bbs +on +( + name='bbs', + filename='D:\数据库\bbs.mdf', + size=10mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='D:\数据库\bbs_log.ldf', + size=10mb, + maxsize=100mb, + filegrowth=10mb +) + +use bbs +go + +create table bbsUsers +( + UID int not null, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +alter table bbsUsers add constraint PK primary key (UID) +alter table bbsUsers add constraint FK unique (uName) +alter table bbsUsers add constraint CK check(uSex='男' or uSex='女') +alter table bbsUsers add constraint DK check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint UK check(uPoint>=0) + + +create table bbsSection +( + sID int not null, + sName varchar(10) not null, + sUid int not null +) +alter table bbsSection add constraint BK primary key(sID) +alter table bbsSection add constraint NK foreign key (sUid) references bbsUsers( UID) + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int references bbsUsers(UID), + tSID int references bbsSection(sID), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int primary key identity(1,1), + rUID int references bbsUsers(UID), + rTID int references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +select * from bbsUsers +insert into bbsUsers(UID,uName,uSex,uAge,uPoint) +values(1,'小雨点','女','20','0') +insert into bbsUsers(UID,uName,uSex,uAge,uPoint) +values(2,'逍遥','男','18','4') +insert into bbsUsers(UID,uName,uSex,uAge,uPoint) +values(3,'七年级生','男','19','2') + +select * from bbsSection +insert into bbsSection(sID,sName,sUid) +values(5,'技术交流',1) +insert into bbsSection(sID,sName,sUid) +values(6,'读书世界',3) +insert into bbsSection(sID,sName,sUid) +values(7,'生活百科',1) +insert into bbsSection(sID,sName,sUid) +values(8,'八卦区',3) + +select * from bbsTopic +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) +values(2,8,'范跑跑','谁是范跑跑','2008-7-8',1) +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) +values(3,5,'.NET','与JAVA的区别是什么呀?','2008-9-1',2) +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) +values(1,7,'今年夏天最流行什么 ','有谁知道今年夏天最流行什么呀?','2008-9-10',0) + +select * from bbsReply +insert into bbsReply(rUID,rTID,rMsg,rTime) +values(1,3,'范跑跑','2008-10-2') +insert into bbsReply(rUID,rTID,rMsg,rTime) +values(2,2,'区别不大','2008-10-2') +insert into bbsReply(rUID,rTID,rMsg,rTime) +values(3,1,'蓝色','2008-10-2') + + + +--在论坛数据库中完成以下题目 +--1.查询出 每个版块 的 版主编号,版主姓名和版块名称 +select * from bbsUsers +select * from bbsTopic +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection inner join bbsTopic on sID=tSID +inner join bbsUsers on tUID=UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select * from bbsTopic +select tUID 发帖人编号,uName 发帖人姓名,tTitle 帖子的标题,tMsg 帖子的内容,tTime 发帖时间 +from bbsUsers inner join bbsTopic on UID=tUID where tCount>2008-9-15 + + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select * from bbsUsers +select * from bbsSection +select sUid 版主编号,uName 版主的名称,sName 版主编号 from bbsSection inner join bbsUsers on sUid=UID where uAge<20 + + +--4.查询出 回复数量最多 的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select * from bbsUsers +select tUID 发帖人编号,uName 姓名,tTitle 主贴标题,tMsg 主贴内容,tCount 回复数量 +from bbsTopic inner join bbsUsers on tUID=UID + +--5.在 主贴表中 查询 每个版块中 每个用户 的 发帖总数 +select * from bbsTopic--主贴表 +select * from bbsSection--版块表 +select * from bbsUsers--用户信息表 +select UID 用户编号,uName 用户名,sID 版块编号,count(sID)发帖总数 from bbsTopic inner join bbsUsers on tUID=UID inner join +bbsSection on sUid=UID group by UID,uName,sID -- Gitee From 78b8dfdca7bb66506a4264f2b0750cb8d3e3ff17 Mon Sep 17 00:00:00 2001 From: huangziyi <3120130015@qq.com> Date: Sat, 27 Mar 2021 19:42:44 +0800 Subject: [PATCH 036/195] first commit --- .../12580/233333.sql" | 103 ++++++++++++++++ .../12580/SQLQuery3.sql" | 89 ++++++++++++++ .../12580/\344\275\234\344\270\2324.sql" | 110 ++++++++++++++++++ 3 files changed, 302 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/12580/233333.sql" create mode 100644 "20210326\344\275\234\344\270\232/12580/SQLQuery3.sql" create mode 100644 "20210326\344\275\234\344\270\232/12580/\344\275\234\344\270\2324.sql" diff --git "a/20210326\344\275\234\344\270\232/12580/233333.sql" "b/20210326\344\275\234\344\270\232/12580/233333.sql" new file mode 100644 index 0000000..5970d58 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/12580/233333.sql" @@ -0,0 +1,103 @@ +use master +go +create database odXHSD +on +( name='odXHSD', + filename='C:\test\odXHSD.mdf', + size=20, + maxsize=100, + filegrowth=10% + ) + log on + ( name='odXHSD_log', + filename='C:\test\odXHSD_log.ldf', + size=20, + maxsize=100, + filegrowth=10% + ) + go + use odXHSD + go + create table orders + ( orderId int primary key identity(1,1), + orderDate datetime, + ) + insert into orders(orderDate) values('2008-01-12 ') + insert into orders(orderDate) values('2008-02-10 ') + insert into orders(orderDate) values('2008-02-15 ') + insert into orders(orderDate) values('2008-03-10 ') + + + create table orderItem + ( ItemiD int primary key identity, + orderId int , + itemType nvarchar(20), + itemName nvarchar(10), + theNumber int, + theMoney money + ) + + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (1,'文具','笔','72' ,'2' ) + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (1,'文具','尺','10' ,'1' ) + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (1,'体育用品','篮球','1','56' ) + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (2,'文具','笔','36','2') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (2,'文具','固体胶','20','3') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (2,'日常用品','透明胶','36','2') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (2,'体育用品','羽毛球','20','3') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (3,'文具','订书机','20','3') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (3,'文具','订书针','10','3') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (3,'文具','裁纸刀','5','5') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'文具','笔','20','2') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'文具','信纸','50','1') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'日常用品','毛巾','4','5') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'日常用品','透明胶','30','1') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'体育用品','羽毛球','20','3' ) + + select * from orders + select * from orderItem + + select sum(theNumber) from orderItem + select orderId,sum(theNumber)As 订购总数量,avg(theMoney)As 平均单价 from orderItem group by orderId having orderId<3 and avg(theMoney)<10 order by orderId + select sum(theNumber)As 订购总数量,avg (theMoney)As 平均单价 from orderItem group by theNumber,theMoney having sum(theNumber)>50 and avg(theMoney)<10 order by theNumber,theMoney + select itemType,COUNT(*)数量 from orderItem group by itemType order by itemType desc + select sum(theNumber)As 订购总数量,avg(theMoney)As 平均单价 from orderItem group by itemType,theMoney having sum(theNumber)>100 + select itemName As 产品名称,count(theNumber) As 订购次数,sum(theNumber)As 总数量,avg(theMoney)As 平均单价 from orderItem group by itemName + +--使用上次作业的订单数据库,完成下列题目: + + select * from orders + select * from orderItem + +--1.查询 所有的订单 的 订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderId,orders.orderDate,orderItem.itemType,orderItem.itemName,orderItem.theNumber,orderItem.theMoney from orders +inner join orderItem on orders.orderId=orderItem.orderId group by orders.orderId,orders.orderDate,itemType,itemName,theNumber,theMoney +--2.查询 订购数量大于50的 订单的编号,订单日期,订购产品的类别 和 订购的产品名称 +select orders.orderId,orders.orderDate,orderItem.itemType,orderItem.itemName from orders +inner join orderItem on orders.orderId=orderItem.orderId +where orderItem.theNumber > 50 +group by orders.orderId,orders.orderDate,orderItem.itemType,orderItem.itemName +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId,orders.orderDate,orderItem.itemType,orderItem.itemType,orderItem.theNumber,orderItem.theMoney,sum(orderItem.theNumber*orderItem.theMoney) from orders +inner join orderItem on orders.orderId=orderItem.orderId group by orders.orderId,orders.orderDate,itemType,theNumber,theMoney + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + select orders.orderId,orders.orderDate,orderItem.itemType,orderItem.itemName,orderItem.theNumber ,orderItem.theMoney,sum(orderItem.theNumber*orderItem.theMoney) from orders + inner join orderItem on orders.orderId=orderItem.orderId group by orders.orderId,orders.orderDate,orderItem.itemType,orderItem.itemName,orderItem.theNumber ,orderItem.theMoney + having theMoney >5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 + +select orders.orderId,orderItem.itemName from orders +inner join orderItem on orders.orderId = orderItem.orderId group by orders.orderId,orderItem.itemName + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/12580/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/12580/SQLQuery3.sql" new file mode 100644 index 0000000..dfbc979 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/12580/SQLQuery3.sql" @@ -0,0 +1,89 @@ +use master +go +create database student +on +( +name='student', +filename='C:\test\student.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='STU_log', +filename='C:\test\student_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use student +go +create table StuInfo +( +StuNO nvarchar(10) unique not null, +StuName nvarchar(10) not null, +StuAge int not null, +StuAddress nvarchar(200) , +StuSeat nvarchar(8) not null, +StuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) + +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','张秋利','20','美国硅谷','1','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','李斯文','18','湖北武汉','2','男') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','马文才','22','湖南长沙','3','男') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','欧阳俊雄','21','湖北武汉','4','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','梅超风','20','湖北武汉','5','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','陈旋风','19','美国硅谷','6','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','陈风','20','美国硅谷','7','女') + +create table Grade +( +ExamNo int primary key identity(1,1), +StuNo nvarchar(10) references StuInfo(StuNO), +WittenExam int not null, +LabExam int not null +) +select* from Grade +insert into Grade(StuNO,WittenExam,LabExam) +values('s2501','50','70') +insert into Grade(StuNO,WittenExam,LabExam) +values('s2502','60','65') +insert into Grade(StuNO,WittenExam,LabExam) +values('s2503','86','85') +insert into Grade(StuNO,WittenExam,LabExam) +values('s2504','40','80') +insert into Grade(StuNO,WittenExam,LabExam) +values('s2505','70','90') +insert into Grade(StuNO,WittenExam,LabExam) +values('s2506','85','90') + + +select * from StuInfo +select * from Grade + +select StuName,StuAge,WittenExam,LabExam from StuInfo inner join Grade on Grade.StuNo=StuInfo.StuNO + +select StuInfo.StuNO,StuName,Grade.WittenExam,LabExam from StuInfo inner join Grade on Grade.StuNo=StuInfo.StuNO where Grade.WittenExam>=60 and Grade.LabExam>=60 + + select StuInfo.StuNO,StuName,Grade.WittenExam,LabExam from StuInfo + left join Grade on Grade.StuNo=StuInfo.StuNO + + select StuInfo.StuName,StuInfo.StuAge,Grade.WittenExam,Grade.LabExam from StuInfo + inner join Grade on StuInfo.StuNO=Grade.StuNo group by StuInfo.StuName,StuInfo.StuAge,Grade.WittenExam,Grade.LabExam + having StuInfo.StuAge >= 20 order by WittenExam desc + + select StuInfo.StuName,StuInfo.StuSex,avg(Grade.LabExam) as 机试平均分 from StuInfo + inner join Grade on StuInfo.StuNO=Grade.StuNo group by StuInfo.StuSex,Grade.LabExam,StuInfo.StuName + + select StuInfo.StuName,StuInfo.StuSex,sum(Grade.WittenExam) as 笔试总分 from StuInfo + inner join Grade on StuInfo.StuNO=Grade.StuNo group by StuInfo.StuName,StuInfo.StuSex,Grade.WittenExam + diff --git "a/20210326\344\275\234\344\270\232/12580/\344\275\234\344\270\2324.sql" "b/20210326\344\275\234\344\270\232/12580/\344\275\234\344\270\2324.sql" new file mode 100644 index 0000000..4949ce3 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/12580/\344\275\234\344\270\2324.sql" @@ -0,0 +1,110 @@ +use master +go +create database bbs +on +( name='bbs', + filename='D:\test\bbs.mdf', + size=10, + maxsize=100, + filegrowth=10% + ) + log on + ( name='bbs_log', + filename='D:\test\bbs_log.ldf', + size=10, + maxsize=100, + filegrowth=10% + ) + go + use bbs + go + create table bbsUsers +( + uID int identity(1,1) not null , + uName nvarchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null, + +) +alter table bbsUsers add constraint PK_bbsUsers_uID primary key(uID) +alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 or uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) +create table bbsSection +( + sID int identity(1,1) not null , + sName varchar(10) not null, + sUid int , + +) +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid)references bbsUsers(uID) + +create table bbsTopic +( + tID int primary key identity(1,1) not null, + tUID int references bbsUsers(uID) not null , + tSID int references bbsSection(sID) , + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime not null, + tCount int not null, +) +create table bbsReply +( + rID int primary key identity(1,1) not null, + rUID int references bbsUsers(uID) , + rTID int references bbsTopic(tID) , + rMsg text not null, + rTime datetime , + ) + select * from bbsReply +select * from bbsSection +select * from bbsTopic +select * from bbsUsers +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint_backup from bbsUsers +insert into bbsSection values('技术名流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑!','谁是范跑跑!', '2008-7-8',1),(3,2,'.NET!','与JAVA的区别是什么呀?','2008-9-1',2),(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10',0) +select * from bbsUsers + + delete from bbsTopic where tUID=2 + delete from bbsReply where rUID=2 + delete from bbsReply where rID=1 + delete from bbsUsers where uName='逍遥' + + alter table bbsSection drop NK + alter table bbsTopic drop FK__bbsTopic__tUID__1920BF5C + + update bbsUsers set uPoint ='10' where uName='小雨点' + delete bbsSection where sName='生活百科' + delete bbsReply + + select tID,count(tCount) from bbsTopic group by tID + select count(rID ) from bbsReply group by rID + select tUID ,count(tSID) from bbsTopic group by tUID + select tUID ,sum(tCount) from bbsTopic group by tUID + select tUID,avg(tCount) from bbsTopic group by tUID having avg(tCount)>3 + select top 1 uName,uSex,uAge,uPoint from bbsUsers + select*from bbsTopic where tTitle like '%快乐%' and tMsg like '%快乐%' + select*from bbsUsers where uAge>=15 and uAge<=20 and uPoint>10 + select*from bbsUsers where uName like'小_大' + select tUID ,tCount from bbsTopic where tTitle like '%!' + + select bbsUsers.uID ,bbsUsers.uName,sName from bbsSection +right join bbsUsers on bbsUsers.uID=bbsSection.sUid + +select tID ,bbsUsers.uName ,tTitle,tMsg ,tTime from bbsTopic +inner join bbsUsers on bbsTopic.tUID=bbsUsers.uID where tTime>'2008-09-15' + +select uID ,uName,bbsSection.sNamefrom bbsUsers from bbsTopic +left join bbsSection on uID=sUid where uAge<20 + +select top 1 tUID ,bbsUsers.uName ,tTitle ,tMsg , tCount from bbsTopic +inner join bbsUsers on uID=tUID order by tCount DESC + +select bbsSection.sName ,uID ,SUM(tID) from bbsTopic +right join bbsSection on sID=tSID +left join bbsUsers on uID=tUID group by bbsSection.sName,uID \ No newline at end of file -- Gitee From 79bdf9197eda98ca6cd80ca4beabaf9ad4df1737 Mon Sep 17 00:00:00 2001 From: PilRio <2535341085@qq.com> Date: Sun, 28 Mar 2021 11:01:04 +0800 Subject: [PATCH 037/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 71 +++++++++++ .../SQLQuery2.sql" | 88 +++++++++++++ .../SQLQuery3.sql" | 118 ++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" new file mode 100644 index 0000000..fb1fb67 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" @@ -0,0 +1,71 @@ +create database excise +on +( + name = 'excise', + filename = 'D:\excise.mdf' +) +log on +( + name = 'excise_log', + filename = 'D:\excise_log.ldf' +) +use excise + +create table Student +( + stuNo nvarchar(10) primary key, + stuName nvarchar(10)not null, + stuAge int not null, + stuAddress nvarchar(20) null, + stuSeat int not null, + stuSex nvarchar(1) not null +) +insert into Student(stuNo,stuName,stuAge,stuAddress,stuSeat,stuSex) values +('s2501','张秋利',20,'美国硅谷',1,'男'), +('s2502','李斯文',18,'湖北武汉',2,'女'), +('s2503','马文才',22,'湖南长沙',3,'男'), +('s2504','欧阳俊雄',21,'湖北武汉',4,'女'), +('s2505','梅超风',20,'湖北武汉',5,'男'), +('s2506','陈旋风',19,'美国硅谷',6,'男'), +('s2507','陈风',20,'美国硅谷',7,'女') + +select * from Student + +create table stuExam( + examNo int primary key identity (1,1), + stuNo nvarchar(10) constraint [Fk_Exam_stuNo] foreign key([stuNo]) references [Student]([stuNO]) not null, + writtenExam int not null, + labExam int not null +) +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) +select * from stuExam + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from Student s +left join stuExam e on s.stuNo = e.stuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select s.stuNo 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from Student s +left join stuExam e on s.stuNO=e.stuNo where writtenExam>60 and labExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select s.stuNo 学号,stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from Student s +left join stuExam e on s.stuNo = e.stuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from Student s +left join stuExam e on s.stuNo = e.stuNo where stuAge>=20 order by writtenExam desc + +--5.查询男女生的机试平均分 +select stuSex 性别,avg(labExam) 平均分 from stuExam e +left join Student s on e.stuNo = s.stuNo group by stuSex + +--6.查询男女生的笔试总分 +select stuSex 性别,sum(writtenExam) from stuExam e +left join Student s on e.stuNo = s.stuNo group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery2.sql" new file mode 100644 index 0000000..a5b94f3 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery2.sql" @@ -0,0 +1,88 @@ +create database shop +on +( + name = 'shop', + filename = 'D:\shop.mdf' +) +log on +( + name = 'shop_log', + filename = 'D:\shop_log.ldf' +) + +use shop + +create table orders +( + orderId int primary key identity(1,1), + orderDate datetime not null +) + +create table orderItem +( + ItemiD int identity(1,1) not null, + orderId int references orders(orderId) not null, + itemType nvarchar(10) not null, + itemName nvarchar(10) not null, + theNumber int not null, + theMoney int not null +) + +insert into orders 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 values +(1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'日常用品','透明胶',20,3), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书针',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'日常用品','毛巾',4,5), +(4,'日常用品','透明胶',30,3), +(4,'体育用品','羽毛球',20,3) +select * from orderItem + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select o.orderId 订单编号,orderDate 订单日期, itemType 类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价 from orders o +left join orderItem oi on o.orderId = oi.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select o.orderId 订单编号,theNumber 订购数量,orderDate 订单日期,itemType 类别,itemName 产品名称 from orders o +left join orderItem oi on o.orderId = oi.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o.orderId 订单编号,orderDate 订单日期,itemType 类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价 from orders o +left join orderItem oi on o.orderId = oi.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o.orderId 订单的编号,orderDate 订单日期,itemType 类别,itemName 产品名称,theNumber 订购数量,theNumber*theMoney 订购总价 from orders o +left join orderItem oi on o.orderId = oi.orderId where theMoney>5 and theNumber>= 50 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select o.orderId 编号 ,sum(theNumber) 订购产品数 from orders o +left join orderItem oi on o.orderId = oi.orderId group by o.orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +-- 订单编号 产品类别 订购次数 总数量 +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select o.orderId 订单编号, itemType 产品类别, count(itemType) 订购次数,sum(theNumber)总数量 from orders o +left join orderItem oi on o.orderId=oi.orderId group by o.orderId,itemType \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery3.sql" new file mode 100644 index 0000000..44a60f9 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery3.sql" @@ -0,0 +1,118 @@ +create database bbs +on +( + name = 'bbs', + filename = 'D:\bbs.mdf' +) + +log on +( + name = 'bbs_log', + filename = 'D:\bbs_log.ldf' +) +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) + +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) + +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) + +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('男','女')) + +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) + +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) + + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) + +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values +('小雨点','女',20,0), +('逍遥','男',18,4), +('七年级生','男',19,2) + + +select * into bbsPoint from bbsUsers + +insert into bbsSection values +('技术交流',1), +('读书世界',3), +('生活百科',1), +('八卦区',3) + +insert into bbsTopic values +(2,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0), +(3,1,'.NET','与JAVA的区别是什么呀?',2008-9-1,2), +(1,3,'范跑跑','谁是范跑跑',2008-7-8,1) + +insert into bbsReply values +(2,1,'不知道',2008-9-10), +(3,2,'不知道',2008-9-1), +(1,3,'不知道',2008-7-8) + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection +left join bbsUsers on bbsSection.sUid = bbsUsers.UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTItle 帖子的标题,tMsg 帖子的内容,tTime 发帖时间 from bbsTopic +left join bbsUsers on bbsTopic.tUID= bbsUsers.UID where tTime>'2008-9-15 00:00:00' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称, uAge 年龄 from bbsPoint +left join bbsSection on bbsPoint.UID=bbsSection.sUid where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tUID 发帖人编号,uName 发帖人姓名,tTItle 主贴标题,tMsg 主贴内容,uPoint 回复数量 from bbsTopic +left join bbsUsers on bbsTopic.tUID= bbsUsers.UID order by uPoint desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName 版块, uName 用户,count(tTItle) 发帖总数 from bbsTopic +left join bbsSection on bbsTopic.tUID= bbsSection.sUid +left join bbsUsers on bbsTopic.tUID= bbsUsers.UID +group by sName , uName + -- Gitee From 027bac375840c42534a892b62741a469c9ac43ae Mon Sep 17 00:00:00 2001 From: adios <1347358158@qq.com> Date: Sun, 28 Mar 2021 13:13:43 +0800 Subject: [PATCH 038/195] =?UTF-8?q?=E6=A2=81=E4=B8=96=E8=B4=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5.sql" | 167 ++++++++++++++++++ .../SQLQuery8.sql" | 91 ++++++++++ .../SQLQuery9.sql" | 104 +++++++++++ 3 files changed, 362 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery5.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery8.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery9.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery5.sql" "b/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery5.sql" new file mode 100644 index 0000000..1d43fae --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery5.sql" @@ -0,0 +1,167 @@ +use master +go +create database bbs +on primary +( +name='bbs', +filename='D:\SQL作业.mdf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +log on +( +name='bbs_log', +filename='D:\SQL作业_log.ldf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +go + +use bbs + +--用户信息表(bbsUsers) +--用户编号 useID int 主键 标识列 +--用户名 uName varchar(10) 唯一约束 不能为空 +--性别 uSex varchar(2) 不能为空 只能是男或女 +--年龄 uAge int 不能为空 范围15-60 +--积分 uPoint int 不能为空 范围 >= 0 + + create table bbsUsers --建立用户信息表 + ( + useID int primary key, + uName varchar(10) unique not null, + uSex varchar(2) check(uSex='男'or uSex='女') not null, + uAge int check(uAge between 15 and 60) not null, + uPoint int check(uPoint>=0) not null + ) + go + + + + --版块表(bbsSection) +--版块编号 sID int 标识列 主键 +--版块名称 sName varchar(10) 不能为空 +--版主编号 sUid int 外键 引用用户信息表的用户编号 + +create table bbsSection --建立板块表 +( +sID int primary key, +sName varchar(10) not null, +sUid int foreign key(sUid)references bbsUsers(useID) +) +go + + +--主贴表(bbsTopic) +--主贴编号 tID int 主键 标识列, +--发帖人编号 tUID int 外键 引用用户信息表的用户编号 +--版块编号 tSID int 外键 引用版块表的版块编号 (标明该贴子属于哪个版块) +--贴子的标题 tTitle varchar(100) 不能为空 +--帖子的内容 tMsg text 不能为空 +--发帖时间 tTime datetime +--回复数量 tCount int + +create table bbsTopic --建立主贴表 +( +tID int primary key, +tUID int foreign key(tUID) references bbsUsers(useID), +tSID int foreign key(tSID) references bbsSection(sID), +tTitle varchar(100) not null, +tMsg text not null, +tTime datetime, +tCount int +) +go + + +--回帖表(bbsReply) +--回贴编号 rID int 主键 标识列, +--回帖人编号 rUID int 外键 引用用户信息表的用户编号 +--对应主贴编号 rTID int 外键 引用主贴表的主贴编号 (标明该贴子属于哪个主贴) +--回帖的内容 rMsg text 不能为空 +--回帖时间 rTime datetime + +create table bbsReply --建立回贴表 +( +rID int identity primary key, +rUID int foreign key(rUID) references bbsUsers(useID), +rTID int foreign key(rTID) references bbsTopic(tID), +rMsg text not null, +rTime datetime +) +go + +--.现在有3个会员注册成功,请用一次插入多行数据的方法向bbsUsers表种插入3行记录,记录值如下: +--小雨点 女 20 0 +--逍遥 男 18 4 +--七年级生 男 19 2 + +select * from bbsUsers +insert bbsUsers values(1,'小雨点','女',20,0),(2,'逍遥','男',18,4),(3,'七年级生','男',19,2) + +--.将bbsUsers表中的用户名和积分两列备份到新表bbsPoint表中,提示查询部分列:select 列名1,列名2 from 表名 + --插入多行: + --先创建好空表,然后再插入数据, + --直接插入数据,然后自动生成表。 + --insert into bbsPoint select ,uPoint from bbsUsers + --select uName,uPoint into bbsPoint from bbsUsers + + select uName,uPoint into bbsPoint from bbsUsers + + --给论坛开设4个板块 + --名称 版主名 + --技术交流 小雨点 + --读书世界 七年级生 + --生活百科 小雨点 + --八卦区 七年级生 + +insert bbsSection values(1,'技术交流',1),(2,'读书世界',2),(3,'生活百科',3),(4,'八卦区',3) + +--向主贴和回帖表中添加几条记录 + --主贴: + --发帖人 板块名 帖子标题 帖子内容 发帖时间 回复数量 + --逍遥 八卦区 范跑跑 谁是范跑跑 2008-7-8 1 + --七年级生 技术交流 .NET 与JAVA的区别是什么呀? 2008-9-1 2 + --小雨点 生活百科 今年夏天最流行什么 有谁知道今年夏天最流行什么呀? 2008-9-10 0 + +insert into bbsTopic(tID,tTitle,tMsg,tTime,tCount) +select 1,'范跑跑','谁是范跑跑','2008-7-8',1 union +select 2,'.NET','与JAVA的区别是什么呀?','2008-9-1',2 union +select 3,'今年夏天最流行什么呀?','有谁知道今年夏天最流行什么呀?','2008-9-10',0 + +--回帖: + --分别给上面三个主贴添加对应的回帖,回帖的内容,时间,回帖人自定 + +insert into bbsReply(rMsg,rTime) +select '我是范跑跑','2008-7-10' union +select '没区别','2008-9-2' union +select '最流行冰激凌','2008-9-10' + + + +select * from bbsUsers +select * from bbsTopic +select * from bbsSection +select * from bbsReply + +--1.查询出每个版块的版主编号,版主姓名和版块名称 + +select s1.useID 版主编号,uName 版主姓名,sName 板块名称 from bbsUsers s1 inner join bbsSection s2 on s1.useID=s2.sUid + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 + +select useID 发帖人编号,uName 发帖人姓名,tTitle 帖子的标题,tMsg 帖子的内容,tTime 发帖时间 from bbsUsers s1 inner join bbsTopic s2 on s1.useID=s2.tID where tTime>'2008-9-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 + +select useID 版主编号,uName 版主姓名,sName 板块名称 from bbsUsers s1 inner join bbsSection s2 on s1.useID=s2.sUid where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 + +select useID,uName,tTitle,tMsg,tCount from bbsUsers s1 inner join bbsTopic s2 on s1.useID=s2.tID group by useID,uName,tTitle,tMsg,tCount having tCount=max(tCount) + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select useID,sum() from bbsTopic s1 inner join bbsUsers s2 on s1.tID=s2.useID \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery8.sql" "b/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery8.sql" new file mode 100644 index 0000000..4e294a3 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery8.sql" @@ -0,0 +1,91 @@ +use master +go + +create database Student +on +( + FileName='D:\SQL作业1.mdf', + Name='Student', + size=5MB, + maxsize=5MB, + filegrowth=3MB +) +log on +( + FileName='D:\SQL作业1_log.ldf', + Name='Student_log', + size=5MB, + maxsize=5MB, + filegrowth=3MB +) +go + +use Student + +go + +create table Student +( + StuNo varchar(10) primary key not null, + StuName nvarchar(10) not null, + StuAge int, + StuAddress nvarchar(20), + StuSeat int, + StuSex int check(StuSex=1 or StuSex=0) not null +) + +create table Score +( + ExamNo int primary key identity(1,1) not null, + StuNo varchar(10) not null, + WrittenExam int default(0) not null, + LabExam int not null +) + + +insert into Student values +('s2501','张秋利',20,'美国硅谷',1,1), +('s2502','李斯文',18,'湖北武汉',2,0), +('s2503','马文才',22,'湖南长沙',3,1), +('s2504','欧阳俊雄',21,'湖北武汉',4,0), +('s2505','梅超风',20,'湖北武汉',5,1), +('s2506','陈旋风',19,'美国硅谷',6,1), +('s2507','陈风',20,'美国硅谷',7,0) + +select * from Student + + +insert into Score values +('s2501',50,70), +('s2502',60,65), +('s2503',86,85), +('s2504',40,80), +('s2505',70,90), +('s2506',85,90) + +alter table Score add constraint FK_Score_StuNo foreign key(StuNo) references Student(StuNo) + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 + +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from Student s1 inner join Score s2 on s1.StuNo=s2.StuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 + +select s1.StuNo 学号,StuName 姓名,WrittenExam 笔试成绩,LabExam 机试成绩 from Student s1 inner join Score s2 on s1.StuNo=s2.StuNo where WrittenExam>60 and LabExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 + +select s1.StuNo 学号,StuName 姓名,WrittenExam 笔试成绩,LabExam 机试成绩 from Student s1 left join Score s2 on s1.StuNo=s2.StuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 + +select StuName,StuAge,WrittenExam,LabExam from Student s1 inner join Score s2 on s1.StuNo=s2.StuNo order by WrittenExam desc + +--5.查询男女生的机试平均分 + +select StuSex 男女,avg(LabExam) 平均分 from Student s1 inner join Score s2 on s1.StuNo=s2.StuNo group by StuSex having StuSex=1 or StuSex=0 + +--6.查询男女生的笔试总分 + +select StuSex 男女,sum(WrittenExam) 总分 from Student s1 inner join Score s2 on s1.StuNo=s2.StuNo group by StuSex having StuSex=1 or StuSex=0 \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery9.sql" "b/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery9.sql" new file mode 100644 index 0000000..59f62b8 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery9.sql" @@ -0,0 +1,104 @@ +use master + +go + +create database DD --建立数据库 +on primary +( +name='D:\SQL作业3', +filename='D:\SQL作业3.mdf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +log on +( +name='D:\SQL作业3_log', +filename='D:\SQL作业3_log.ldf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +go + +use DD +create table orders --建立订单表 +( +orderId int primary key, +orderDate datetime +) +go + +create table orderltem +( +ltemiD int primary key, +orderId int, +itemType varchar(15), +itemName varchar(20), +theNumber int, +theMoney int +) +go + +insert orders(orderId,orderDate) +select 1,'2008-01-12 00:00:00.000' union +select 2,'2008-02-10 00:00:00.000' union +select 3,'2008-02-15 00:00:00.000' union +select 4,'2008-03-10 00:00:00.000' + +select * from orders + +insert into orderltem(ltemiD,orderId,itemType,itemName,theNumber,theMoney) +select 1,1,'文具','笔',72,2 union +select 2,1,'文具','尺',10,1 union +select 3,1,'体育用品','篮球',1,56 union +select 4,2,'文具','笔',36,2 union +select 5,2,'文具','固体胶',20,3 union +select 6,2,'日常用品','透明胶',2,1 union +select 7,2,'体育用品','羽毛球',20,3 union +select 8,3,'文具','订书机',20,3 union +select 9,3,'文具','丁书针',10,3 union +select 10,3,'文具','裁纸刀',5,5 union +select 11,4,'文具','笔',20,2 union +select 12,4,'文具','信纸',50,1 union +select 13,4,'日常用品','毛巾',4,5 union +select 14,4,'日常用品','透明胶',30,1 union +select 15,5,'体育用品','羽毛球',20,3 + +select * from orderltem + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select s1.orderId 订单编号,orderDate 订单日期,itemType 产品类型,itemName 产品名称,theNumber 订购数量,theMoney 订购单价 from orders s1 inner join orderltem s2 on s1.orderId=s2.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 + +select s1.orderId 订单编号,orderDate 订单日期,itemType 产品类型,itemName 产品名称 from orders s1 inner join orderltem s2 on s1.orderId=s2.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select s1.orderId 订单编号,orderDate 订单日期,itemType 产品类型,itemName 产品名称,theNumber 订单数量,theMoney 订单单价,sum(theNumber* theMoney) 总价 from orders s1 inner join orderltem s2 on s1.orderId=s2.orderId group by s1.orderId,orderDate,itemType,itemName,theNumber,theMoney + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select s1.orderId 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订单数量,theMoney 订单单价,sum(theNumber*theMoney) 总价 from orders s1 inner join orderltem s2 on s1.orderId=s2.orderId group by s1.orderId,orderDate,itemType,itemName,theNumber,theMoney having theMoney>=5 and theNumber>=50 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 + +select s1.orderId,sum(theNumber) 订购总数 from orderltem s1 inner join orders s2 on s1.orderId=s2.orderId group by s1.orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +select s1.orderId 订单编号,itemName 产品类别,count(itemType) 订购次数,sum(theNumber) 订购总数量 from orders s1 inner join orderltem s2 on s1.orderId=s2.orderId group by s1.orderId,itemName order by s1.orderId + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 \ No newline at end of file -- Gitee From 28952778854b0bb2dec53b3f20547418fe2e1a0b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 28 Mar 2021 13:14:47 +0800 Subject: [PATCH 039/195] 0326 --- .../\344\275\234\344\270\232\344\270\200.sql" | 101 +++++++++++++++ .../\344\275\234\344\270\232\344\270\211.sql" | 117 ++++++++++++++++++ .../\344\275\234\344\270\232\344\272\214.sql" | 92 ++++++++++++++ 3 files changed, 310 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\270\200.sql" create mode 100644 "20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\270\211.sql" create mode 100644 "20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\272\214.sql" diff --git "a/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\270\200.sql" "b/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\270\200.sql" new file mode 100644 index 0000000..edb6350 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\270\200.sql" @@ -0,0 +1,101 @@ +create database Studentinfo + +on +( + name='Studentinfo', + filename='D:\Studentinfo.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='Studentinfo_log', + filename='D:\Studentinfo_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +use Studentinfo +go +create table StuDent +( + sTUNO varchar(15), + stuName nvarchar(20), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') +) + +insert into StuDent(sTUNO,stuName,stuAge,stuAddress,stuSeat,stuSex) +select 's2501','张秋里',20,'美国硅谷',1,'男' union +select 's2502','李斯文',18,'湖北武汉',2,'女' union +select 's2503','马文才',22,'湖南长沙',3,'男' union +select 's2504','欧阳俊雄',21,'湖北武汉',4,'女' union +select 's2505','梅超风',20,'湖北武汉',5,'男' union +select 's2506','陈旋风',19,'美国硅谷',6,'男' union +select 's2507','陈风',20,'美国硅谷',7,'女' + + +create table Score +( + examNO int, + stuNO varchar(15), + writtenExam varchar(200), + labExam varchar(200) +) + +insert into Score(examNO,stuNO,writtenExam,labExam) +select 1,'s2501','50','70' union +select 2,'s2501','60','65' union +select 3,'s2501','86','85' union +select 4,'s2501','40','80' union +select 5,'s2501','70','90' union +select 6,'s2501','85','90' + +create table stuExam +(examNo int, + stuNo varchar(15), + writtenExam int, + labExam int +) +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) + + +select * from stuExam +select * from StuDent +select * from Score + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名, stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from StuDent s +left join stuExam e on s.stuNo = e.stuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuName 姓名, stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from StuDent s +left join stuExam e on s.stuNo = e.stuNo where writtenExam>60 and labExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuName 姓名, s.stuNo 学号,writtenExam 笔试成绩,labExam 机试成绩 from StuDent s +left join stuExam e on s.stuNo = e.stuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from StuDent s +left join stuExam e on s.stuNo = e.stuNo where stuAge>=20 order by writtenExam desc + +--5.查询男女生的机试平均分 +select stuSex,AVG(labExam)平均分 from stuExam e +left join StuDent s on e.stuNo= s.stuNo group by stuSex + +--6.查询男女生的笔试总分 +select stuSex, SUM(writtenExam) 笔试总分 from stuExam e +left join StuDent s on e.stuNo= s.stuNo group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\270\211.sql" "b/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\270\211.sql" new file mode 100644 index 0000000..8c1e96a --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\270\211.sql" @@ -0,0 +1,117 @@ +create database bbs +on +( + name = 'bbs', + filename = 'D:\bbs.mdf' +) + +log on +( + name = 'bbs_log', + filename = 'D:\bbs_log.ldf' +) +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) + +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) + +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) + +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('男','女')) + +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) + +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) + + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) + +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values +('小雨点','女',20,0), +('逍遥','男',18,4), +('七年级生','男',19,2) + + +select * into bbsPoint from bbsUsers + +insert into bbsSection values +('技术交流',1), +('读书世界',3), +('生活百科',1), +('八卦区',3) + +insert into bbsTopic values +(2,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0), +(3,1,'.NET','与JAVA的区别是什么呀?',2008-9-1,2), +(1,3,'范跑跑','谁是范跑跑',2008-7-8,1) + +insert into bbsReply values +(2,1,'不知道',2008-9-10), +(3,2,'不知道',2008-9-1), +(1,3,'不知道',2008-7-8) + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection +left join bbsUsers on bbsSection.sUid = bbsUsers.UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTItle 帖子的标题,tMsg 帖子的内容,tTime 发帖时间 from bbsTopic +left join bbsUsers on bbsTopic.tUID= bbsUsers.UID where tTime>'2008-9-15 00:00:00' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称, uAge 年龄 from bbsPoint +left join bbsSection on bbsPoint.UID=bbsSection.sUid where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tUID 发帖人编号,uName 发帖人姓名,tTItle 主贴标题,tMsg 主贴内容,uPoint 回复数量 from bbsTopic +left join bbsUsers on bbsTopic.tUID= bbsUsers.UID order by uPoint desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName 版块, uName 用户,count(tTItle) 发帖总数 from bbsTopic +left join bbsSection on bbsTopic.tUID= bbsSection.sUid +left join bbsUsers on bbsTopic.tUID= bbsUsers.UID +group by sName , uName diff --git "a/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\272\214.sql" "b/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\272\214.sql" new file mode 100644 index 0000000..d6d1625 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\350\203\241\350\266\212/\344\275\234\344\270\232\344\272\214.sql" @@ -0,0 +1,92 @@ +create database shop on( + name='shop', + filename='D:\shop.mdf' +) +log on( + name='shop_log', + filename='D:\shop.ldf' +) + +use shop +go + +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) +create table orders( + orderId int primary key identity(1,1), + orderDate datetime default(getdate()) +) + +--订购项目表(orderItem),列为: +create table orderItem( +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) + ItemiD int identity(1,1), + orderId int references orders(orderId), + itemType nvarchar(20), +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) + itemName nvarchar(20), + theNumber int, + theMoney int +) + +insert into orders(orderDate) values +('2008-01-12 00:00:00'), +('2008-02-10 00:00:00'), +('2008-02-15 00:00:00'), +('2008-03-10 00:00:00') +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), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书针',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'日常用品','毛巾',4,5), +(4,'日常用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) +select * from orderItem +select * from orders +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select I.orderId 订单编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购产品的产品名称,theNumber 订购数量 ,theMoney 订购单价 from orderItem I +left join orders d on I.orderId = d.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select I.orderId 订单编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购产品的产品名称 from orderItem I +left join orders d on I.orderId = d.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select I.orderId 订单编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购产品的产品名称,theNumber 订购数量 ,theMoney 订购单价,theNumber*theMoney 订单总价 from orderItem I +left join orders d on I.orderId = d.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select I.orderId 订单编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购产品的产品名称,theNumber 订购数量 ,theMoney 订购单价,theNumber*theMoney 订单总价 from orderItem I +left join orders d on I.orderId = d.orderId where theMoney>=5 and theNumber>=50 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select I.orderId 订单编号,SUM(theNumber) 订购数量 from orderItem I group by I.orderId + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select I.orderId 订单编号,itemType 产品类别,count(theNumber)订购次数,SUM(theNumber) 总数量 from orderItem I +left join orders d on I.orderId = d.orderId group by itemType,I.orderId \ No newline at end of file -- Gitee From 0ac50ff60095b3aeb66895525edfbb99b767c176 Mon Sep 17 00:00:00 2001 From: weilijiang <3055679233@qq.com> Date: Sun, 28 Mar 2021 14:55:13 +0800 Subject: [PATCH 040/195] 03.28 sql --- .../SQL1.sql" | 98 ++++++++++++++ .../SQL2.sql" | 104 +++++++++++++++ .../SQL\344\275\234\344\270\2323.sql" | 120 ++++++++++++++++++ 3 files changed, 322 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL\344\275\234\344\270\2323.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL1.sql" "b/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL1.sql" new file mode 100644 index 0000000..f377f01 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL1.sql" @@ -0,0 +1,98 @@ +use master +go +create database STU +on +( +name='STU', +filename='D:\sql\STU.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='STU_log', +filename='D:\sql\STU_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use STU +go +create table StuInfo +( +StuNO nvarchar(10) unique not null, +StuName nvarchar(10) not null, +StuAge int not null, +StuAddress nvarchar(200) , +StuSeat nvarchar(8) not null, +StuSex nvarchar(1) default('男') check(StuSex='男' or StuSex='女') +) + +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','张秋利','20','美国硅谷','1','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','李斯文','18','湖北武汉','2','男') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','马文才','22','湖南长沙','3','男') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','欧阳俊雄','21','湖北武汉','4','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','梅超风','20','湖北武汉','5','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','陈旋风','19','美国硅谷','6','女') +insert into StuInfo(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','陈风','20','美国硅谷','7','女') + +create table Chengji +( +ExamNo int primary key identity(1,1), +StuNo nvarchar(10) references StuInfo(StuNO), +WittenExam int not null, +LabExam int not null +) +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2501','50','70') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2502','60','65') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2503','86','85') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2504','40','80') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2505','70','90') +insert into Chengji(StuNO,WittenExam,LabExam) +values('s2506','85','90') + + +--练习1 +--数据如图片1,使用上次作业的数据 +select * from StuInfo +select * from Chengji +--1.查询学生的姓名(StuName),年龄(StuAge),笔试成绩(WittenExam)和机试成绩(LabExam) +select StuInfo.StuNO,StuInfo.StuName 姓名,StuInfo.StuAge 年龄,Chengji.WittenExam 笔试成绩,Chengji.LabExam 机试成绩 +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号(StuNO),姓名(StuName),笔试成绩(WittenExam)和机试成绩(LabExam) +select StuInfo.StuNO 学号,StuInfo.StuName 姓名,Chengji.WittenExam 笔试成绩,Chengji.LabExam 机试成绩 +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo +where Chengji.WittenExam>60 and Chengji.LabExam>60 + +--3.查询所有学生的学号(StuNO),姓名(StuName),笔试成绩(WittenExam),机试成绩(LabExam),没有参加考试的学生的成绩以NULL值填充 +select StuInfo.StuNO 学号,StuInfo.StuName 姓名,Chengji.WittenExam 笔试成绩,Chengji.LabExam 机试成绩 +from StuInfo left join Chengji on StuInfo.StuNO=Chengji.StuNo + +--4.查询年龄(StuAge)在20以上(包括20)的学生的姓名(StuName),年龄(StuAge),笔试成绩(WittenExam)和机试成绩(LabExam),并按笔试成绩降序排列 +select StuInfo.StuNO 学号,StuInfo.StuName 姓名,StuInfo.StuAge 年龄,Chengji.WittenExam 笔试成绩,Chengji.LabExam 机试成绩 +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo +where StuInfo.StuAge>=20 order by WittenExam DESC + +--5.查询 男女生的 机试(LabExam)平均分 +select StuInfo.StuSex 性别, avg(LabExam) 平均分 +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo +group by StuSex +--6.查询男女生的笔试(WittenExam)总分 +select StuInfo.StuSex 性别, sum(WittenExam) 总分 +from StuInfo inner join Chengji on StuInfo.StuNO=Chengji.StuNo +group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL2.sql" "b/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL2.sql" new file mode 100644 index 0000000..46a6d2b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL2.sql" @@ -0,0 +1,104 @@ +use master +go +create database ORD +on +( +name='ORD', +filename='D:\sql\ORD.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='ORD_log', +filename='D:\sql\ORD_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use ORD +go +create table Orders +( +OrderID int primary key not null, +OrderDate datetime +) +go +use ORD +go +create table Orderltem +( +ItemID int primary key not null, +OrderID int references Orders(OrderID) not null, +ItemType varchar(8) not null, +ItemName varchar(6) not null, +TheNumber int not null, +TheMoney int not null +) +go +insert into Orders (OrderID,OrderDate) values(1,'2008-01-12') +insert into Orders (OrderID,OrderDate) values(2,'2008-02-10') +insert into Orders (OrderID,OrderDate) values(3,'2008-02-15') +insert into Orders (OrderID,OrderDate) values(4,'2008-03-10') + +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(1,1,'文具','笔','72','2') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(2,1,'文具','尺','10','1') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(3,1,'体育用具','篮球','1','56') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(4,2,'文具','笔','36','2') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(5,2,'文具','固体胶','20','3') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(6,2,'日常用品','透明胶','2','1') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(7,2,'体育用品','羽毛球','20','3') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(8,3,'文具','订书机','20','3') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(9,3,'文具','订书机','10','3') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(10,3,'文具','裁纸刀','5','5') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(11,4,'文具','笔','20','2') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(12,4,'文具','信纸','50','1' ) +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(13,4,'日常用品','毛巾','4','5') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(14,4,'日常用品','透明胶','30','1') +insert into Orderltem (ItemID,OrderID,ItemType,ItemName,TheNumber,TheMoney) values(15,4,'体育用品','羽毛球','20','3') + + +--练习2 +--使用上次作业的订单数据库,完成下列题目: +select * from Orders +select * from Orderltem +--1.查询所有的订单的订单的编号(OrderID),订单日期(OrderDate),订购产品的类别(ItemType)和订购的产品名称(ItemName),订购数量(TheNumber)和订购单价(TheMoney) +select Orders.OrderID 编号,Orders.OrderDate 日期,Orderltem.ItemType 类别,Orderltem.ItemName 名称,Orderltem.TheNumber 数量,Orderltem.TheMoney 单价 +from Orders inner join Orderltem on Orders.OrderID=Orderltem.OrderID + +--2.查询订购数量(TheNumber)大于50的订单的编号(OrderID),订单日期(OrderDate),订购产品的类别(ItemType)和订购的产品名称(ItemName) +select Orders.OrderID 编号,Orders.OrderDate 日期,Orderltem.ItemType 类别,Orderltem.ItemName 名称,Orderltem.TheNumber 数量 +from Orders inner join Orderltem on Orders.OrderID=Orderltem.OrderID +where Orderltem.TheNumber>50 + +--3.查询所有的订单的订单的编号(OrderID),订单日期(OrderDate),订购产品的类别(ItemType)和订购的产品名称(ItemName),订购数量(TheNumber)和订购单价(TheMoney)以及订购总价 +select Orders.OrderID 订单的编号,Orders.OrderDate 订单日期,Orderltem.ItemType 产品的类别,Orderltem.ItemName 产品名称,Orderltem.TheNumber 订购数量,Orderltem.TheMoney 订购单价, sum(Orderltem.TheNumber*Orderltem.TheMoney) 订购总价 +from Orders inner join Orderltem on Orders.OrderID=Orderltem.OrderID +group by Orders.OrderID,OrderDate,ItemType,ItemName,TheNumber,TheMoney + +--4.查询单价(TheMoney)大于等于5 并且 数量(TheNumber)大于等于50的订单 的订单的编号(OrderID),订单日期(OrderDate),订购产品的类别(ItemType)和订购的产品名称(ItemName),订购数量(TheNumber)和订购单价(TheMoney)以及订购总价 +select Orders.OrderID 订单编号,Orders.OrderDate 订单日期,Orderltem.ItemType 类别,Orderltem.ItemName 产品名称,Orderltem.TheNumber 订购数量,Orderltem.TheMoney 订购单价, sum(Orderltem.TheNumber*Orderltem.TheMoney) 总价 +from Orders inner join Orderltem on Orders.OrderID=Orderltem.OrderID +where Orderltem.TheMoney>=5 and Orderltem.TheNumber>=50 +group by Orders.OrderID,OrderDate,ItemType,ItemName,TheNumber,TheMoney + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号(OrderID) 订购产品数 +-- 1 3 +-- 2 4 +select Orders.OrderID 编号,count(*)订购产品数 +from Orderltem inner join Orders on Orders.OrderID=Orderltem.OrderID +group by Orders.OrderID + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +-- 订单编号(OrderID) 产品类别(ItemType) 订购次数 总数量 +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select Orders.OrderID 编号,Orderltem.ItemType 类别,count(*)订购次数,sum(TheNumber) 总数量 +from Orderltem inner join Orders on Orders.OrderID=Orderltem.OrderID +group by Orders.OrderID,ItemType diff --git "a/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL\344\275\234\344\270\2323.sql" "b/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL\344\275\234\344\270\2323.sql" new file mode 100644 index 0000000..c73660c --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL\344\275\234\344\270\2323.sql" @@ -0,0 +1,120 @@ +use master +go +create database BBS +on +( +name='BBS', +filename='D:\sql\BBS.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='BBS_log', +filename='D:\sql\BBS_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use BBS +go +create table BBSUsers--用户信息表 +( +UID int not null, +UName varchar(10) not null, +USex varchar(2) not null, +UAge int not null, +UPoint int not null +) + +alter table BBSUsers add constraint PK_BBSUsers_UID primary key(UID) +alter table BBSUsers add constraint UK_BBSUsers_UName unique(UName) +alter table BBSUsers add constraint CK_BBSUsers_USex check(USex='男' or USex='女') +alter table BBSUsers add constraint CK_BBSUsers_UAge check(UAge>=15 and UAge<=60) +alter table BBSUsers add constraint CK_BBSUsers_UPoint check(UPoint>=0) + +go +use BBS +go +create table BBSSection--版块表 +( +SID int not null, +SName varchar(10) not null, +SUID int not null +) +alter table BBSSection add constraint PK_BBSSection_SID primary key(SID) +alter table BBSSection add constraint FK_BBSSection_SUID foreign key (SUID) references BBSUsers(UID) + +go +use BBS +go +create table BBSTopic--主贴表 +( +TID int primary key identity(1,1) not null, +TUID int references BBSUsers(UID) not null, +TSID int references BBSSection(SID) not null, +TTitle varchar(100) not null, +TMsg text not null, +TTime datetime , +Tcount int , +) + +go +use BBS +go +create table BBSReply--回帖表 +( +RID int primary key identity(1,1) not null, +RUID int references BBSUsers(UID) not null, +RTID int references BBSTopic(TID) not null, +RMsg text , +RTime datetime , +) +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(1,'小雨点','女','20','0') +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(2,'逍遥','男','18','4') +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(3,'七年级生','男','19','2') + +select UName,UPoint into BBSPoint from BBSUsers + +insert into BBSSection (SID,SName,SUID) values(4,'技术交流',1) +insert into BBSSection (SID,SName,SUID) values(5,'读书世界',3) +insert into BBSSection (SID,SName,SUID) values(6,'生活八卦',1) +insert into BBSSection (SID,SName,SUID) values(7,'八卦区',3) + +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(2,7,'范跑跑','谁是范跑跑','2008-7-8',1) +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(3,4,'.NET','与JAVA的区别是什么','2008-9-1',2) +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(1,6,'今年夏天最流行什么','有谁知道今年夏天最流行什么','2008-9-10',0) + +insert into BBSReply (RUID,RMsg,RTime,RTID) values(1,'范跑跑是什么人','2008-10-1',1) +insert into BBSReply (RUID,RMsg,RTime,RTID) values(2,'它们的区别是什么','2008-11-1',2) +insert into BBSReply (RUID,RMsg,RTime,RTID) values(3,'最流行什么','2008-11-20',3) + + +--练习3 +select * from BBsReply --回帖表 +select * from BBsSection --版块表 +select * from BBsTopic --主帖表 +select * from BBsUsers --用户信息表 + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select SID 版主编号,UName 版主姓名,SName 版块名称 FROM BBsSection +left join BBsUsers on SID=UID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +SELECT TUID 发帖人编号,UName 发帖人姓名,TTitle 帖子的标题,TMsg 帖子的内容,TTime 发帖时间 from BBsTopic +left join BBsUsers ON UID=TID where TTime>'2008-9-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select SID 版主的编号,UName 版主的名称,SName 版块的名称,UAge 年龄 from BBsSection +left join BBsUsers on SID=UID where UName<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 TUID 编号,UName 发帖人姓名,TTitle 主贴标题,TMsg 主贴内容, +Tcount 回复数量 from BBsTopic left join BBsUsers on UID = TID ORDER BY Tcount desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select UName 用户名, SName 板块名, count(*) 发帖总数 from BBsTopic +inner join BBsUsers ON TUID=UID +LEFT JOIN BBsSection ON TID = SID GROUP BY UName,SName -- Gitee From b7677881d433c1f5ee0b4e7061f2e66591823fdf Mon Sep 17 00:00:00 2001 From: hzt1993 <248875989@qq.com> Date: Sun, 28 Mar 2021 16:36:46 +0800 Subject: [PATCH 041/195] first commit --- .../SQLQuery1.sql" | 59 ++++++++++ .../SQLQuery2.sql" | 67 +++++++++++ .../SQLQuery3.sql" | 106 ++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" new file mode 100644 index 0000000..ea5bb0e --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" @@ -0,0 +1,59 @@ +create database Student +go +use Student +go + +select * from stuclass +select * from examclass +create table stuclass +( + stuNO varchar(10) primary key , + stuName varchar(10), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex int, +) +select * from stuclass +insert into stuclass values ('s2501','张秋利',20,'美国硅谷',1,1),('s2502','李斯文',18,'湖北武汉',2,0),('s2503','马文才',22,'湖南长沙',3,1), +('s2504','欧阳俊雄',21,'湖北武汉',4,0),('s2505','梅超风',20,'湖北武汉',5,1),('s2506','陈旋风',19,'美国硅谷',6,1),('s2507','陈风',20,'美国硅谷',7,0) + + + +create table examclass +( + examNo int primary key identity(1,1), + stuNo varchar(10) references stuclass(stuNO), + writtenExam int , + labExam int , +) +select * FROM DBO.stuclass +select * from examclass inner join stuclass on examclass.stuNo = stuclass.stuNO +insert into examclass values ('s2501',50,70),('s2502',60,65),('s2503',86,85),('s2504',40,80), +('s2505',70,90),('s2506',85,90) + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +--内连接 +select stuclass.stuName 姓名, stuclass.stuAge 年龄,examclass.writtenExam 笔试成绩,examclass.labExam 机试成绩 from stuclass +inner join examclass on stuclass.stuNO = examclass.stuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuclass.stuNO 学号 ,stuclass.stuName 姓名, stuclass.stuAge 年龄, examclass.writtenExam 笔试成绩, examclass.labExam 机试成绩 from examclass +inner join stuclass on stuclass.stuNO = examclass.stuNo where writtenExam>60 and labExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuclass.stuNO 学号 ,stuclass.stuName 姓名, stuclass.stuAge 年龄, examclass.writtenExam 笔试成绩, examclass.labExam 机试成绩 from examclass +right join stuclass on stuclass.stuNO = examclass.stuNo + + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuclass.stuName 姓名, stuclass.stuAge 年龄,examclass.writtenExam 笔试成绩,examclass.labExam 机试成绩 from stuclass +inner join examclass on stuclass.stuNO = examclass.stuNo where writtenExam>=20 order by writtenExam DESC + +--5.查询 男女生 的 机试平均分 +select stuSex ,avg(labExam)机试平均分 from stuclass inner join examclass on stuclass.stuNO = examclass.stuNo group by stuSex + + +--6.查询男女生的笔试总分 + +select stuSex,sum(writtenExam) 笔试总分 from stuclass inner join examclass on stuclass.stuNO = examclass.stuNo group by stuSex diff --git "a/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery2.sql" new file mode 100644 index 0000000..12cadec --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery2.sql" @@ -0,0 +1,67 @@ +create database Demo_01 +go +use Demo_01 +go +create table orders +( + orderId int primary key identity not null, + orderDate datetime not null, +) + +insert into orders values('2008-01-12'),('2008-02-10'),('2008-02-15'),('2008-03-10') + + +create table orderItem +( + ItemiD int primary key identity not null, + orderId int references orders(orderId) not null, + itemType nvarchar(10) not null, + itemName nvarchar(10) not null, + theNumber int not null, + theMoney int not null, +) +insert into orderItem values(1,'文具','笔',72,2),(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56),(2,'文具','笔',36,2),(2,'文具','固体胶',20,3),(2,'日常用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3),(3,'文具','订书机',20,3),(3,'文具','订书针',10,3),(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2),(4,'文具','信纸',50,1),(4,'日常用品','毛巾',4,5),(4,'日常用品','透明胶',30,1),(4,'体育用品','羽毛球',20,3) + +select * from orders +select * from orderItem + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderId 订单编号,orderDate 订单日期,itemType 产品类别, itemName 产品名称, +theNumber 订购数量,theMoney 订购单价 from orders inner join orderItem on orders.orderId = orderItem.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.theNumber 订购数量,orders.orderId 订单编号,orderDate 订单日期,itemType 产品类别, itemName 产品名称 +from orders inner join orderItem on orders.orderId = orderItem.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId 订单编号,orderDate 订单日期,itemType 产品类别, itemName 产品名称,theNumber 订购数量,theMoney 订购单价, +(theNumber*theMoney) 订购总价 from orders inner join orderItem on orders.orderId = orderItem.orderId + +--4.查询 单价大于等于5 并且 数量大于等于50 的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select theMoney,orderDate 订单日期,itemType 产品类别, itemName 产品名称,orderItem.theNumber 订购数量,theMoney 订购单价, +(theNumber*theMoney) 订购总价 from orderItem inner join orders on orderItem.orderId = orders.orderId where theMoney>=5 and theNumber>=50 + +--5.查询每个订单分别订购了几个产品,例如: +--编号 订购产品数 +--1 3 +--2 4 +select orderId,count(*)订购产品数 from orderItem group by orderId + +--6.查询 每个订单里的 每个类别的产品 分别订购了几次 和 总数量,例如: + + --订单编号 产品类别 订购次数 总数量 + +--1 文具 2 82 +--1 体育用品 1 1 +--2 文具 2 56 +--2 体育用品 1 2 +--2 日常用品 + +select orders.orderId 订单编号,itemType 产品类别, count(*)订购次数,sum(theNumber)总数量 from orderItem inner join +orders on orders.orderId=orderItem.orderId group by itemType,orders.orderId + +select orderId 订单编号,itemType 产品类别, count(*)订购次数,sum(theNumber)总数量 from orderItem +group by orderId,itemType \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery3.sql" new file mode 100644 index 0000000..ff452f5 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery3.sql" @@ -0,0 +1,106 @@ +use master +go +create database bbs +on( + name='bbs', + filename='C:\text\bbs.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +log on( + name='bbs_log', + filename='C:\text\bbs_log.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +go +use bbs +go + +--用户信息表 +create table bbsUsers +( + uID int identity(1,1) not null , + uName nvarchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null, + +) +alter table bbsUsers add constraint PK_bbsUsers_uID primary key(uID) +alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 or uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) + +--板块表 +create table bbsSection +( + sID int identity(1,1) not null , + sName varchar(10) not null, + sUid int , + +) +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid)references bbsUsers(uID) + +--主贴表 +create table bbsTopic +( + tID int primary key identity(1,1) not null, + tUID int references bbsUsers(uID) not null , + tSID int references bbsSection(sID) , + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime not null, + tCount int not null, +) + +--回贴表 +create table bbsReply +( + rID int primary key identity(1,1) not null, + rUID int references bbsUsers(uID) , + rTID int references bbsTopic(tID) , + rMsg text not null, + rTime datetime , +) +select * from bbsReply +select * from bbsSection +select * from bbsUsers +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint_backup from bbsUsers +insert into bbsSection values('技术名流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑!','谁是范跑跑!', '2008-7-8',1),(3,2,'.NET!','与JAVA的区别是什么呀?','2008-9-1',2),(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10',0) +insert into bbsReply values(3,1,'一名地震自己先跑的教师','2008-7-8'),(1,2,'不知道','2008-9-15'),(2,2,'Java更难','2008-9-20') +update bbsUsers set uPoint=30 where uName='小雨点' + + +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select bbsUsers.uID,bbsUsers.uName 版主姓名,bbsSection.sName 板块名称 from bbsSection right join bbsUsers +on bbsUsers.uID = bbsSection.sUid + + + +--2.查询出主贴的发帖时间在2008-8-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select * from bbsTopic +select bbsTopic.tID 发帖人编号,bbsUsers.uName 发帖人姓名,tTitle 帖子标题, +tMsg 帖子内容,tTime 发帖时间 from bbsTopic inner join bbsUsers on bbsTopic.tUID = bbsUsers.UID +where tTime>='2008-8-15' + + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select * from bbsUsers +select bbsUsers.uID 版主编号,bbsUsers.uName 版主姓名,bbsSection.sName 板块名称 from bbsUsers left join bbsSection +on bbsUsers.uID = bbsSection.sUid where uAge<=20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select tUID 发帖人编号,bbsUsers.uName 发帖人姓名,bbsTopic.tTitle 主贴标题, bbsTopic.tMsg 主贴内容, +bbsTopic.tCount 回复数量 from bbsTopic inner join bbsUsers on uID=tUID order by tCount DESC + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select * from bbsTopic +select tID,sum(tID)发帖总数 from bbsTopic inner join bbsReply +on bbsTopic.tID = bbsReply.rTID group by tID \ No newline at end of file -- Gitee From 338299b75b76784dd7d6ef42285cebc8ccf9f346 Mon Sep 17 00:00:00 2001 From: cowlong <1220590642@qq.com> Date: Sun, 28 Mar 2021 19:18:33 +0800 Subject: [PATCH 042/195] 3.26 --- .../\344\275\234\344\270\232\344\270\200.sql" | 101 ++++++++++++++++++ .../\344\275\234\344\270\232\344\270\211.sql" | 90 ++++++++++++++++ .../\344\275\234\344\270\232\344\272\214.sql" | 92 ++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\270\200.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\270\211.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\272\214.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\270\200.sql" "b/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\270\200.sql" new file mode 100644 index 0000000..5b40263 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\270\200.sql" @@ -0,0 +1,101 @@ +create database SD + +on +( + name='SD', + filename='D:\Studenta.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='SD_log', + filename='D:\Studenta_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +use SD +go +create table SD2 +( + sTUNO varchar(15), + stuName nvarchar(20), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') +) + +insert into SD2(sTUNO,stuName,stuAge,stuAddress,stuSeat,stuSex) +select 's2501','张秋里',20,'美国硅谷',1,'男' union +select 's2502','李斯文',18,'湖北武汉',2,'女' union +select 's2503','马文才',22,'湖南长沙',3,'男' union +select 's2504','欧阳俊雄',21,'湖北武汉',4,'女' union +select 's2505','梅超风',20,'湖北武汉',5,'男' union +select 's2506','陈旋风',19,'美国硅谷',6,'男' union +select 's2507','陈风',20,'美国硅谷',7,'女' + + +create table Score +( + examNO int, + stuNO varchar(15), + writtenExam varchar(200), + labExam varchar(200) +) + +insert into Score(examNO,stuNO,writtenExam,labExam) +select 1,'s2501','50','70' union +select 2,'s2501','60','65' union +select 3,'s2501','86','85' union +select 4,'s2501','40','80' union +select 5,'s2501','70','90' union +select 6,'s2501','85','90' + +create table stuExam +(examNo int, + stuNo varchar(15), + writtenExam int, + labExam int +) +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) + + +select * from stuExam +select * from SD2 +select * from Score + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名, stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from SD2 s +left join stuExam e on s.stuNo = e.stuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuName 姓名, stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from SD2 s +left join stuExam e on s.stuNo = e.stuNo where writtenExam>60 and labExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuName 姓名, s.stuNo 学号,writtenExam 笔试成绩,labExam 机试成绩 from SD2 s +left join stuExam e on s.stuNo = e.stuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from SD2 s +left join stuExam e on s.stuNo = e.stuNo where stuAge>=20 order by writtenExam desc + +--5.查询男女生的机试平均分 +select stuSex,AVG(labExam)平均分 from stuExam e +left join SD2 s on e.stuNo= s.stuNo group by stuSex + +--6.查询男女生的笔试总分 +select stuSex, SUM(writtenExam) 笔试总分 from stuExam e +left join SD2 s on e.stuNo= s.stuNo group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\270\211.sql" "b/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\270\211.sql" new file mode 100644 index 0000000..71ef22f --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\270\211.sql" @@ -0,0 +1,90 @@ +create database bbs + +on +( + name='bbs', + filename='D:\Studenta\bbs.mdf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='D:\Studenta\bbs_log.ldf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +go +use bbs +go +create table bbsUsers +( + UIDD int identity, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +create table bbsSection +( + sIDD int identity, + sName varchar(10) not null, + sUid int +) + +alter table bbsUsers add constraint Pk_bbsUsers_UIDD primary key(UIDD) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uPoint check(uPoint>=0) + +alter table bbsSection add constraint Pk_bbsSection_sIDD primary key(sIDD) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UIDD) + +create table bbsTopic +( + tID int identity primary key, + tUID int foreign key references bbsUsers(UIDD), + tSID int foreign key references bbsSection(sIDD), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int identity primary key, + rUID int foreign key references bbsUsers(UIDD), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'),(3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), +(1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') + +insert into bbsReply values(3,2,'八嘎','2008-7-8'),(1,1,'python','2008-7-8'),(1,3,'上海','2008-7-8') + +select * from bbsReply --回帖表 +select * from bbsSection --版块表 +select * from bbsTopic --主帖表 +select * from bbsUsers --用户信息表 + + +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sIDD,uName,sName from bbsSection left join bbsUsers on sIDD=UIDD +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID,tMsg,tTime,uName, tTitle from bbsTopic left join bbsUsers on tID=UIDD where tTime> '2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sIDD,uName,sName from bbsSection left join bbsUsers on sIDD=UIDD where uAge < 20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select tUID,tMsg,uName, tTitle,tcount from bbsUsers lefrt join bbsTopic c on UIDD = c.tUID order by tcount desc +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select uName 用户名,sName 版块名称,count(*)发帖总数 from bbsTopic + inner join bbsUsers on bbsTopic.tUID = bbsUsers.UIDD + inner join bbsSection on bbsUsers.UIDD= bbsSection.sUid group by uName,sName diff --git "a/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\272\214.sql" "b/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\272\214.sql" new file mode 100644 index 0000000..d88df8e --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/\344\275\234\344\270\232\344\272\214.sql" @@ -0,0 +1,92 @@ +create database mall on( + name='mall', + filename='D:\Studenta\mall.mdf' +) +log on( + name='mall_log', + filename='D:\Studenta\mall.ldf' +) + +use shop +go + +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) +create table orders( + orderId int primary key identity(1,1), + orderDate datetime default(getdate()) +) + +--订购项目表(orderItem),列为: +create table orderItem( +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) + ItemiD int identity(1,1), + orderId int references orders(orderId), + itemType nvarchar(20), +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) + itemName nvarchar(20), + theNumber int, + theMoney int +) + +insert into orders(orderDate) values +('2008-01-12 00:00:00'), +('2008-02-10 00:00:00'), +('2008-02-15 00:00:00'), +('2008-03-10 00:00:00') +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), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书针',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'日常用品','毛巾',4,5), +(4,'日常用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) +select * from orderItem +select * from orders +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select I.orderId 订单编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购产品的产品名称,theNumber 订购数量 ,theMoney 订购单价 from orderItem I +left join orders d on I.orderId = d.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select I.orderId 订单编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购产品的产品名称 from orderItem I +left join orders d on I.orderId = d.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select I.orderId 订单编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购产品的产品名称,theNumber 订购数量 ,theMoney 订购单价,theNumber*theMoney 订单总价 from orderItem I +left join orders d on I.orderId = d.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select I.orderId 订单编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购产品的产品名称,theNumber 订购数量 ,theMoney 订购单价,theNumber*theMoney 订单总价 from orderItem I +left join orders d on I.orderId = d.orderId where theMoney>=5 and theNumber>=50 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select I.orderId 订单编号,SUM(theNumber) 订购数量 from orderItem I group by I.orderId + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select I.orderId 订单编号,itemType 产品类别,count(theNumber)订购次数,SUM(theNumber) 总数量 from orderItem I +left join orders d on I.orderId = d.orderId group by itemType,I.orderId \ No newline at end of file -- Gitee From c4a97508ed36d9bcfbfde0b966a960bbc93a09f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E6=B5=B7=E5=BD=AA?= <3305448617@qq.com> Date: Sun, 28 Mar 2021 19:51:07 +0800 Subject: [PATCH 043/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery4.sql" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery4.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery4.sql" "b/20210326\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery4.sql" new file mode 100644 index 0000000..9b52429 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery4.sql" @@ -0,0 +1,68 @@ +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select * from StuDent +select StuDent.stuName 姓名, StuDent.stuAge 年龄,Score.writtenExam 笔试成绩,Score.labExam 机试成绩 from StuDent inner join Score on StuDent.stuNO=Score.stuNO + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select * from StuDent +select * from Score +select Score.writtenExam,Score.labExam,StuDent.sTUNO,stuName from Score inner join StuDent on Score.stuNO=StuDent.sTUNO where writtenExam>60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuDent.sTUNO,StuDent.stuName,Score.writtenExam,Score.labExam from StuDent left join Score on StuDent.stuNO=Score.stuNO + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuDent.stuAge,StuDent.stuName,Score.writtenExam,Score.labExam from StuDent inner join Score on StuDent.stuNO=Score.stuNO where stuAge>=20 order by writtenExam desc + +--5.查询男女生的机试平均分 +select StuDent.stuSex,avg(Score.labExam) from StuDent inner join Score on StuDent.stuNO=Score.stuNO group by StuDent.stuSex + +--6.查询男女生的笔试总分 +select StuDent.stuSex,sum(Score.writtenExam) from StuDent inner join Score on StuDent.stuNO=Score.stuNO group by StuDent.stuSex + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orderItem.orderId,orders.orderDate,orderItem.itemType,orderItem.itemName from orderItem inner join orders on orderItem.orderId=orders.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId,orders.orderDate,orderItem.itemType,orderItem.itemName from orderItem inner join orders on orderItem.orderId=orders.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId,orders.orderDate,orderItem.itemType,orderItem.itemName,orderItem.theNumber,orderItem.theNumber*theMoney from orderItem inner join orders on orderItem.orderId=orders.orderId + +--5.查询每个订单分别订购了几个产品,例如: + --编号 订购产品数 + -- 1 3 + -- 2 4 +select itemType,orderId,theNumber from orderItem group by itemType,orderId,theNumber + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + + -- 1 文具 2 82 + -- 1 体育用品 1 1 + -- 2 文具 2 56 + -- 2 体育用品 1 2 + -- 2 日常用品 1 20 +select orderId,itemType,count(itemType)订购次数 ,sum(theNumber) 总数量 from orderItem group by orderId,itemType order by orderId + + +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select * from bbsUsers +select * from bbsSection +select bbsSection.sUid,bbsUsers.uName,bbsSection.sName from bbsSection inner join bbsUsers on bbsSection.sUid=bbsUsers.UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select bbsTopic.tTime,bbsTopic.tUID,bbsUsers.uName,bbsTopic.tTitle,bbsTopic.tMsg, bbsTopic.tTime from bbsTopic inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID where tTime>2008-9-15 + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select bbsUsers.uAge,bbsSection.sUid,bbsUsers.uName,bbsSection.sName from bbsSection inner join bbsUsers on bbsSection.sUid=bbsUsers.UID group by uAge,sUid,uName,sName having uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select bbsReply.rID, bbsReply.rUID,bbsTopic.tTitle,bbsTopic.tMsg,bbsTopic.tCount from bbsReply inner join bbsTopic on bbsReply.rUID=bbsTopic.tUID where tCOunt=2 + + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select bbsSection.sName,count(tID) from bbsTopic inner join bbsSection on bbsSection.sUid =bbsTopic.tUID group by sName, tUid + + -- Gitee From 8a4c3d040fea76108f122eacfb83546b10928bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E6=A2=A6=E6=9E=97?= <2777141796@qq.com> Date: Sun, 28 Mar 2021 20:03:38 +0800 Subject: [PATCH 044/195] =?UTF-8?q?=E5=85=AB=E5=98=8E=E5=8E=8B=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 261 ++++++++++++++++++ .../SQLQuery2.sql" | 204 ++++++++++++++ .../SQLQuery3.sql" | 110 ++++++++ 3 files changed, 575 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery1.sql" new file mode 100644 index 0000000..35d3cd0 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery1.sql" @@ -0,0 +1,261 @@ +drop database Studentinfo + +create database Studentinfo + + + +on + +( + + name='Studentinfo', + + filename='E:\SQL\Studentinfo.mdf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +log on + +( + + name='Studentinfo_log', + + filename='E:\SQL\Studentinfo_log.ldf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + + + +use Studentinfo + +go + +create table StuDent + +( + + sTUNO varchar(15), + + stuName nvarchar(20), + + stuAge int, + + stuAddress nvarchar(50), + + stuSeat int, + + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') + +) + + + +insert into StuDent(sTUNO,stuName,stuAge,stuAddress,stuSeat,stuSex) + +select 's2501','张秋里',20,'美国硅谷',1,'男' union + +select 's2502','李斯文',18,'湖北武汉',2,'女' union + +select 's2503','马文才',22,'湖南长沙',3,'男' union + +select 's2504','欧阳俊雄',21,'湖北武汉',4,'女' union + +select 's2505','梅超风',20,'湖北武汉',5,'男' union + +select 's2506','陈旋风',19,'美国硅谷',6,'男' union + +select 's2507','陈风',20,'美国硅谷',7,'女' + + + + + +create table Score + +( + + examNO int, + + stuNO varchar(15), + + writtenExam int, + + labExam int + +) + +drop table Score + +insert into Score(examNO,stuNO,writtenExam,labExam) + +select 1,'s2501','50','70' union + +select 2,'s2502','60','65' union + +select 3,'s2503','86','85' union + +select 4,'s2504','40','80' union + +select 5,'s2505','70','90' union + +select 6,'s2506','85','90' + + + +--指定别名 + +select stuNO as 学号, stuName as 姓名 ,stuAddress as 地址,stuSeat as 座位号,stuSex as 性别 from StuDent + + + +--查询 stuName,stuAge,stuAddress + +select stuName,stuAge,stuAddress from StuDent + + + +--查询 学号 笔试 机试 指定别名1 + +select stuNO as 学号 ,writtenExam as 笔试,labExam as 机试 from Score + +--指定别名2 + +select stuNO 学号 ,writtenExam 笔试,labExam 机试 from Score + +--指定别名3 + +select 学号=stuNO,笔试=writtenExam,机试=labExam from Score + + + + + +select stuNO+stuName+stuAddress+'@'+stuAddress as 邮箱 from StuDent + + + +--查询并计算总分 + +select stuNO as 学号,writtenExam as 笔试 ,labExam as 机试, writtenExam+labExam as 总分 from Score + + + + + +select stuName ,stuAddress from StuDent + + + +select stuAge as 所有年龄 from StuDent + + + +--查询前三 + +select top 3 * from StuDent + +--查询前四 姓名 座位号 + +select top 4 stuName,stuSeat from StuDent + + + +select top 50 percent * from StuDent + + + +select stuName ,stuAddress='湖北武汉',stuAge=20 from StuDent + + + +--范围查询并降序 + +select labExam from Score where labExam>=60 and labExam<=80 order by labExam DESC + + + +-- in or + +select * from StuDent where stuAddress = '湖北武汉' or stuAddress = '湖南长沙' + +select * from StuDent where stuAddress in('湖北武汉', '湖南长沙') + + + +select writtenExam from Score where writtenExam<70 order by writtenExam + + + +select * from StuDent where stuAge is null or stuAge='' + +select*from StuDent where stuAge is not null and not stuage='' + + + +--模糊查询 + +select * from StuDent where stuName like'张%' + + + +select * from StuDent where stuAddress like '%湖%' + + + +select * from StuDent where stuName like'张_' + + + +select * from StuDent where stuName like'__俊%' + + + +select * from StuDent order by stuAge DESC + + + +select * from StuDent order by stuAge DESC , stuSeat ASC + + + +select top 1 * from Score order by writtenExam DESC + + + +select top 1 * from Score order by labExam ASC + + +--1.查询学生的姓名,年龄,笔试成绩和机试成 +select * from StuDent +select * from Score +select M.StuName 姓名,M.stuAge 年龄,L .writtenExam 鼻屎 ,L .labExam 鸡屎 from StuDent M inner join Score L on M.stuno = L.stuno + + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select Score.stuno 学号,StuDent.StuName 姓名,StuDent.stuAge 年龄,Score .writtenExam 鼻屎 ,Score .labExam 鸡屎 from StuDent inner join Score on StuDent.stuno = Score.stuno WHERE Score .writtenExam>60 AND Score .labExam >60 + + + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select Score.stuno 学号, StuDent.StuName 姓名,StuDent.stuAge 年龄,Score .labExam 鸡屎,Score .writtenExam 鼻屎 from StuDent left join Score on StuDent.stuno = Score.stuno + + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuDent.StuName 姓名,StuDent.stuAge 年龄,Score .writtenExam 鼻屎 ,Score .labExam 鸡屎 from StuDent inner join Score on StuDent.stuno = Score.stuno WHERE StuDent.stuAge>=20 order by writtenExam desc + +--5.查询男女生的机试平均分 +select StuDent.stusex 性别,avg(Score .labExam) 鸡屎平均 from StuDent inner join Score on StuDent.stuno = Score.stuno group by StuDent.stusex +--6.查询男女生的笔试总分 +select StuDent.stusex 性别,sum(Score .writtenExam)鼻屎总分 from StuDent inner join Score on StuDent.stuno = Score.stuno group by StuDent.stusex diff --git "a/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery2.sql" new file mode 100644 index 0000000..d3162b0 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery2.sql" @@ -0,0 +1,204 @@ +use master + + + +create database bbs + + + +on + + + +( + + + + name='bbs', + + + + filename='E:\bbs.mdf', + + + + size=6MB, + + + + maxsize=100MB, + + + + filegrowth=10MB + + + +) + + + + + + + +log on + + + +( + + + + name='bbs_log', + + + + filename='E:\bss_log.ldf', + + + + size=6MB, + + + + maxsize=100MB, + + + + filegrowth=10MB + + + +) + + + +go + + use bbs + + go + + + + drop database bbs + + --订单表 + + create table orders + + ( + + orderId int primary key, + + orderDate datetime + +) + + + drop table orders + +insert into orders(orderId,orderDate) + +select 1,'2008-01-12' union + +select 2,'2008-02-10' union + +select 3,'2008-02-15' union + +select 4,'2008-03-10' + + + --订单项目表 + + create table orderItem + + ( + + ItemiD int not null primary key identity(1,1) ,--项目编号 + + orderId varchar(50),--订单编号 + + itemType nvarchar(20) ,--产品类别 + + itemName nvarchar(20),--产品名称 + + theNumber int ,--订购数量 + + theMoney int --订购单价 + + + + ) + + drop table orderItem + + select * from orderItem + + insert into orderItem( orderId,itemType,itemName,theNumber,theMoney ) + + select '1', '文具', '笔', 72 , 2 union + + select '1', '文具', '尺', 10 , 1 union + + select '1', '体育用品', '篮球', 1 , 56 union + + select '2', '文具', '笔', 1 , 36 union + + select '2', '文具', '固体胶', 20 , 3 union + + select '2', '日常用品', '透明胶',2 , 1 union + + select '2', '体育用品', '羽毛球', 20 , 3 union + + select '3', '文具', '订书机', 20 , 3 union + + select '3', '文具', '订书针', 10 , 3 union + + select '3', '文具', '载纸刀', 5 , 5 union + + select '4', '文具', '笔', 20 , 2 union + + select '4', '文具', '信纸', 50 , 1 union + + select '4', '日常用品', '毛巾', 4 , 5 union + + select '4', '日常用品', '透明胶', 30 , 1 union + + select '4', '体育用品', '羽毛球', 20 , 3 + + + select * from orderItem + select * from orders + --使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select L .orderId 订单编号 , M.orderDate 日期,L.itemType 类别,L. itemName 名称 ,L.theNumber 数量,L.theMoney 单价 from orders M inner join orderItem L on M.orderId=L.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select L.orderId 订单编号, M.orderDate 日期,L.itemType 类别,L. itemName 名称 ,L.theNumber 数量 from orders M inner join orderItem L on M.orderId=L.orderId where L.theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select L.orderId 订单编号, M.orderDate 日期,L.itemType 类别,L. itemName 名称 ,L.theNumber 数量, L.theMoney 单价 ,L.theMoney * L.theNumber 总价 from orders M inner join orderItem L on M.orderId=L.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select L.orderId 订单编号, M.orderDate 日期,L.itemType 类别,L. itemName 名称 ,L.theNumber 数量, L.theMoney 单价 ,L.theMoney * L.theNumber 总价 from orders M inner join orderItem L on M.orderId=L.orderId where L.theMoney >=5 and L.theNumber>50 + +--5.查询每个订单分别订购了几个产品,例如: + --编号 订购产品数 +select L.orderId 订单编号, L.theNumber 订购数量 from orders M inner join orderItem L on M.orderId=L.orderId group by L.theNumber,L.orderId + + + + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量select M.orderDate 日期,L.itemType 类别,L. itemName 名称 ,L.theNumber 数量, L.theMoney 单价 ,L.theMoney * L.theNumber 总价 from orders M inner join orderItem L on M.orderId=L.orderId where L.theMoney >=5 and L.theNumber>50 +select L.orderId 订单编号,L.itemType 类别,count(*) 订购次数, SUM(L.theNumber)总数量 from orders M inner join orderItem L on M.orderId=L.orderId group by L.itemType,L.orderId + + --订单编号 产品类别 订购次数 总数量 + + -- 1 文具 2 82 + -- 1 体育用品 1 1 + -- 2 文具 2 56 + -- 2 体育用品 1 2 + -- 2 日常用品 1 20 \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery3.sql" new file mode 100644 index 0000000..df0c81b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/2\346\235\250\346\242\246\346\236\227/SQLQuery3.sql" @@ -0,0 +1,110 @@ +create database dds + +on +( + name='dds', + filename='D:\dds.mdf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='dds_log', + filename='D:\dds_log.ldf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +go +use dds +go +--用户信息表 +create table bbsUsers +( + UIDD int identity, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +--板块表 +select * from bbsSection + +create table bbsSection +( + sIDD int identity, + sName varchar(10) not null, + sUid int +) + +alter table bbsUsers add constraint Pk_bbsUsers_UIDD primary key(UIDD) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uPoint check(uPoint>=0) + +alter table bbsSection add constraint Pk_bbsSection_sIDD primary key(sIDD) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UIDD) + + +--主贴表 +drop table bbsTopic +create table bbsTopic +( + tID int identity primary key, + tUID int foreign key references bbsUsers(UIDD), + tSID int foreign key references bbsSection(sIDD), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + +--回帖表 +drop table bbsReply +create table bbsReply +( + rID int identity primary key, + rUID int foreign key references bbsUsers(UIDD), + rTID int foreign key references bbsTopic(tID), + rMsg varchar(20) not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'),(3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), +(1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') +insert into bbsReply values(3,2,'狗屎超粘','2008-7-8'),(1,1,'不知道','2008-7-8'),(1,3,'黑丝','2008-7-8') + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号版主姓名和版块名称 +select * from bbsSection --板块表 + select * from bbsTopic + select M.sIDD 编号,L.uName 姓名,M.sName 版块 from bbsSection M inner join bbsUsers L on M.sIDD=L.UIDD + + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 + select * from bbsUsers +select M.tid 编号 ,L.uName 姓名 ,M.tTitle 标题, M.tMsg 内容,M.tTime 时间 from bbsTopic M inner join bbsUsers L on M.tid=L.UIDD where tTime >'2008-9-15' + + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select M.sIDD 编号,L.uage 年龄,L.uName 姓名,M.sName 版块 from bbsSection M inner join bbsUsers L on M.sIDD=L.UIDD where L.uage<20 + + +--4.查询出回复数量最多的主贴的 发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select * from bbsReply + +select UIDD,uName,tTitle,tMsg,tCount from bbsTopic left join bbsUsers on bbsTopic.tID=bbsUsers.UIDD + + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select * from bbsSection +select * from bbsTopic +select * from bbsUsers +select uName 姓名,count(tTitle)总数,sName from bbsUsers inner join bbsTopic on bbsUsers.UIDD=bbsTopic.tUID +inner join bbsSection on bbsTopic.tUID=bbsSection.sUid group by tTitle,uName,sName -- Gitee From 1d865738ae6173bdeaffc2b84e515d7345b3f1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=96=E7=BA=B7?= <8332024+o2444091281@user.noreply.gitee.com> Date: Sun, 28 Mar 2021 20:49:38 +0800 Subject: [PATCH 045/195] =?UTF-8?q?=E9=BB=84=E9=94=9F=E5=AE=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQL1.sql" | 79 ++++++++++++ .../SQL2.sql" | 88 ++++++++++++++ .../SQL3.sql" | 115 ++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL3.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL1.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL1.sql" new file mode 100644 index 0000000..7a68c13 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL1.sql" @@ -0,0 +1,79 @@ +use master +go + +create database Student05 +go + +use Student05 +go + +create table StuIS +( + StuNO nvarchar(10) unique not null, + StuName nvarchar(10) not null, + StuAge int not null, + StuAddress nvarchar(200) , + StuSeat nvarchar(8) not null, + StuSex nvarchar(1) default('鐢') check(StuSex='鐢' or StuSex='濂') +) + +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2501','寮犵鍒','20','缇庡浗纭呰胺','1','濂') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2502','鏉庢柉鏂','18','婀栧寳姝︽眽','2','鐢') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2503','椹枃鎵','22','婀栧崡闀挎矙','3','鐢') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2504','娆ч槼淇婇泟','21','婀栧寳姝︽眽','3','濂') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2505','姊呰秴椋','20','婀栧寳姝︽眽','4','濂') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2506','闄堟棆椋','19','缇庡浗纭呰胺','5','濂') +insert into StuIS(StuNO,StuName,StuAge,StuAddress,StuSeat,StuSex) +values('s2507','闄堥','20','缇庡浗纭呰胺','7','濂') + +create table Grate +( + ExamNo int primary key identity(1,1), + StuNo nvarchar(10) references StuIS(StuNO), + WExam int not null, + LabExam int not null +) +insert into Grate(StuNO,WExam,LabExam) +values('s2501','50','70') +insert into Grate(StuNO,WExam,LabExam) +values('s2502','60','65') +insert into Grate(StuNO,WExam,LabExam) +values('s2503','86','85') +insert into Grate(StuNO,WExam,LabExam) +values('s2504','40','80') +insert into Grate(StuNO,WExam,LabExam) +values('s2505','70','90') +insert into Grate(StuNO,WExam,LabExam) +values('s2506','85','90') + + +--鏁版嵁濡傚浘鐗1,浣跨敤涓婃浣滀笟鐨勬暟鎹 +select * from Grate +select * from StuIS +--1.鏌ヨ瀛︾敓鐨勫鍚嶏紝骞撮緞锛岀瑪璇曟垚缁╁拰鏈鸿瘯鎴愮哗 +select StuName,StuAge ,WExam,LabExam from StuIS +inner join Grate on StuIS.StuNO = Grate.StuNO + +--2.鏌ヨ绗旇瘯鍜屾満璇曟垚缁╅兘鍦60鍒嗕互涓婄殑瀛︾敓鐨勫鍙凤紝濮撳悕锛岀瑪璇曟垚缁╁拰鏈鸿瘯鎴愮哗 +select StuIS.StuNO ,StuName,WExam,LabExam from StuIS +inner join Grate on StuIS.StuNO = Grate.StuNO where Grate.WExam>=60 and Grate.LabExam>=60 + +--3.鏌ヨ鎵鏈夊鐢熺殑瀛﹀彿锛屽鍚嶏紝绗旇瘯鎴愮哗锛屾満璇曟垚缁╋紝娌℃湁鍙傚姞鑰冭瘯鐨勫鐢熺殑鎴愮哗浠ULL鍊煎~鍏 +select StuIS.StuNO ,StuName,WExam,LabExam from StuIS +left join Grate on StuIS.StuNO = Grate.StuNO + +--4.鏌ヨ骞撮緞鍦20浠ヤ笂锛堝寘鎷20锛夌殑瀛︾敓鐨勫鍚嶏紝骞撮緞锛岀瑪璇曟垚缁╁拰鏈鸿瘯鎴愮哗锛屽苟鎸夌瑪璇曟垚缁╅檷搴忔帓鍒 +select StuName,StuAge,WExam,LabExam from StuIS +inner join Grate on StuIS.StuNo = Grate.StuNO where StuIS.StuAge>=20 order by Grate.WExam DESC +--5.鏌ヨ鐢峰コ鐢熺殑鏈鸿瘯骞冲潎鍒 +select StuSex , avg(LabExam) from StuIS +inner join Grate on StuIS.StuNO = Grate.StuNO group by StuSex +--6.鏌ヨ鐢峰コ鐢熺殑绗旇瘯鎬诲垎 +select StuSex , sum(WExam) from StuIS +inner join Grate on StuIS.StuNO = Grate.StuNO group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL2.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL2.sql" new file mode 100644 index 0000000..56dec4b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL2.sql" @@ -0,0 +1,88 @@ +create database OrderIno +go + +use OrderIno +go + +create table orders +( + orderID int primary key identity(1,1), + orderDate datetime +) + +create table orderltem +( + ltemID int identity(1,1), + orderID int , + itemType nvarchar(15), + itemName nvarchar(10), + theNumber int , + theMoney money +) + +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 orderltem values +(1,'鏂囧叿','绗',72,2), +(1,'鏂囧叿','灏',10,1), +(1,'浣撹偛鐢ㄥ搧','绡悆',1,56), +(2,'鏂囧叿','绗',36,2), +(2,'鏂囧叿','鍥轰綋鑳',20,3), +(2,'鐢熸椿鐢ㄥ搧','閫忔槑鑳',2,1), +(2,'浣撹偛鐢ㄥ搧','缇芥瘺鐞',20,3), +(3,'鏂囧叿','璁功鏈',20,3), +(3,'鏂囧叿','璁功鏈',10,3), +(3,'鏂囧叿','瑁佺焊鍒',5,5), +(4,'鏂囧叿','绗',20,2), +(4,'鏂囧叿','淇$焊',50,1), +(4,'鐢熸椿鐢ㄥ搧','姣涘肪',4,5), +(4,'鐢熸椿鐢ㄥ搧','閫忔槑鑳',30,1), +(4,'浣撹偛鐢ㄥ搧','缇芥瘺鐞',20,3) + + +--浣跨敤涓婃浣滀笟鐨勮鍗曟暟鎹簱锛屽畬鎴愪笅鍒楅鐩細 + +select * from orders --璁㈠崟琛 +select * from orderltem --璁㈣喘椤圭洰琛 + +--璁㈠崟琛紙orders锛夊垪涓猴細璁㈠崟缂栧彿锛坥rderID 涓婚敭锛 璁㈣喘鏃ユ湡锛坥rderDate锛--璁㈣喘椤圭洰琛紙orderItem锛夛紝鍒椾负锛--椤圭洰缂栧彿锛圛temID锛夎鍗曠紪鍙凤紙orderID锛変骇鍝佺被鍒紙itemType锛--浜у搧鍚嶇О锛坕temName锛 璁㈣喘鏁伴噺锛坱heNumber锛 璁㈣喘鍗曚环锛坱heMoney锛 +--1.鏌ヨ鎵鏈夌殑璁㈠崟鐨勮鍗曠殑缂栧彿锛岃鍗曟棩鏈燂紝璁㈣喘浜у搧鐨勭被鍒拰璁㈣喘鐨勪骇鍝佸悕绉帮紝璁㈣喘鏁伴噺鍜岃璐崟浠 +select orders.orderID 璁㈠崟鐨勭紪鍙 ,orderDate 璁㈠崟鏃ユ湡, itemType 璁㈣喘浜у搧鐨勭被鍒,itemName 璁㈣喘鐨勪骇鍝佸悕绉 from orders +inner join orderltem on orders.orderID =orderltem.orderID + +--2.鏌ヨ璁㈣喘鏁伴噺澶т簬50鐨勮鍗曠殑缂栧彿锛岃鍗曟棩鏈燂紝璁㈣喘浜у搧鐨勭被鍒拰璁㈣喘鐨勪骇鍝佸悕绉 +select orders.orderID 璁㈠崟鐨勭紪鍙 ,orderDate 璁㈠崟鏃ユ湡, itemType 璁㈣喘浜у搧鐨勭被鍒,itemName 璁㈣喘鐨勪骇鍝佸悕绉 from orders +inner join orderltem on orders.orderID =orderltem.orderID where orderltem.theNumber >50 + + +--3.鏌ヨ鎵鏈夌殑璁㈠崟鐨勮鍗曠殑缂栧彿锛岃鍗曟棩鏈燂紝璁㈣喘浜у搧鐨勭被鍒拰璁㈣喘鐨勪骇鍝佸悕绉帮紝璁㈣喘鏁伴噺鍜岃璐崟浠蜂互鍙婅璐讳环 +select orders.orderID 璁㈠崟鐨勭紪鍙 ,orderDate 璁㈠崟鏃ユ湡, itemType 璁㈣喘浜у搧鐨勭被鍒,itemName 璁㈣喘鐨勪骇鍝佸悕绉, theNumber 璁㈣喘鏁伴噺 ,theMoney 璁㈣喘鍗曚环 , theNumber*theMoney 璁㈣喘鎬讳环 from orders +inner join orderltem on orders.orderID =orderltem.orderID + + +--4.鏌ヨ鍗曚环澶т簬绛変簬5骞朵笖鏁伴噺澶т簬绛変簬50鐨勮鍗曠殑璁㈠崟鐨勭紪鍙凤紝璁㈠崟鏃ユ湡锛岃璐骇鍝佺殑绫诲埆鍜岃璐殑浜у搧鍚嶇О锛岃璐暟閲忓拰璁㈣喘鍗曚环浠ュ強璁㈣喘鎬讳环 +select orders.orderID 璁㈠崟鐨勭紪鍙 ,orderDate 璁㈠崟鏃ユ湡, itemType 璁㈣喘浜у搧鐨勭被鍒,itemName 璁㈣喘鐨勪骇鍝佸悕绉, theNumber 璁㈣喘鏁伴噺 ,theMoney 璁㈣喘鍗曚环 , theNumber*theMoney 璁㈣喘鎬讳环 from orders +inner join orderltem on orders.orderID =orderltem.orderID where orderltem.theMoney>=5 and orderltem.theNumber>=50 + + +--5.鏌ヨ姣忎釜璁㈠崟鍒嗗埆璁㈣喘浜嗗嚑涓骇鍝侊紝渚嬪锛 +-- 缂栧彿 璁㈣喘浜у搧鏁 +-- 1 3 +-- 2 4 +select orderID 璁㈠崟鐨勭紪鍙 , count(*)璁㈣喘浜у搧鏁 from orderltem group by orderID + + +--6.鏌ヨ姣忎釜璁㈠崟閲岀殑姣忎釜绫诲埆鐨勪骇鍝佸垎鍒璐簡鍑犳鍜屾绘暟閲忥紝渚嬪锛 +-- 璁㈠崟缂栧彿 浜у搧绫诲埆 璁㈣喘娆℃暟 鎬绘暟閲 +-- 1 鏂囧叿 2 82 +-- 1 浣撹偛鐢ㄥ搧 1 1 +-- 2 鏂囧叿 2 56 +-- 2 浣撹偛鐢ㄥ搧 1 2 +-- 2 鏃ュ父鐢ㄥ搧 1 20 + +select orderID 璁㈠崟鐨勭紪鍙 , itemType 浜у搧绫诲埆 ,count(*)璁㈣喘娆℃暟 , sum(theNumber) 鎬绘暟閲 + from orderltem group by orderID,itemType order by orderID \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL3.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL3.sql" new file mode 100644 index 0000000..dd829d2 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL3.sql" @@ -0,0 +1,115 @@ +use master +go + +create database bbs +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +-- +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) +-- +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) +-- +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('鐢','濂')) +-- +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) +-- +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) +-- + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +-- +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values +('灏忛洦鐐','濂',20,0), +('閫嶉仴','鐢',18,4), +('涓冨勾绾х敓','鐢',19,2) + + +select * into bbsPoint from bbsUsers + +insert into bbsSection values +('鎶鏈氦娴',1), +('璇讳功涓栫晫',3), +('鐢熸椿鐧剧',1), +('鍏崷鍖',3) + +insert into bbsTopic values +(2,4,'浠婂勾澶忓ぉ鏈娴佽浠涔','鏈夎皝鐭ラ亾浠婂勾澶忓ぉ鏈娴佽浠涔堝憖?',2008-9-10,0), +(3,1,'.NET','涓嶫AVA鐨勫尯鍒槸浠涔堝憖?',2008-9-1,2), +(1,3,'鑼冭窇璺','璋佹槸鑼冭窇璺',2008-7-8,1) + +insert into bbsReply values +(2,1,'涓嶇煡閬',2008-9-10), +(3,2,'涓嶇煡閬',2008-9-1), +(1,3,'涓嶇煡閬',2008-7-8) + +select * from bbsReply --鍥炲笘琛 +select * from bbsSection --鐗堝潡琛 +select * from bbsTopic --涓诲笘琛 +select * from bbsUsers --鐢ㄦ埛淇℃伅琛 + +--鍦ㄨ鍧涙暟鎹簱涓畬鎴愪互涓嬮鐩 +--1.鏌ヨ鍑 姣忎釜鐗堝潡 鐨 鐗堜富缂栧彿锛 鐗堜富濮撳悕 鍜岀増鍧楀悕绉 +select sUid 鐗堜富缂栧彿,uName 鐗堜富濮撳悕,sName 鐗堝潡鍚嶇О from bbsSection +inner join bbsUsers on bbsUsers.UID = bbsSection.sUid + +--2.鏌ヨ鍑轰富璐寸殑鍙戝笘鏃堕棿鍦2008-9-15浠ュ悗鐨勪富璐寸殑鍙戝笘浜虹紪鍙凤紝鍙戝笘浜哄鍚嶏紝甯栧瓙鐨勬爣棰橈紝甯栧瓙鐨勫唴瀹瑰拰鍙戝笘鏃堕棿 +select tUID 鍙戝笘浜虹紪鍙,uName 鍙戝笘浜哄鍚,tTItle 甯栧瓙鐨勬爣棰 ,tMsg 甯栧瓙鐨勫唴瀹,tTime 鍙戝笘鏃堕棿 from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID where tTime>'2008-9-15' + + +--3.鏌ヨ鍑哄勾榫勫湪20浠ヤ笅鐨勭増涓荤殑缂栧彿锛岀増涓荤殑鍚嶇О鍜岀増鍧楃殑鍚嶇О +select sUid 鐗堜富缂栧彿,uName 鐗堜富濮撳悕,sName 鐗堝潡鍚嶇О from bbsSection +inner join bbsUsers on bbsUsers.UID = bbsSection.sUid where uAge<20 + +--4.鏌ヨ鍑哄洖澶嶆暟閲忔渶澶氱殑涓昏创鐨勫彂甯栦汉缂栧彿锛屽彂甯栦汉濮撳悕锛屼富璐存爣棰橈紝涓昏创鍐呭鍜屽洖澶嶆暟閲 +select rUID 鍙戝笘浜虹紪鍙 , uName 鍙戝笘浜哄鍚 ,tTItle 涓昏创鏍囬 , tMsg 涓昏创鍐呭 , tCount 鍥炲鏁伴噺 from bbsReply +inner join bbsTopic on bbsTopic.tUID = bbsReply.rUID +inner join bbsUsers on bbsUsers.UID = bbsReply.rUID where tCount=(select max(tCount) from bbsTopic) + +--5.鍦ㄤ富璐磋〃涓煡璇㈡瘡涓増鍧椾腑姣忎釜鐢ㄦ埛鐨勫彂甯栨绘暟 +select tSID 鐗堝潡 , uName 鍙戝笘浜哄鍚 , count(*) from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID +inner join bbsSection on bbsUsers.UID =bbsSection.sID group by tSID ,uName \ No newline at end of file -- Gitee From b4c876016eb8fe8b4e2de19c84700c77cecb970d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=80?= <8332095+Xone-by-one@user.noreply.gitee.com> Date: Sun, 28 Mar 2021 21:00:20 +0800 Subject: [PATCH 046/195] 123 --- .../SQLQuery1.sql" | 69 +++++++++++ .../SQLQuery2.sql" | 91 ++++++++++++++ .../SQLQuery3.sql" | 111 ++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" new file mode 100644 index 0000000..4fbb09a --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" @@ -0,0 +1,69 @@ +create database Studentinfo + +on +( + name='Studentinfo', + filename='C:\app\Studentinfo.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='Studentinfo_log', + filename='C:\app\Studentinfo_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +use Studentinfo +go +create table StuDent +( + sTUNO varchar(15), + stuName nvarchar(20), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') +) + +insert into StuDent(sTUNO,stuName,stuAge,stuAddress,stuSeat,stuSex) +select 's2501','张秋里',20,'美国硅谷',1,'男' union +select 's2502','李斯文',18,'湖北武汉',2,'女' union +select 's2503','马文才',22,'湖南长沙',3,'男' union +select 's2504','欧阳俊雄',21,'湖北武汉',4,'女' union +select 's2505','梅超风',20,'湖北武汉',5,'男' union +select 's2506','陈旋风',19,'美国硅谷',6,'男' union +select 's2507','陈风',20,'美国硅谷',7,'女' + + +create table Score +( + examNO int, + stuNO varchar(15), + writtenExam varchar(200), + labExam varchar(200) +) + +insert into Score(examNO,stuNO,writtenExam,labExam) +select 1,'s2501','50','70' union +select 2,'s2502','60','65' union +select 3,'s2503','86','85' union +select 4,'s2504','40','80' union +select 5,'s2505','70','90' union +select 6,'s2506','85','90' + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName,stuAge,writtenExam,labExam from StuDent inner join Score on StuDent.sTUNO=Score.stuNO +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuDent.sTUNO,stuName,writtenExam,labExam from StuDent inner join Score on StuDent.sTUNO=Score.stuNO where Score.writtenExam>=60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuDent.sTUNO,StuDent.StuName,Score.writtenExam,Score.labExam from StuDent left outer join Score on StuDent.sTUNO=Score.stuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName,stuAge,writtenExam,labExam from StuDent inner join Score on StuDent.sTUNO=Score.stuNO where StuDent.stuAge>=20 order by writtenExam desc +--5.查询男女生的机试平均分 +select StuSex,AVG(labExam) from StuDent inner join Score on StuDent.sTUNO=Score.stuNO group by StuSex +--6.查询男女生的笔试总分 +select StuSex,SUM(writtenExam) from StuDent left join Score on StuDent.sTUNO=Score.stuNO group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery2.sql" new file mode 100644 index 0000000..c446b2f --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery2.sql" @@ -0,0 +1,91 @@ +create database asd +on +( + name='asd', + filename='C:\app\asd.mdf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) +log on +( + name='asd_log', + filename='C:\app\asd.ldf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) +go +use asd +go +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) + +create table orders +( + orderId int primary key, + orderDate datetime +) +--插入表1数据 +insert into orders(orderId,orderDate) +select 1,'2008-01-12' union +select 2,'2008-02-10' union +select 3,'2008-02-15' union +select 4,'2008-03-10' +select * from orders +--订购项目表(orderItem),列为: +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) +create table orderItem +( + ItemiD int primary key identity(1,1), + orderId int, + itemType varchar(20), + itemName varchar(20), + theNumber int , + theMoney int +) +--添加表二的外键约束 关联表一的order id +alter table orderItem add constraint FK foreign key (orderId) references orders(orderId) +--插入表2数据 +insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) +select 1,'文具','笔',72,2 union +select 1,'文具','尺',10,1 union +select 1,'体育用品','篮球',1,56 union +select 2,'文具','笔',36,2 union +select 2,'文具','固体胶',20,3 union +select 2,'日常用品','透明胶',2,1 union +select 2,'体育用品','羽毛球',20,3 union +select 3,'文具','订书机',20,3 union +select 3,'文具','订书针',10,3 union +select 3,'文具','裁纸刀',5,5 union +select 4,'文具','笔',20,2 union +select 4,'文具','信纸',50,1 union +select 4,'日常用品','毛巾',4,5 union +select 4,'日常用品','透明胶',30,1 union +select 4,'体育用品','羽毛球',20,3 + +--Select*from orders +--Select*from orderItem + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderId,orderDate,itemType,itemName,theNumber,theMoney from orders inner join orderItem on orders.orderId=orderItem.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderId,theNumber,orderDate,itemType,itemName from orders inner join orderItem on orders.orderId=orderItem.orderId where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId,orderDate,itemType,itemName,theMoney,itemName*theMoney from orders inner join orderItem on orders.orderId=orderItem.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +Select orders.orderId,orderDate,itemType,itemName,theMoney,itemName*theMoney from orders inner join orderItem on orders.orderId=orderItem.orderId where theMoney>5 and itemName>50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId,COUNT(itemName) from orderItem group by orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +select orderId,itemType,COUNT(itemType),SUM(theMoney) from orderItem group by orderId,itemType order by orderId asc +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery3.sql" new file mode 100644 index 0000000..c3f876e --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery3.sql" @@ -0,0 +1,111 @@ +use master +go +create database BBS +on +( +name='BBS', +filename='C:\app\BBS.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='BBS_log', +filename='C:\app\BBS_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use BBS +go +create table BBSUsers--用户信息表 +( +UID int not null, +UName varchar(10) not null, +USex varchar(2) not null, +UAge int not null, +UPoint int not null +) + +alter table BBSUsers add constraint PK_BBSUsers_UID primary key(UID) +alter table BBSUsers add constraint UK_BBSUsers_UName unique(UName) +alter table BBSUsers add constraint CK_BBSUsers_USex check(USex='男' or USex='女') +alter table BBSUsers add constraint CK_BBSUsers_UAge check(UAge>=15 and UAge<=60) +alter table BBSUsers add constraint CK_BBSUsers_UPoint check(UPoint>=0) + +go +use BBS +go +create table BBSSection--版块表 +( +SID int not null, +SName varchar(10) not null, +SUID int not null +) +alter table BBSSection add constraint PK_BBSSection_SID primary key(SID) +alter table BBSSection add constraint FK_BBSSection_SUID foreign key (SUID) references BBSUsers(UID) + +go +use BBS +go +create table BBSTopic--主贴表 +( +TID int primary key identity(1,1) not null, +TUID int references BBSUsers(UID) not null, +TSID int references BBSSection(SID) not null, +TTitle varchar(100) not null, +TMsg text not null, +TTime datetime , +Tcount int , +) + +go +use BBS +go +create table BBSReply--回帖表 +( +RID int primary key identity(1,1) not null, +RUID int references BBSUsers(UID) not null, +RTID int references BBSTopic(TID) not null, +RMsg text , +RTime datetime , +) +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(1,'小雨点','女','20','0') +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(2,'逍遥','男','18','4') +insert into BBSUsers (UID,UName , USex , UAge , UPoint) values(3,'七年级生','男','19','2') + +select UName,UPoint into BBSPoint from BBSUsers + +insert into BBSSection (SID,SName,SUID) values(4,'技术交流',1) +insert into BBSSection (SID,SName,SUID) values(5,'读书世界',3) +insert into BBSSection (SID,SName,SUID) values(6,'生活八卦',1) +insert into BBSSection (SID,SName,SUID) values(7,'八卦区',3) + +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(2,7,'范跑跑','谁是范跑跑','2008-7-8',1) +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(3,4,'.NET','与JAVA的区别是什么','2008-9-1',2) +insert into BBSTopic (TUID,TSID,TTitle,TMsg,TTime,Tcount) values(1,6,'今年夏天最流行什么','有谁知道今年夏天最流行什么','2008-9-10',0) + +insert into BBSReply (RUID,RMsg,RTime,RTID) values(1,'范跑跑是什么人','2008-10-1',1) +insert into BBSReply (RUID,RMsg,RTime,RTID) values(2,'它们的区别是什么','2008-11-1',2) +insert into BBSReply (RUID,RMsg,RTime,RTID) values(3,'最流行什么','2008-11-20',3) + + +select * from BBsReply --回帖表 +select * from BBsSection --版块表 +select * from BBsTopic --主帖表 +select * from BBsUsers --用户信息表 + + + +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select SID,UName,SName from BBSUsers inner join BBSSection on BBSUsers.UID=BBSSection.SUID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select TUID,UName,TTitle,TMsg,TTime from BBSUsers inner join BBSTopic on BBSUsers.UID=BBSTopic.TUID where TTime>2008-9-15 +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select SID,UName,SName,UAge from BBSUsers inner join BBSSection on BBSUsers.UID=BBSSection.SUID where BBSUsers.UAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 TUID,UNAme,TTitle,TMsg,Tcount from BBSTopic inner join BBSUsers on BBSTopic.TUID=BBSUsers.UID ORDER BY Tcount DESC +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select UName,SName,COUNT(*) from BBSTopic inner join BBSSection on BBSTopic.TUID=BBSSection.SUID inner join BBSUsers on BBSTopic.TUID=BBSUsers.UID group by UName,SName -- Gitee From de9d7cc8b74772229a6ac68a32a744f5121807e3 Mon Sep 17 00:00:00 2001 From: heiiii <1390105108@qq.com> Date: Sun, 28 Mar 2021 22:06:04 +0800 Subject: [PATCH 047/195] =?UTF-8?q?=E9=99=88=E6=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\231\210\346\227\255/SQLQuery1.sql" | 76 ++++++++++++++ .../\351\231\210\346\227\255/SQLQuery2.sql" | 90 +++++++++++++++++ .../\351\231\210\346\227\255/SQLQuery3.sql" | 98 +++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery1.sql" new file mode 100644 index 0000000..4024cdd --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery1.sql" @@ -0,0 +1,76 @@ +create database Studentinfo +on +( + name='Studentinfo', + filename='D:\Studentinfo.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='Studentinfo_log', + filename='D:\Studentinfo_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +use Studentinfo +go +create table StuDent +( + sTUNO varchar(15), + stuName nvarchar(20), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') +) + +insert into StuDent(sTUNO,stuName,stuAge,stuAddress,stuSeat,stuSex) +select 's2501','张秋里',20,'美国硅谷',1,'男' union +select 's2502','李斯文',18,'湖北武汉',2,'女' union +select 's2503','马文才',22,'湖南长沙',3,'男' union +select 's2504','欧阳俊雄',21,'湖北武汉',4,'女' union +select 's2505','梅超风',20,'湖北武汉',5,'男' union +select 's2506','陈旋风',19,'美国硅谷',6,'男' union +select 's2507','陈风',20,'美国硅谷',7,'女' + + +create table Score +( + examNO int, + stuNO varchar(15), + writtenExam int, + labExam int +) + + +insert into Score(examNO,stuNO,writtenExam,labExam) +select 1,'s2501','50','70' union +select 2,'s2502','60','65' union +select 3,'s2503','86','85' union +select 4,'s2504','40','80' union +select 5,'s2505','70','90' union +select 6,'s2506','85','90' + + + + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试,labExam 机试 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuDent.sTUNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO where writtenExam>60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuDent.sTUNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuDent left join Score on StuDent.sTUNO=Score.stuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO where stuAge>=20 order by writtenExam desc +--5.查询男女生的机试平均分 +select stuSex,avg(labExam)平均分 from Score left join StuDent on Score.stuNO=StuDent.sTUNO group by stuSex +--6.查询男女生的笔试总分 +select stuSex,sum(writtenExam)总分 from Score left join StuDent on Score.stuNO=StuDent.sTUNO group by stuSex + +select * from Score +select * from StuDent \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" new file mode 100644 index 0000000..c743c9a --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" @@ -0,0 +1,90 @@ +create database cc +on +( + name='cc', + filename='D:\cc.mdf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) +log on +( + name='cc_log', + filename='D:\cc.ldf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) +go +use cc +go +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) + +create table orders +( + orderId int primary key, + orderDate datetime +) +--插入表1数据 +insert into orders(orderId,orderDate) +select 1,'2008-01-12' union +select 2,'2008-02-10' union +select 3,'2008-02-15' union +select 4,'2008-03-10' +select * from orders +--订购项目表(orderItem),列为: +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) +create table orderItem +( + ItemiD int primary key identity(1,1), + orderId int, + itemType varchar(20), + itemName varchar(20), + theNumber int , + theMoney int +) +--添加表二的外键约束 关联表一的order id +alter table orderItem add constraint FK foreign key (orderId) references orders(orderId) +--插入表2数据 +insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) +select 1,'文具','笔',72,2 union +select 1,'文具','尺',10,1 union +select 1,'体育用品','篮球',1,56 union +select 2,'文具','笔',36,2 union +select 2,'文具','固体胶',20,3 union +select 2,'日常用品','透明胶',2,1 union +select 2,'体育用品','羽毛球',20,3 union +select 3,'文具','订书机',20,3 union +select 3,'文具','订书针',10,3 union +select 3,'文具','裁纸刀',5,5 union +select 4,'文具','笔',20,2 union +select 4,'文具','信纸',50,1 union +select 4,'日常用品','毛巾',4,5 union +select 4,'日常用品','透明胶',30,1 union +select 4,'体育用品','羽毛球',20,3 + +--使用上次作业的订单数据库,完成下列题目: +--订单表(orders) 订购项目表(orderItem) +select * from orders +select * from orderItem +--1.查询所有的订单的 订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orderItem.orderId 订单编号,orders.orderDate 日期,itemType 类别,itemName 产品名称,theNumber 数量,theMoney 单价 from orderItem inner join orders on orderItem.orderId=orders.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId 订单编号,theNumber 数量,orders.orderDate 日期,itemType 类别,itemName 产品名称 from orderItem inner join orders on orderItem.orderId=orders.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orders.orderDate 日期,itemName 产品名称,theNumber 数量,theMoney 单价 ,theMoney*theNumber 订购总价 +from orderItem inner join orders on orderItem.orderId=orders.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orderDate 日期,itemType 类别,itemName 产品名称,theNumber 数量,theMoney 单价 ,theMoney*theNumber 订购总价 + from orderItem inner join orders on orderItem.orderId=orders.orderId where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId 编号 ,count(itemName)订购产品数 from orderItem group by orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +select orderId,itemType 类别,count(itemType)次数,sum(theNumber)总数量 from orderItem group by orderId,itemType order by orderId asc \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery3.sql" new file mode 100644 index 0000000..c5ec325 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery3.sql" @@ -0,0 +1,98 @@ +create database bbs + +on +( + name='bbs', + filename='D:\bbs.mdf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='D:\bbs_log.ldf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +go +use bbs +go +create table bbsUsers +( + UIDD int identity, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +create table bbsSection +( + sIDD int identity, + sName varchar(10) not null, + sUid int +) + +alter table bbsUsers add constraint Pk_bbsUsers_UIDD primary key(UIDD) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uPoint check(uPoint>=0) + +alter table bbsSection add constraint Pk_bbsSection_sIDD primary key(sIDD) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UIDD) + +create table bbsTopic +( + tID int identity primary key, + tUID int foreign key references bbsUsers(UIDD), + tSID int foreign key references bbsSection(sIDD), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int identity primary key, + rUID int foreign key references bbsUsers(UIDD), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'),(3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), +(1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') + +insert into bbsReply values(3,2,'八嘎','2008-7-8'),(1,1,'python','2008-7-8'),(1,3,'上海','2008-7-8') + +--据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sIDD,uName,sName from bbsSection left join bbsUsers on sIDD=UIDD + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID,uName,tTitle,tMsg,tTime from bbsTopic left join bbsUsers on tID=UIDD where tTime > '2008-09-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sIDD,uName,sName,uAge from bbsSection left join bbsUsers on sIDD=UIDD where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tUID,uName,tTitle,tMsg,tCount from bbsUsers t left join bbsTopic x on t.UIDD=x.tID order by tCount desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select uName 用户名,sName 版块名称,count(*)发帖总数 from bbsTopic + inner join bbsUsers on bbsTopic.tUID = bbsUsers.UIDD + inner join bbsSection on bbsUsers.UIDD= bbsSection.sUid group by uName,sName + + + + +select * from bbsReply --回帖表 +select * from bbsSection --版块表 +select * from bbsTopic --主帖表 +select * from bbsUsers --用户信息表 \ No newline at end of file -- Gitee From 16dc0331e74d3fe77a6f3d25ddcfd1f9815ad875 Mon Sep 17 00:00:00 2001 From: xiangbianxiaozhu <1589953126@qq.com> Date: Sun, 28 Mar 2021 22:18:43 +0800 Subject: [PATCH 048/195] ll --- .../SQLQuery1.sql" | 120 ++++++++++++++++++ .../SQLQuery11.sql" | 112 ++++++++++++++++ .../SQLQuery2.sql" | 110 ++++++++++++++++ 3 files changed, 342 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery11.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery2.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" new file mode 100644 index 0000000..de27b0f --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" @@ -0,0 +1,120 @@ +use master +go +create database JXC +on +( name='JXC', + filename='D:\JXC.mdf', + size=20, + maxsize=100, + filegrowth=10% + ) + log on + ( name='JXC_log', + filename='D:\JXC_log.ldf', + size=20, + maxsize=100, + filegrowth=10% + ) + go + use JXC + go + create table orders + ( orderId int primary key identity(1,1), + orderDate datetime, + ) + insert into orders(orderDate) values('2008-01-12 ') + insert into orders(orderDate) values('2008-02-10 ') + insert into orders(orderDate) values('2008-02-15 ') + insert into orders(orderDate) values('2008-03-10 ') + + + create table orderItem + ( ItemiD int primary key identity, + orderId int , + itemType nvarchar(20), + itemName nvarchar(10), + theNumber int, + theMoney money + ) + + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (1,'文具','笔','72' ,'2' ) + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (1,'文具','尺','10' ,'1' ) + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (1,'体育用品','篮球','1','56' ) + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (2,'文具','笔','36','2') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (2,'文具','固体胶','20','3') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (2,'日常用品','透明胶','36','2') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (2,'体育用品','羽毛球','20','3') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (3,'文具','订书机','20','3') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (3,'文具','订书针','10','3') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (3,'文具','裁纸刀','5','5') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'文具','笔','20','2') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'文具','信纸','50','1') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'日常用品','毛巾','4','5') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'日常用品','透明胶','30','1') + insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) values (4,'体育用品','羽毛球','20','3' ) + + select *from orders + select *from orderItem + +--1.查询所有的订单的订单编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orderItem.orderId 订单编号 ,orderDate 订单日期, itemType 产品类别 , itemname 产品名称, theNumber 订购数量 ,theMoney 订购单价 from orderItem inner join orders on orderItem.orderId =orders.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 + +select orderItem.orderId 订单编号,orderDate 订单日期, itemType 产品类别 ,itemname 产品名称 , theNumber 订购数量 from orderItem inner join orders on orderItem.orderId =orders.orderId where theNumber>=50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orderItem.orderId 订单编号,orderDate 订单日期, itemType 产品类别 ,itemname 产品名称 , theNumber 订购数量,theMoney 订购单价,(theNumber)*(theMoney) 订购总价 + +from orderItem inner join orders on orderItem.orderId =orders.orderId group by orderItem.orderId ,orderDate ,itemType ,theNumber ,theMoney,itemname + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orderItem.orderId 订单编号,orderDate 订单日期, itemType 产品类别 ,itemname 产品名称 , theNumber 订购数量,theMoney 订购单价,(theNumber)*(theMoney) 订购总价 + + from orderItem inner join orders on orderItem.orderId =orders.orderId where theMoney>=5 and theNumber>=50 group by orderItem.orderId ,orderDate ,itemType ,theNumber ,theMoney,itemname + + --5.查询每个订单分别订购了几个产品,例如:编号 订购产品数 + -- 1 3 + -- 2 4 + +select orderId 订单编号,count(itemType) 产品数目 from orderItem group by orderId + + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +-- 订单编号 产品类别 订购次数 总数量 +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + + +select orderId 订单编号,itemType 产品类别 ,count( itemname) 订购次数 ,sum(theNumber) 订购数量 +from orderItem group by orderId,itemType + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery11.sql" "b/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery11.sql" new file mode 100644 index 0000000..39dbe93 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery11.sql" @@ -0,0 +1,112 @@ + +use master +go +create database L1 +on +( name='L1', + filename='D:\L1.mdf', + size=10, + maxsize=100, + filegrowth=10% + ) + log on + ( name='L1_log', + filename='D:\L1_log.ldf', + size=10, + maxsize=100, + filegrowth=10% + ) + go + use L1 + go + create table bbsUsers + (UID int identity(1,1), + uName varchar(10) not null, + uSex varchar(2) not null , + uAge int not null , + uPoint int not null , + ) + alter table bbsUsers add constraint PK_bbsUsers_UID primary key(UID) + alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) + alter table bbsUsers add constraint DK_bbsUsers_uSex check(uSex='男'or uSex='女') + alter table bbsUsers add constraint DK_bbsUsers_uAge check(uAge>=15 and uAge<=60) + alter table bbsUsers add constraint DK_bbsUsers_uPoint check(uPoint>=0) + + create table bbsSection + (sID int identity, + sName varchar(10) not null, + sUid int , + ) + alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) + alter table bbsSection add constraint FK_bbsSection_sUid foreign key (sUid) references bbsUsers (UID) + + + create table bbsTopic +( tID int primary key identity, + tUID int foreign key references bbsUsers (UID), + tSID int references bbsSection(sID) , + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime , + tCount int + ) +create table bbsReply +( rID int primary key identity, + rUID int foreign key references bbsUsers (UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime + ) + select * from bbsSection + insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) + select uName,uPoint into bbsPoint from bbsUsers + + insert into bbsSection values (' 技术交流',1),('读书世界' ,3),(' 生活百科',1),('八卦区' ,3) + insert into bbsTopic values(2,4,'范跑跑!','谁是范跑跑!', '2008-7-8',1),(3,2,'.NET!','与JAVA的区别是什么呀?','2008-9-1',2),(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10',0) + + insert into bbsReply values(3,1,'谁问的谁就是范跑跑','20210316'), + (1,2,'这个更简单','20210316'), + (1,3,'今年夏天最流行内裤外穿','20210316') + + +select * from bbsSection +select * from bbsReply +select * from bbsTopic +select * from bbsUsers + + +--1.查询出每个版块的版主编号,版主姓名和版块名称 + +select sid 版主编号, sName 板块名称 , uName 版主姓名 from bbsSection left join bbsUsers on bbsSection.sID=bbsUsers.UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 + +select bbsUsers.uName 版主姓名,bbsTopic.tTitle 贴标 ,bbsTopic.tMsg 帖内,bbsTopic.ttime 发帖时间 from bbsTopic right join bbsUsers on bbsTopic.tUID=bbsUsers.UID where + +bbsTopic.ttime >'2008-9-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 + +select sid 版主编号, sName 板块名称 , uName 版主姓名 from bbsSection left join bbsUsers on bbsSection.sID=bbsUsers.UID where bbsUsers.uAge <20 + + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 + +--select bbsUsers.uName 姓名 , bbsTopic.tTitle 贴标,bbsSection.sID 版主编号,bbsTopic.tMsg 帖内,bbsTopic.tCount from bbsTopic left join bbsUsers left join bbsSection on bbsUsers.UID = bbsSection.sUid + +--注:不会 + + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select tuid ,sum(tcount) from bbsTopic group by tuid + + + + + + + + + + diff --git "a/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery2.sql" new file mode 100644 index 0000000..0d9122b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery2.sql" @@ -0,0 +1,110 @@ +create database Zmt + +on +( +name='Zmt', +filename='D:\Zmt.mdf', +size=5mb, +maxsize=100mb, +filegrowth=10% +) + +log on + +( +name='Zmt_log', +filename='D:\Zmt_log.ldf', +size=5mb, +maxsize=100mb, +filegrowth=10% +) + +use Zmt + +create table Jxc +( +stuNo char(10) primary key, + +stuName char(10) not null, + +stuAge int not null , + +stuAddress char(10) not null , + +stuSeat int identity , + +steSex int check(steSex=1 or steSex=0), + +) + +create table J + +( + +esamNo int identity primary key , + +stuNO char(10) references Jxc(stuNo), + +writtenExam int not null, + +labExam int not null , + +) + + +insert into Jxc(stuNO,stuName,stuAge,stuAddress,steSex) values + +( 's2501','张秋利',20,'美国硅谷',1 ), + +('s2502','李思文',18,'湖北武汉',0), + +( 's2503','马文才',22,'湖南长沙',1 ), + +( 's2504','欧阳俊雄',21,'湖北武汉',0 ), + +( 's2505','梅超风',20,'湖北武汉',1 ), + +( 's2506','陈旋风',19,'美国硅谷',1 ), + +( 's2507','陈风',20,'美国硅谷',0) + +insert into J(stuNO,writtenExam,labExam) + +select 's2501',50,70 union + +select 's2502',60,65 union + +select 's2503',86,85 union + +select 's2504',40,80 union + +select 's2505',70,90 union + +select 's2506',85,90 + + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 + +select stuName 学生名字, stuAge 学生年龄, labExam 机试成绩, writtenExam 笔试成绩 from JXC left join j on Jxc.stuNo =J.stuNO + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 + +select j.stuNo 学号 ,stuName 学生名字 , labExam 机试成绩 ,writtenExam 笔试成绩 from Jxc,J where labExam>60 and writtenExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 + +select Jxc.stuNO 学号,stuName 学生名字 , labExam 机试成绩 ,writtenExam 笔试成绩 from jxc left join j on Jxc.stuNo =J.stuNO + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 + +select stuName 学生名字 ,stuAge 学生年龄, labExam 机试成绩 ,writtenExam 笔试成绩 from jxc left join j on Jxc.stuNo =J.stuNO where stuAge>=20 order by writtenExam desc + +--5.查询男女生的机试平均分 + +select (steSex) 性别 , avg (labExam) 机试平均成绩 from Jxc left join J on Jxc.stuNo =J.stuNO group by steSEX + +--6.查询男女生的笔试总分 + +select (steSex) 性别 , sum (labExam) 机试平总成绩 from Jxc left join j on Jxc.stuNo =J.stuNO group by steSEX -- Gitee From d4ae50a2364e6947c3f68fdb404b7bca173ab74c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E7=91=BE=E8=A8=80?= <2220660532@qq.com> Date: Sun, 28 Mar 2021 22:20:09 +0800 Subject: [PATCH 049/195] =?UTF-8?q?=E6=AE=B5=E5=97=A3=E5=87=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 133 ++++++++++++++++++ .../SQLQuery2.sql" | 101 +++++++++++++ .../SQLQuery3.sql" | 123 ++++++++++++++++ 3 files changed, 357 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery1.sql" new file mode 100644 index 0000000..707af6d --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery1.sql" @@ -0,0 +1,133 @@ +create database Student2 + +on +( + name='Student2', + filename='D:\Student2.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='Student2_log', + filename='D:\Student2_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +use student2 +go + +create table StuInfo +( + sTUNO varchar(15), + stuName nvarchar(20), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') +) + +insert into Stuinfo values ('2501','张秋利','20','美国硅谷','1','女') +insert into Stuinfo values ('2502','李斯文','18','湖北武汉','2','女') +insert into Stuinfo values ('2503','马文才','22','湖南长沙','3','男') +insert into Stuinfo values ('2504','欧阳俊雄','21','湖北武汉','4','男') +insert into Stuinfo values ('2505','梅超风','20','湖北武汉','5','女') +insert into Stuinfo values ('2506','陈旋风','19','美国硅谷','6','男') +insert into Stuinfo values ('2507','陈风','20','美国硅谷','7','男') + +create table Stuexam2 +( + examNO int, + stuNO varchar(15), + writtenExam varchar(200), + labExam varchar(200) +) + +insert into Stuexam2 values ('1','2501','50','70') +insert into Stuexam2 values ('2','2502','60','65') +insert into Stuexam2 values ('3','2503','86','85') +insert into Stuexam2 values ('4','2504','40','80') +insert into Stuexam2 values ('5','2505','70','90') +insert into Stuexam2 values ('6','2506','85','90') + +select sTUNO as 学号 , stuName as 姓名 , stuAge as 年龄 , stuAddress as 地址 , stuSeat as 座号, stuSex as 性别 from Stuinfo +select sTUNO 学号,stuName as 姓名 , stuAge as 年龄 , stuAddress as 地址 , stuSeat as 座号, stuSex as 性别 from Stuinfo +select 学号=sTUNO , 姓名=stuName , 年龄=stuAge , 地址=stuAddress , 座号= stuSeat, 性别= stuSex from Stuinfo + +select stuName , stuAge , stuAddress from Stuinfo + +select examNO as 考号 , stuNO as 学号 , writtenExam as 笔试成绩 , labExam as 机试成绩 from Stuexam2 +select examNO 考号,stuNO as 学号 , writtenExam as 笔试成绩 , labExam as 机试成绩 from Stuexam2 +select 考号=examNO , 学号=stuNO , 笔试成绩=writtenExam , 机试成绩= labExam from Stuexam2 + +select stuName+stuAddress+'@'+stuAddress as 邮箱 from Stuinfo + +select stuNO as 学号,writtenExam as 笔试 ,labExam as 机试, writtenExam+labExam as 总分 from Stuexam2 + +select stuName ,stuAddress from Stuinfo + +select stuAge as 所有年龄 from Stuinfo + +select top 3 * from Stuinfo + +select top 4 * from Stuinfo + +select top 50 percent * from Stuinfo + +select * from Stuinfo where stuAddress = '湖北武汉' and stuAge = 20 + +select * from Stuexam2 where labExam >=60 and labExam <= 80 order by labExam DESC + +select * from Stuinfo where stuAddress = '湖北武汉' or stuAddress='湖南长沙' + +select * from Stuexam2 where writtenExam >=70 and labExam <= 90 order by labExam ASC + +select * from Stuinfo where stuAge is null + +select * from Stuinfo where stuAge is not null + +select * from Stuinfo where stuName like '张%' + +select * from Stuinfo where stuName like '%胡%' + +select * from Stuinfo where stuName like '__俊%' + +select * from Stuinfo order by stuAge DESC + +select * from Stuinfo order by stuAge DESC , stuSeat ASC + +select top 1 * from Stuexam2 order by writtenExam desc + +select top 1 * from Stuexam2 order by writtenExam asc + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 + +select stuName 姓名,stuAge 年龄,writtenExam 笔试, labExam 机试 from StuInfo inner join Stuexam2 on StuInfo.sTUNO = Stuexam2.stuNO + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 + +select StuInfo.sTUNO 学号,stuName 姓名 , writtenExam 笔试, labExam 机试 from StuInfo inner join Stuexam2 on StuInfo.sTUNO = Stuexam2.stuNO where labExam>60 and writtenExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 + +select StuInfo.sTUNO 学号,stuName 姓名,writtenExam 笔试,labExam 机试 from StuInfo left join Stuexam2 on StuInfo.sTUNO =Stuexam2.stuNO + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 + +select stuName 姓名, stuAge 年龄, writtenExam 笔试 , labExam 机试 from StuInfo inner join Stuexam2 on StuInfo.sTUNO = Stuexam2.stuNO where stuAge>=20 + +--5.查询男女生的机试平均分 + +select stuSex 性别 , AVG(labExam) 平均分 from Stuexam2 inner join StuInfo on Stuexam2.stuNO=StuInfo.sTUNO group by stuSex + +--6.查询男女生的笔试总分 + +select stuSex 性别 , sum(writtenExam) 总分 from Stuexam2 inner join StuInfo on Stuexam2.stuNO=StuInfo.sTUNO group by stuSex + +alter table Stuexam2 alter column labExam int + +alter table Stuexam2 alter column writtenExam int \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery2.sql" new file mode 100644 index 0000000..a9918ea --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery2.sql" @@ -0,0 +1,101 @@ +use master +go + +create database order1 +on +( +name='order1', +filename='D:\sql.mdf', +size=5MB, +filegrowth=10MB, +maxsize=50MB +) +log on +( +name='order1_log', +filename='D:\sql.ldf', +size=5MB, +filegrowth=10MB, +maxsize=50MB +) +go + +use order1 +go + +create table orders +( +orderID int primary key identity(1,1) not null, +orderDate datetime not null +) + +create table orderItem +( +itemID int primary key identity(1,1) not null, +orderid int not null, +itemType varchar(20) not null, +itemName varchar(20) not null, +theNumber int not null, +theMoney money not null +) + +insert into orders values ('2008-01-12 00:00.000'), +('2008-02-10 00:00.000'),('2008-02-15 00:00.000'), +('2008-03-10 00:00.000') + +insert into orderItem values(1,'文具','笔','72','2'), +(1,'文具','尺','10','1'),(1,'体育用品','篮球','1','56'), +(2,'文具','笔','36','2'),(2,'文具','固体胶','20','3'), +(2,'日常用品','透明胶','2','1'),(2,'体育用品','羽毛球','20','3'), +(3,'文具','订书机','20','3'),(3,'文具','订书针','10','3'), +(3,'文具','裁纸刀','5','5'),(4,'文具','笔','20','2'), +(4,'文具','信纸','50','1'),(4,'日常用品','毛巾','4','5'), +(4,'日常用品','透明胶','30','1'),(4,'体育用品','羽毛球','20','3') + +select sum(theNumber) from orderItem + +select orderid 订单编号,theNumber 所有物品数量,AVG(theMoney) 平均单价 from orderItem group by orderid,theNumber having orderid<3 and AVG(theMoney)<10 order by orderid asc + +select theNumber 所有物品数量,AVG(theMoney) 平均单价 from orderItem group by theNumber having theNumber>50 and AVG(theMoney)<10 + +select itemType 商品类别 , theNumber 订购次数 from orderItem group by itemType,theNumber + +select itemType 物品类别 , sum(theNumber) 总数量 ,AVG(theMoney) 平均单价 from orderItem group by itemType having sum(theNumber)>100 + +select itemName 产品名称 , count(theNumber) 订购次数, sum(theNumber) 总数量 , AVG(theMoney) 平均单价 from orderItem group by itemName + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orderItem.orderid 编号,orderDate 日期,itemType 类别 , itemName 名称, theNumber 数量,theMoney 单价 from orderItem inner join orders on orderItem.orderid=orders.orderID + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 + +select orderItem.orderid 编号, orderDate 日期,itemType 类别,itemName 名称 from orderItem inner join orders on orderItem.orderid=orders.orderID where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orderItem.orderid 编号, orderDate 日期, itemType 类别, itemName 名称, theNumber 数量,theNumber* theMoney 总价 from orderItem inner join orders on orderItem.orderid=orders.orderID group by orderItem.orderid,orderDate,itemType,itemName,theNumber,theMoney + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orderItem.orderid 编号,orderDate 日期,itemType 类别 , itemName 名称, theNumber 数量,theMoney 单价,theNumber*theMoney 总价 from orderItem inner join orders on orderItem.orderid=orders.orderID where theMoney>=5 and theNumber>=50 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 + +select orderid 编号,theNumber 产品数 from orderItem group by orderid,theNumber + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderid 编号,itemType 类别, count(theNumber) 次数 ,theNumber 总数量 from orderItem group by orderid,itemType, theNumber \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery3.sql" new file mode 100644 index 0000000..abd6e28 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery3.sql" @@ -0,0 +1,123 @@ +create database bbs +on +( +name='bbs', +filename='D:\sql4.mdf', +size=5mb, +maxsize=50mb, +filegrowth=10mb +) +log on +( +name='bbs_log', +filename='D:\sql4.ldf', +size=5mb, +maxsize=50mb, +filegrowth=10mb +) +go + +use bbs +go + +create table bbsUsers +( +UID int identity(1,1), +uName varchar(10) not null, +uSex varchar(2) not null, +uAge int not null, +uPoint int not null +) + +alter table bbsUsers add constraint PK_UID primary key(UID) +alter table bbsUsers add constraint uName unique(uName) +alter table bbsUsers add constraint uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint uPoint check(uPoint>=0) + +create table bbsTopic +( +tID int primary key identity(1,1), +tUID int foreign key references bbsUsers(UID), +tSID int foreign key references bbsSection(sID), +tTitle varchar(100) not null, +tMsg text not null, +tTime datetime , +tCount int +) + +create table bbsReply +( +rID int primary key identity(1,1), +rUID int foreign key references bbsUsers(UID), +rTID int foreign key references bbsTopic(tID), +rMsg text not null, +rTime datetime +) + +create table bbsSection +( +sID int identity(1,1), +sName varchar(10) not null, +sUid int +) + +alter table bbsSection add constraint Pk_sID primary key (sID) +alter table bbsSection add constraint CK_sUid foreign key (sUid) references bbsUsers(UID) + +insert into bbsUsers values('小雨点','女','20','0') +insert into bbsUsers values('逍遥','男','18','4') +insert into bbsUsers values('七年级生','男','19','2') + +select uName,uSex from bbsUsers + +select uName,uPoint into bbsPoint from bbsUsers + +select * from bbsSection + +insert into bbsSection (sName,sUid) +values('技术交流',1), + ('读书世界',3), + ('生活百科',1), + ('八卦区',3) + +insert into bbsTopic( tUID,tSID,tTitle,tMsg,tTime,tCount ) +values (2,4,'范跑跑','谁是范跑跑','2008-7-8','1'),(3,1,'.NET','与JAVA的区别是什么','2008-9-1','2'), +(1,3,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10','0') + +insert into bbsReply(rMsg,rTime,rUID) values +('他是范跑跑','2008-7-9',1), +('不知道','2008-9-2',2), +('不知道','2008-9-11',3) + +alter table bbsReply drop constraint FK__bbsReply__rUID__30F848ED +alter table bbsTopic drop constraint FK__bbsTopic__tUID__2D27B809 +delete bbsUsers where uName='逍遥' + +update bbsUsers set upoint =12 where uName='小雨点' + +alter table bbsTopic drop constraint FK__bbsTopic__tSID__2E1BDC42 +delete bbsSection where sName = '生活百科' + +delete bbsReply + + +--1.查询出每个版块的版主编号,版主姓名和版块名称 + +select UID 版主编号,uName 姓名,sName 名称 from bbsSection inner join bbsUsers on bbsSection.sUid=bbsUsers.UID + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 + +select tUID 版主编号,uName 姓名,tTitle 标题,tMsg 内容,tTime 时间 from bbsTopic inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 + +select tID 编号,sName 名称,uName 姓名 from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 + +select top 1 tID 发帖人编号,uName 姓名,tTitle 标题,tMsg 内容,tCount 数量 from bbsTopic inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID order by tCount DESC + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select tSID 版块,tUID 用户,count(tSID) 发帖总数 from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on bbsTopic.tUID=bbsUsers.UID group by tSID,tUID \ No newline at end of file -- Gitee From cf0498509811a2af12714c6f48be35c4caf2afd2 Mon Sep 17 00:00:00 2001 From: yiQ <1325307033@qq.com> Date: Sun, 28 Mar 2021 22:33:41 +0800 Subject: [PATCH 050/195] =?UTF-8?q?=E5=91=A8=E6=9C=AB=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\273\203\344\271\2401.sql" | 66 +++++++++++++++ .../\347\273\203\344\271\2402.sql" | 84 +++++++++++++++++++ .../\347\273\203\344\271\2403.sql" | 20 +++++ 3 files changed, 170 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2401.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2402.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2403.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2401.sql" "b/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2401.sql" new file mode 100644 index 0000000..0f538c0 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2401.sql" @@ -0,0 +1,66 @@ +create database Student +on +( + name='Student', + filename='D:\SQL\Student.mdf' +) +log on +( + name='Student_log', + filename='D:\SQL\Student_log.ldf' +) +go + +create table StuInfo +( + stuNo char(5) primary key(stuNo), + stuName nvarchar(20), + stuAge int, + stuAddress text, + stuSeat int identity(1,1), + stuSex char(1) check(stuSex in(1,0)) +) + +create table StuExam +( + examNo int identity(1,1), + stuNo char(5), + writtenExam int check(writtenExam>=0 and writtenExam<=100), + labExam int check(labExam>=0 and labExam<=100) +) + + alter table StuExam add constraint RK_StuExam_stuNo foreign key(stuNo) references StuInfo(stuNo) + + insert into StuInfo 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 values + ('s2501',50,70),('s2502',60,65),('s2503',86,85),('s2504',40,80),('s2505',70,90),('s2506',85,90) + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select i.stuNo 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuInfo i left join StuExam e +on i.stuNo=e.stuNo where writtenExam>60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i left join StuExam e on i.stuNo=e.stuNo +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +where stuAge>=20 order by writtenExam DESC +--5.查询男女生的机试平均分 +select stuSex 性别,avg(labExam) 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +where stuAge>=20 group by stuSex +--6.查询男女生的笔试总分 +select stuSex 性别,sum(writtenExam) 笔试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2402.sql" "b/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2402.sql" new file mode 100644 index 0000000..59a3de1 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2402.sql" @@ -0,0 +1,84 @@ +create database Assignment +on +( + name='Assignment', + filename='D:\SQL\Assignment.mdf' +) +log on +( + name='Assignment_log', + filename='D:\SQL\Assignment_log.ldf' +) +go + +use Assignment +go +--drop table orderItem +create table orders +( + orderId int primary key, + orderDate date +) + +create table orderItem +( + ItemiD int identity(1,1) primary key, + orderId int references orders(orderId), + itemType varchar(12), + itemName varchar(12), + theNumber int, + theMoney money +) +insert into orders values + (1,'2008-01-12'), + (2,'2008-02-10'), + (3,'2008-02-15'), + (4,'2008-03-10') +insert into orderItem values + (1,'文具','笔',72,2), + (1,'文具','尺',10,1), + (1,'体育用品','篮球',1,56), + (2,'文具','笔',36,2), + (2,'文具','固体胶',20,3), + (2,'日常用品','透明胶',2,1), + (2,'体育用品','羽毛球',20,3), + (3,'文具','订书机',20,3), + (3,'文具','订书针',10,3), + (3,'文具','裁纸刀',5,5), + (4,'文具','笔',20,2), + (4,'文具','信纸',50,1), + (4,'日常用品','毛巾',4,5), + (4,'日常用品','透明胶',30,1), + (4,'体育用品','羽毛球',20,3) +-- 使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价 +from orders o inner join orderItem i on o.orderId=i.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称 +from orders o inner join orderItem i on o.orderId=i.orderId +where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 +from orders o inner join orderItem i on o.orderId=i.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 +from orders o inner join orderItem i on o.orderId=i.orderId +where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select o.orderId 订单编号,count(*) from orders o inner join orderItem i on o.orderId=i.orderId group by o.orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select o.orderId 订单编号,itemType 订购类别,count(*) 订购次数,sum(theNumber) 总数量 +from orders o inner join orderItem i on o.orderId=i.orderId group by o.orderId,itemType order by o.orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2403.sql" "b/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2403.sql" new file mode 100644 index 0000000..46670cb --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/\347\273\203\344\271\2403.sql" @@ -0,0 +1,20 @@ +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 +from bbsSection bs inner join bbsUsers bu +on sUid=bu.UID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTitle 贴子的标题,tMsg 帖子的内容,tTime 发帖时间 +from bbsTopic bs inner join bbsUsers bu +on tUID=bu.UID where tTime>'2008-9-15' +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 +from bbsSection bs inner join bbsUsers bu +on sUid=bu.UID where uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select tUID 发帖人编号,uName 发帖人姓名,tTitle 贴子的标题,tMsg 帖子的内容,tCount 回复数量 +from bbsTopic bs inner join bbsUsers bu +on tUID=bu.UID where tCount=(select max(tCount) from bbsTopic) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select sName,uName 用户名,count(tUID ) 发帖总数 +from bbsSection S left join bbsUsers U on sUid =UID left join bbsTopic T on sID =tUID group by sName,uName -- Gitee From 4f01bdf4e55fe781dd854fda6e4d8f6f0e2f6e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=8F=B6=E5=B8=85?= <2876015251@qq.com> Date: Sun, 28 Mar 2021 22:40:07 +0800 Subject: [PATCH 051/195] sql10 --- .../SQLQuery1.sql" | 72 +++++++++++++ .../SQLQuery2.sql" | 75 +++++++++++++ .../SQLQuery3.sql" | 101 ++++++++++++++++++ 3 files changed, 248 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" new file mode 100644 index 0000000..faecf51 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" @@ -0,0 +1,72 @@ +use master +go + +create database Student2 +on +( + name='Student2', + filename='D:\meiguo\Student2.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='Student2_log', + filename='D:\meiguo\Student2_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use Student2 +go +create table StuInfo +( + StuNo varchar(20) primary key , + StuName nchar(20) not null, + StuAge int not null, + StuAdress varchar(20) not null, + StuSeat int not null, + StuSex char(2) not null +) +go + +insert into StuInfo(StuNo,StuName,StuAge,StuAdress,StuSeat,StuSex) values +('s2501','张秋利',20,'美国硅谷',1,1),('s2502','李斯文',18,'湖北武汉',2,0), +('s2503','马文才',22,'湖南长沙',3,1),('s2504','欧阳俊雄',21,'湖北武汉',4,0), +('s2505','梅超风',20,'湖北武汉',5,1),('s2506','陈旋风',19,'美国硅谷',6,1), +('s2507','陈风',20,'美国硅谷',7,0),('s2508','张三',20,'伊拉克',8,0) +go + +use Student2 +go +create table Score +( + ExamNo int primary key identity(1,1), + StuNO varchar(20) not null, + WrittenExam int not null, + LabExam int not null +) +go + +insert into Score(StuNo,WrittenExam,LabExam) values +('s2501',50,70),('s2502',60,65),('s2503',86,85), +('s2504',40,80),('s2505',70,90),('s2506',85,90), +('s2507','',''),('s2508','','') +select * from Score +select * from StuInfo +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select Stuname 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from StuInfo inner join Score on StuInfo.StuNo=Score.StuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuInfo.StuNo 学号 ,StuName 姓名, WrittenExam 笔试成绩,LabExam 机试成绩 from Score inner join StuInfo on StuInfo.StuNo=Score.StuNo where WrittenExam>60 and LabExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以0值填充 +select StuInfo.StuNo 学号 ,StuName 姓名, WrittenExam 笔试成绩,LabExam 机试成绩 from StuInfo inner join Score on StuInfo.StuNo=Score.StuNo where WrittenExam=0 and LabExam=0 +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName 姓名 ,StuAge 年龄, WrittenExam 笔试成绩,LabExam 机试成绩 from StuInfo inner join Score on StuInfo.StuNo=Score.StuNo where StuAge>=20 order by WrittenExam +--5.查询男女生的机试平均分 +select StuSex 性别, avg(LabExam)机试平均分 from StuInfo inner join Score on StuInfo.StuNo=Score.StuNo group by StuSex +--6.查询男女生的笔试总分 +select StuSex 性别, sum(WrittenExam)笔试总分 from StuInfo inner join Score on StuInfo.StuNo=Score.StuNo group by StuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" new file mode 100644 index 0000000..25674f5 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" @@ -0,0 +1,75 @@ +use master +go +create database market +on( + name=' market', + filename='D:\bank\ market.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +log on( + name=' market_log', + filename='D:\bank\ market_log.ldf', + size=5, + maxsize=100, + filegrowth=10% +) +USE market +go +create table orders +( + orderId int primary key identity not null, + orderDate datetime not null, +) +create table orderItem +( + ItemiD int primary key identity not null, + orderId int references orders(orderId) not null, + itemType nvarchar(10) not null, + itemName nvarchar(10) not null, + theNumber int not null, + theMoney int not null, +) + +insert into orders values('2008-01-12'),('2008-02-10'),('2008-02-15'),('2008-03-10') +insert into orderItem values +(1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'日常用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书针',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'日常用品','毛巾',4,5), +(4,'日常用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) +select * from orders +select * from orderItem +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney from orders inner join orderItem on orders.orderId=orderItem.orderid +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId,orderDate,itemType,itemName from orders inner join orderItem on orders.orderId=orderItem.orderid where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及 订购总价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber*theMoney 订购总价 from orderItem inner join orders on orderItem.orderId=orders.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select from orders inner join orderItem on orderItem.orderId=orders.orderId where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: + -- 编号 订购产品数 + -- 1 3 + -- 2 4 +select orderId 编号 ,count(*) 次数 from orderItem group by orderId +--6.查询每个订单里的每个类别的产品 分别订购了几次 和 总数量,例如: + + --订单编号 产品类别 订购次数 总数量 + -- 1 文具 2 82 + -- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select orderId 编号,itemType,count(*)订购次数,sum(theNumber)总数量 from orderItem group by orderId ,itemType order by orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery3.sql" new file mode 100644 index 0000000..d7d532a --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery3.sql" @@ -0,0 +1,101 @@ +create database bbs + +on +( + name='bbs', + filename='D:\bbs.mdf', + size=10mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='D:\bbs_log.ldf', + size=10mb, + maxsize=100mb, + filegrowth=10mb +) +go +use bbs +go +create table bbsUsers +( + UIDD int identity, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +create table bbsSection +( + sIDD int identity, + sName varchar(10) not null, + sUid int +) + +alter table bbsUsers add constraint Pk_bbsUsers_UIDD primary key(UIDD) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uPoint check(uPoint>=0) + +alter table bbsSection add constraint Pk_bbsSection_sIDD primary key(sIDD) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UIDD) + +create table bbsTopic +( + tID int identity primary key, + tUID int foreign key references bbsUsers(UIDD), + tSID int foreign key references bbsSection(sIDD), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int identity primary key, + rUID int foreign key references bbsUsers(UIDD), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'),(3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), +(1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') + +insert into bbsReply values(3,2,'八嘎','2008-7-8'),(1,1,'python','2008-7-8'),(1,3,'上海','2008-7-8') + + + +select * from bbsReply --回帖表 +select * from bbsSection --版块表 +select * from bbsTopic --主帖表 +select * from bbsUsers --用户信息表 + + +--据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sIDD,uName,sName from bbsSection left join bbsUsers on sIDD=UIDD + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID,uName,tTitle,tMsg,tTime from bbsTopic left join bbsUsers on tID=UIDD where tTime > '2008-09-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sIDD,uName,sName,uAge from bbsSection left join bbsUsers on sIDD=UIDD where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tUID,uName,tTitle,tMsg,tCount from bbsUsers t left join bbsTopic x on t.UIDD=x.tID order by tCount desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select uName 用户名,sName 版块名称,count(*)发帖总数 from bbsTopic inner join bbsUsers on bbsTopic.tUID = bbsUsers.UIDD + inner join bbsSection on bbsUsers.UIDD= bbsSection.sUid group by uName,sName + + + + -- Gitee From 5e980b9abff829c0731a0c06150dd1d0a36f8e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BA=8C=E6=9F=B1?= <2964399941@qq.com> Date: Sun, 28 Mar 2021 22:42:47 +0800 Subject: [PATCH 052/195] =?UTF-8?q?=E6=9D=8E=E5=98=89=E5=9F=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5.sql" | 192 ++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery5.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery5.sql" "b/20210326\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery5.sql" new file mode 100644 index 0000000..7fbc34e --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery5.sql" @@ -0,0 +1,192 @@ +use master +go +create database task +go +use task +go +create table Student +( +stuid nvarchar(10) primary key, +stuname nvarchar(5) not null , +stuage int , +stuaddress nvarchar(200), +stuseat int identity(1,1), +stusex int check(stusex=1 or stusex=0) +) +create table result +( +examn0 int primary key identity(1,1), +stuid nvarchar(10) references Student(stuid), +writtenexam int check(writtenexam>=0 or writtenexam<=100), +labexam int check(labexam>=0 or labexam<=100) +) + +insert into Student +select 's2501','张秋利','20','美国硅谷','1' union +select 's2502','李斯文','18','湖北武汉','0' union +select 's2503','马文才','22','湖南长沙','1' union +select 's2504','欧阳俊雄','21','湖北武汉','0' union +select 's2505','梅超风','20','湖北武汉','1'union +select 's2506','陈旋风','19','美国硅谷','1' union +select 's2507','陈风','20','美国硅谷','0' +select * from Student +insert into result +select 's2501','50','70' union +select 's2502','60','65' union +select 's2503','86','85' union +select 's2504','40','80' union +select 's2505','70','90' union +select 's2506','85','90' +select * from result + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuname 姓名,stuage 年龄,r.writtenexam 笔试成绩,r.labexam 机试成绩 from Student s inner join result r on s.stuid=r.stuid +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select s.stuname 姓名,s.stuid 学号 ,writtenexam 笔试成绩,labexam 机试成绩 from result r inner join Student s on s.stuid=r.stuid where writtenexam>60 and labexam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select s.stuid 学号,s.stuname 姓名, writtenexam 笔试成绩,labexam 机试成绩 from Student s left join result r on s.stuid=r.stuid +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuname 姓名,stuage 年龄,r.writtenexam 笔试成绩,r.labexam 机试成绩 from Student s inner join result r on s.stuid= r.stuid where s.stuage>=20 order by writtenexam desc +--5.查询男女生的机试平均分 +select avg(r.labexam) 机试平均分,stusex 性别 from Student s inner join result r on s.stuid=r.stuid group by stusex +--6.查询男女生的笔试总分 +select stusex 性别,sum(r.writtenexam) 笔试总分 from Student s inner join result r on s.stuid=r.stuid group by stusex + + +use Students +go +create table orders +( + orderId int primary key identity, + orderDate datetime, +) + +create table orderItem +( + ItemiD int primary key identity, + orderId int references orders(orderId), + itemType nvarchar(20), + itemName nvarchar(20), + theNumber int, + theMoney money +) + +insert into orders 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 values(1,'文具','笔',72,'2'), +(1,'文具','尺',10,'1'), +(1,'体育用品','篮球',1,'56'), +(2,'文具','笔',36,'2'), +(2,'文具','固体胶',20,'3'), +(2,'日常用品','透明胶',2,'1'), +(2,'体育用品','羽毛球',20,'3'), +(3,'文具','订书机',20,'3'), +(3,'文具','订书针',20,'3'), +(3,'文具','裁纸刀',5,'5'), +(4,'文具','笔',20,'2'), +(4,'文具','信封',50,'1'), +(4,'日常用品','毛巾',4,'5'), +(4,'日常用品','透明胶',30,'1'), +(4,'体育用品','羽毛球',20,'3') +select * from orders +select * from orderItem +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select * from orderItem inner join orders on orderItem.orderId=orders.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderId,orderDate,itemName,itemType from orderItem inner join orders on orderItem.orderId=orders.orderId +where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber * theMoney 订购总价 +from orderItem inner join orders on orderItem.orderId=orders.orderId +group by orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney,theNumber * theMoney 订购总价 +from orderItem inner join orders on orderItem.orderId=orders.orderId where theMoney>5 and theNumber>50 +group by orderItem.orderId,orderDate,itemType,itemName,theNumber,theMoney +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderID,sum(theNumber) 订购产品数 from orderItem group by orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 + --2 日常用品 1 20 +select * from orderItem +select orderId,itemType,count(ItemName) 订购次数,sum(theNumber) 总数量 from orderItem group by orderId,itemType + +use Students +go +create table bbsUsers +( + uID int identity(1,1) not null , + uName nvarchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null + +) +alter table bbsUsers add constraint PK_bbsUsers_uID primary key(uID) +alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 or uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) +create table bbsSection +( + sID int identity(1,1) not null , + sName varchar(10) not null, + sUid int , + +) +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid)references bbsUsers(uID) +create table bbsTopic +( + tID int primary key identity(1,1) not null, + tUID int references bbsUsers(uID) not null , + tSID int references bbsSection(sID) , + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime not null, + tCount int not null, +) +create table bbsReply +( + rID int primary key identity(1,1) not null, + rUID int references bbsUsers(uID) , + rTID int references bbsTopic(tID) , + rMsg text not null, + rTime datetime , +) +go +use Students +go +select * from bbsSection +select * from bbsReply +select * from bbsTopic +select * from bbsUsers +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +insert into bbsSection values('技术名流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑','谁是范跑跑', 2008-7-8,1),(3,2,'.NET','与JAVA的区别是什么呀?',2008-9-1,2),(1,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0) +insert into bbsReply values(2,2,'一名地震自己先跑的教师',2008-7-8),(3,3,'不知道',2008-9-1),(1,1,'流行穿黑裙子',2008-9-10) +update bbsUsers set uPoint=30 where uName='小雨点' + +--1.查询出每个版块的版主编号 suid,版主姓名 uname和版块名称sname +select bbsSection.sUid 版主编号,bbsUsers.uName 版主姓名,bbsSection.sName 版块名称 from bbsSection inner join bbsUsers on bbsSection.sUid=bbsUsers.uuID +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select bt.tUID 编号,bu.uName 姓名,bt.tTitle 标题,bt.tMsg 内容,bt.tTime 时间 from bbsTopic bt inner join bbsUsers bu on bt.tUID=bu.uuID where bt.tTime<2008-9-15 +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select bs.sUid 编号,bu.uName 名称,bs.sName 版块的名称 from bbsUsers bu inner join bbsSection bs on bs.sUid=bu.uuID where bu.uAge<20 +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select max(bt.tCount) ,bt.tUID,bu.uName,bt.tTitle,bt.tMsg from bbsTopic bt inner join bbsUsers bu on bt.tUID=bu.uuID group by tUID,bu.uName,tTitle,tMsg,max(bt.tCount) +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select tSID 版块,tUID 用户,count(tSID) 发帖总数 from bbsTopic inner join bbsSection on sID=tID inner join bbsUsers on tUID=uID group by tSID,tUID \ No newline at end of file -- Gitee From 0bc8d93dee36b43e3b44457b47a4729604efc54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= <3148578490@qq.com> Date: Sun, 28 Mar 2021 22:49:17 +0800 Subject: [PATCH 053/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=BB=84=E6=96=87?= =?UTF-8?q?=E8=81=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\273\204\346\226\207\350\201\252/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" "b/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 407329904516402768615690f76a6c889d758bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= <3148578490@qq.com> Date: Sun, 28 Mar 2021 22:50:07 +0800 Subject: [PATCH 054/195] =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...6\350\241\250\346\237\245\350\257\242.sql" | 168 ++++++++++++++++++ ...6\350\241\250\346\237\245\350\257\242.sql" | 90 ++++++++++ ...6\350\241\250\346\237\245\350\257\242.sql" | 168 ++++++++++++++++++ 3 files changed, 426 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery-\345\255\246\347\224\237\344\277\241\346\201\257\350\277\236\350\241\250\346\237\245\350\257\242.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\350\256\242\350\264\255\350\277\236\350\241\250\346\237\245\350\257\242.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\350\256\272\345\235\233\350\277\236\350\241\250\346\237\245\350\257\242.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery-\345\255\246\347\224\237\344\277\241\346\201\257\350\277\236\350\241\250\346\237\245\350\257\242.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery-\345\255\246\347\224\237\344\277\241\346\201\257\350\277\236\350\241\250\346\237\245\350\257\242.sql" new file mode 100644 index 0000000..26513e0 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery-\345\255\246\347\224\237\344\277\241\346\201\257\350\277\236\350\241\250\346\237\245\350\257\242.sql" @@ -0,0 +1,168 @@ +use master +go +create database bbs +on +( + name='bbs', + filename='D:\SQL作业\SQL作业8\bbs.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='bbs_log', + filename='D:\SQL作业\SQL作业8\bbs_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use bbs +create table bbsUsers +( + UID int identity(1,1), + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +go + +alter table bbsUsers add constraint PK_bbsUsers_UID primary key (UID) +alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) + + +use bbs +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) +go + +alter table bbsSection add constraint PK_bbsSection_sID primary key (sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + +use bbs +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int constraint FK_bbsUsers_UID references bbsUsers(UID), + tSID int constraint FK_bbsSection_sID references bbsSection(sID), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +go + +use bbs +create table bbsReply +( + rID int primary key identity(1,1), + rUID int constraint FK_bbsReply_rUID references bbsUsers(UID), + rTID int constraint FK_bbsTopic_tID references bbsTopic(tID), + rMsg text not null, + rTime datetime +) +go + + +--1.现在有3个会员注册成功,请用一次插入多行数据的方法向bbsUsers表种插入3行记录,记录值如下: +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +--2.将bbsUsers表中的用户名和积分两列备份到新表bbsPoint表中,提示查询部分列:select 列名1,列名2 from 表名 +select uName,uPoint into bbsPoint from bbsUsers +--3.给论坛开设4个板块 +-- 名称 版主名 +-- 技术交流 小雨点 +-- 读书世界 七年级生 +-- 生活百科 小雨点 +-- 八卦区 七年级生 +insert into bbsSection values ('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) + +select * from bbsUsers +--4.向主贴和回帖表中添加几条记录 + +-- 主贴: + +-- 发帖人 板块名 帖子标题 帖子内容 发帖时间 回复数量 +-- 逍遥 八卦区 范跑跑 谁是范跑跑 2008-7-8 1 +-- 七年级生 技术交流 .NET 与JAVA的区别是什么呀? 2008-9-1 2 +-- 小雨点 生活百科 今年夏天最流行什么 有谁知道今年夏天最流行 2008-9-10 0 +-- 什么呀? + +-- 回帖: +-- 分别给上面三个主贴添加对应的回帖,回帖的内容,时间,回帖人自定 +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) values +(2,2,'范跑跑','谁是范跑跑','2008-7-8',1),(3,3,'.NET','与JAVA的区别是什么呀?','2008-9-1',2), +(1,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10',0) +--5.因为会员“逍遥”发表了非法帖子,现将其从论坛中除掉,即删除该用户,请用语句实现(注意主外键,要删除主键,先要将引用了该主键的外键数据行删除) +alter table bbsTopic drop constraint FK_bbsUsers_UID +delete from bbsUsers where uName='逍遥' +--6.因为小雨点发帖较多,将其积分增加10分 +update bbsUsers set uPoint=10 where uName='小雨点' +--7.因为板块“生活百科”灌水的人太少,现决定取消该板块,即删除(注意主外键) +alter table bbsTopic drop constraint FK_bbsSection_sID +delete from bbsSection where sName='生活百科' +--8.因回帖积累太多,现需要将所有的回帖删除 +delete from bbsReply + + +select * from bbsTopic--主贴表 +select * from bbsSection--版块表 +select * from bbsUsers--用户信息表 +select * from bbsReply--回帖表 + +--在论坛数据库中完成以下题目 + +--1.在主贴表中统计每个版块的发帖总数 +select tSID 发帖总数,count(*) from bbsTopic group by tSID +select * from bbsTopic--主贴表 + +--2.在回帖表中统计每个主贴的回帖总数量 +select rTID 主贴编号,count(*)回帖数量 from bbsReply group by rTID +select * from bbsReply--回帖表 + +--3.在主贴表中统计每个用户的发的主帖的总数 +select tUID 用户编号,count(*)发贴总数 from bbsTopic group by tUID +select * from bbsTopic--主贴表 + +--4.在主贴表中统计每个用户发的主贴的回复数量总和 +select * from bbsTopic--主贴表 +select tUID 用户编号,sum(tCount)回帖总数 from bbsTopic group by tUID + +--5.在主贴表中查询每个版块的主贴的平均回复数量大于3的版块的平均回复数量 +select * from bbsTopic--主贴表 +select tSID 板块编号,avg(tCount)平均回复数 from bbsTopic group by tSID having avg(tCount)>3 + +--6.在用户信息表中查询出积分最高的用户的用户名,性别,年龄和积分 +select * from bbsUsers--用户信息表 +select top 1 uName 用户名,uSex 性别,uAge 年龄,uPoint 积分 from bbsUsers group by uName,uSex,uAge,uPoint + +--7.在主贴表中(bbsTopic)中将帖子的内容或标题中有“快乐”两字的记录查询出来 +select * from bbsTopic--主贴表 +select tTitle 标题,tMsg 内容 from bbsTopic where tTitle like '%快乐%' or tMsg like '%快乐%' + +--8.在用户信息表(bbsUsers)中将用户年龄在15-20之间并且积分在10分以上的优秀用户查询出来(用多种方法实现) +select * from bbsUsers--用户信息表 +select * from bbsUsers where uAge between 15 and 20 and uPoint>10 +select * from bbsUsers where uAge>15 and uAge<20 and uPoint>10 + +--9.在用户信息表(bbsUsers)中将用户名的第一个字为“小”,第三字为“大”的用户信息查询出来 +select * from bbsUsers--用户信息表 +select * from bbsUsers where uName='小_大' + +--10.在主贴表(bbsTopic)中将在2008-9-10 12:00:00 以后发的并且回复数量在10以上的帖子的标题和内容查询出来,并且为列取上对应的中文列名 +select * from bbsTopic--主贴表 +select tID 主贴编号,tTitle 贴子标题,tMsg 帖子内容 from bbsTopic where tTime>'2008-9-10 12:00:00' and tCount>10 + +--11.在主贴表(bbsTopic)中将帖子的标题是以‘!’结尾的帖子的发帖人编号和回复数量查询出来 +select * from bbsTopic--主贴表 +select tUID,tCount from bbsTopic where tTitle like '%!' \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\350\256\242\350\264\255\350\277\236\350\241\250\346\237\245\350\257\242.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\350\256\242\350\264\255\350\277\236\350\241\250\346\237\245\350\257\242.sql" new file mode 100644 index 0000000..931060b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\350\256\242\350\264\255\350\277\236\350\241\250\346\237\245\350\257\242.sql" @@ -0,0 +1,90 @@ +use master +go + +create database order1 +on +( + name='order1', + filename='E:\数据库文件\数据库跟目录文件\连表查询:内连接、外连接、交叉连接、全连接、自连接\order1.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='order1_log', + filename='E:\数据库文件\数据库跟目录文件\连表查询:内连接、外连接、交叉连接、全连接、自连接\order1_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use order1 +go +create table orders +( + orderId int primary key identity(1,1), + orderDate date +) +go + +insert into orders values('2008-01-12'),('2008-02-10'),('2008-02-15'),('2008-03-10') +select * from orders--订单表 + + +use order1 +go +create table orderItem +( + ItemiD int, + orderId int constraint FK_orderItem_orderId foreign key references orders(orderId), + itemType nchar(15), + itemName char(20), + theNumber int, + theMoney money +) +go + +insert into orderItem values +(1,1,'文具','笔',72,2),(2,1,'文具','尺',10,1),(3,1,'体育用品','篮球',1,56),(4,2,'文具','笔',36,2), +(5,2,'文具','固体胶',20,3),(6,2,'日常用品','透明胶',2,1),(7,2,'体育用品','羽毛球',20,3),(8,3,'文具','订书机',20,3), +(9,3,'文具','订书针',10,3),(10,3,'文具','裁纸刀',5,5),(11,4,'文具','笔',20,2),(12,4,'文具','信纸',50,1), +(13,4,'日常用品','毛巾',4,5),(14,1,'日常用品','透明胶',30,1),(15,4,'体育用品','羽毛球',20,3) + +select * from orderItem--订购项目表 + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orderItem.ItemiD 订单编号,orderDate 订单日期, itemType 订单类别,itemName 产品名称,theNumber 订购数量,theMoney 产品单价 from orders inner join orderItem on orderItem.orderId=orders.orderId + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.ItemiD 订单编号,orderDate 订单日期,itemType 订单类别,itemName 产品名称 from orderItem inner join orders on orderItem.orderId=orders.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 产品单价,theNumber*theMoney 订购总价 from orderItem inner join orders on orderItem.orderId=orders.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orderItem.orderId 订单编号,orderDate 订单日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 产品单价,theNumber*theMoney 订购总价 from orderItem inner join orders on orderItem.orderId=orders.orderId where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 + +select orderId 订单类别编, count(theNumber) 订单产品数 from orderItem group by orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderItem.orderId 订单编号,itemType 产品类别,count(itemType)订购次数,sum(theNumber)总数 from orderItem inner join orders on orderItem.orderId=orders.orderId group by orderItem.orderId,orderItem.itemType order by orderItem.orderId asc +select orderId,itemType 类别,count(itemType)次数,sum(theNumber)总数量 from orderItem group by orderId,itemType order by orderId asc \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\350\256\272\345\235\233\350\277\236\350\241\250\346\237\245\350\257\242.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\350\256\272\345\235\233\350\277\236\350\241\250\346\237\245\350\257\242.sql" new file mode 100644 index 0000000..66ac1a4 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\350\256\272\345\235\233\350\277\236\350\241\250\346\237\245\350\257\242.sql" @@ -0,0 +1,168 @@ +use master +go +create database bbs +on +( + name='bbs', + filename='E:\数据库文件\数据库跟目录文件\连表查询:内连接、外连接、交叉连接、全连接、自连接\bbs.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='bbs_log', + filename='E:\数据库文件\数据库跟目录文件\连表查询:内连接、外连接、交叉连接、全连接、自连接\bbs_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use bbs +create table bbsUsers +( + UID int identity(1,1), + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +go + +alter table bbsUsers add constraint PK_bbsUsers_UID primary key (UID) +alter table bbsUsers add constraint UK_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint CK_bbsUsers_uSex check(uSex='男' or uSex='女') +alter table bbsUsers add constraint CK_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint CK_bbsUsers_uPoint check(uPoint>=0) + + +use bbs +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) +go + +alter table bbsSection add constraint PK_bbsSection_sID primary key (sID) +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + +use bbs +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int constraint FK_bbsUsers_UID references bbsUsers(UID), + tSID int constraint FK_bbsSection_sID references bbsSection(sID), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +go + +use bbs +create table bbsReply +( + rID int primary key identity(1,1), + rUID int constraint FK_bbsReply_rUID references bbsUsers(UID), + rTID int constraint FK_bbsTopic_tID references bbsTopic(tID), + rMsg text not null, + rTime datetime +) +go + + +--1.现在有3个会员注册成功,请用一次插入多行数据的方法向bbsUsers表种插入3行记录,记录值如下: +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +--2.将bbsUsers表中的用户名和积分两列备份到新表bbsPoint表中,提示查询部分列:select 列名1,列名2 from 表名 +select uName,uPoint into bbsPoint from bbsUsers +--3.给论坛开设4个板块 +-- 名称 版主名 +-- 技术交流 小雨点 +-- 读书世界 七年级生 +-- 生活百科 小雨点 +-- 八卦区 七年级生 +insert into bbsSection values ('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) + +select * from bbsUsers +--4.向主贴和回帖表中添加几条记录 + +-- 主贴: + +-- 发帖人 板块名 帖子标题 帖子内容 发帖时间 回复数量 +-- 逍遥 八卦区 范跑跑 谁是范跑跑 2008-7-8 1 +-- 七年级生 技术交流 .NET 与JAVA的区别是什么呀? 2008-9-1 2 +-- 小雨点 生活百科 今年夏天最流行什么 有谁知道今年夏天最流行 2008-9-10 0 +-- 什么呀? + +-- 回帖: +-- 分别给上面三个主贴添加对应的回帖,回帖的内容,时间,回帖人自定 +insert into bbsTopic(tUID,tSID,tTitle,tMsg,tTime,tCount) values +(2,2,'范跑跑','谁是范跑跑','2008-7-8',1),(3,3,'.NET','与JAVA的区别是什么呀?','2008-9-1',2), +(1,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?','2008-9-10',0) +--5.因为会员“逍遥”发表了非法帖子,现将其从论坛中除掉,即删除该用户,请用语句实现(注意主外键,要删除主键,先要将引用了该主键的外键数据行删除) +alter table bbsTopic drop constraint FK_bbsUsers_UID +delete from bbsUsers where uName='逍遥' +--6.因为小雨点发帖较多,将其积分增加10分 +update bbsUsers set uPoint=10 where uName='小雨点' +--7.因为板块“生活百科”灌水的人太少,现决定取消该板块,即删除(注意主外键) +alter table bbsTopic drop constraint FK_bbsSection_sID +delete from bbsSection where sName='生活百科' +--8.因回帖积累太多,现需要将所有的回帖删除 +delete from bbsReply + + +select * from bbsTopic--主贴表 +select * from bbsSection--版块表 +select * from bbsUsers--用户信息表 +select * from bbsReply--回帖表 + +--在论坛数据库中完成以下题目 + +--1.在主贴表中统计每个版块的发帖总数 +select tSID 发帖总数,count(*) from bbsTopic group by tSID +select * from bbsTopic--主贴表 + +--2.在回帖表中统计每个主贴的回帖总数量 +select rTID 主贴编号,count(*)回帖数量 from bbsReply group by rTID +select * from bbsReply--回帖表 + +--3.在主贴表中统计每个用户的发的主帖的总数 +select tUID 用户编号,count(*)发贴总数 from bbsTopic group by tUID +select * from bbsTopic--主贴表 + +--4.在主贴表中统计每个用户发的主贴的回复数量总和 +select * from bbsTopic--主贴表 +select tUID 用户编号,sum(tCount)回帖总数 from bbsTopic group by tUID + +--5.在主贴表中查询每个版块的主贴的平均回复数量大于3的版块的平均回复数量 +select * from bbsTopic--主贴表 +select tSID 板块编号,avg(tCount)平均回复数 from bbsTopic group by tSID having avg(tCount)>3 + +--6.在用户信息表中查询出积分最高的用户的用户名,性别,年龄和积分 +select * from bbsUsers--用户信息表 +select top 1 uName 用户名,uSex 性别,uAge 年龄,uPoint 积分 from bbsUsers group by uName,uSex,uAge,uPoint + +--7.在主贴表中(bbsTopic)中将帖子的内容或标题中有“快乐”两字的记录查询出来 +select * from bbsTopic--主贴表 +select tTitle 标题,tMsg 内容 from bbsTopic where tTitle like '%快乐%' or tMsg like '%快乐%' + +--8.在用户信息表(bbsUsers)中将用户年龄在15-20之间并且积分在10分以上的优秀用户查询出来(用多种方法实现) +select * from bbsUsers--用户信息表 +select * from bbsUsers where uAge between 15 and 20 and uPoint>10 +select * from bbsUsers where uAge>15 and uAge<20 and uPoint>10 + +--9.在用户信息表(bbsUsers)中将用户名的第一个字为“小”,第三字为“大”的用户信息查询出来 +select * from bbsUsers--用户信息表 +select * from bbsUsers where uName='小_大' + +--10.在主贴表(bbsTopic)中将在2008-9-10 12:00:00 以后发的并且回复数量在10以上的帖子的标题和内容查询出来,并且为列取上对应的中文列名 +select * from bbsTopic--主贴表 +select tID 主贴编号,tTitle 贴子标题,tMsg 帖子内容 from bbsTopic where tTime>'2008-9-10 12:00:00' and tCount>10 + +--11.在主贴表(bbsTopic)中将帖子的标题是以‘!’结尾的帖子的发帖人编号和回复数量查询出来 +select * from bbsTopic--主贴表 +select tUID,tCount from bbsTopic where tTitle like '%!' \ No newline at end of file -- Gitee From 649c11930492a166a7a7437a3bb350a452bc6389 Mon Sep 17 00:00:00 2001 From: pdxnb <2454478226@qq.com> Date: Sun, 28 Mar 2021 22:53:43 +0800 Subject: [PATCH 055/195] first commit --- .../\344\275\234\344\270\2321.sql" | 76 +++++++++++++ .../\344\275\234\344\270\2322.sql" | 97 ++++++++++++++++ .../\344\275\234\344\270\2323.sql" | 104 ++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2321.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2322.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2323.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2321.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..1d6c82e --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2321.sql" @@ -0,0 +1,76 @@ +create database Studentinfo +on +( + name='Studentinfo', + filename='D:\Studentinfo.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='Studentinfo_log', + filename='D:\Studentinfo_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +use Studentinfo +go +create table StuDent +( + sTUNO varchar(15), + stuName nvarchar(20), + stuAge int, + stuAddress nvarchar(50), + stuSeat int, + stuSex nvarchar(1) default('男') check(stuSex='男' or stuSex='女') +) + +insert into StuDent(sTUNO,stuName,stuAge,stuAddress,stuSeat,stuSex) +select 's2501','张秋里',20,'美国硅谷',1,'男' union +select 's2502','李斯文',18,'湖北武汉',2,'女' union +select 's2503','马文才',22,'湖南长沙',3,'男' union +select 's2504','欧阳俊雄',21,'湖北武汉',4,'女' union +select 's2505','梅超风',20,'湖北武汉',5,'男' union +select 's2506','陈旋风',19,'美国硅谷',6,'男' union +select 's2507','陈风',20,'美国硅谷',7,'女' + + +create table Score +( + examNO int, + stuNO varchar(15), + writtenExam int, + labExam int +) + + +insert into Score(examNO,stuNO,writtenExam,labExam) +select 1,'s2501','50','70' union +select 2,'s2502','60','65' union +select 3,'s2503','86','85' union +select 4,'s2504','40','80' union +select 5,'s2505','70','90' union +select 6,'s2506','85','90' + + + + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试,labExam 机试 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuDent.sTUNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO where writtenExam>60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select StuDent.sTUNO 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuDent left join Score on StuDent.sTUNO=Score.stuNO +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 from StuDent inner join Score on StuDent.sTUNO=Score.stuNO where stuAge>=20 order by writtenExam desc +--5.查询男女生的机试平均分 +select stuSex,avg(labExam)平均分 from Score left join StuDent on Score.stuNO=StuDent.sTUNO group by stuSex +--6.查询男女生的笔试总分 +select stuSex,sum(writtenExam)总分 from Score left join StuDent on Score.stuNO=StuDent.sTUNO group by stuSex + +select * from Score +select * from StuDent diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2322.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..223d80b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2322.sql" @@ -0,0 +1,97 @@ +create database cc +on +( + name='cc', + filename='D:\cc.mdf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) +log on +( + name='cc_log', + filename='D:\cc.ldf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) +go +use cc +go +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) + +create table orders +( + orderId int primary key, + orderDate datetime +) +--插入表1数据 +insert into orders(orderId,orderDate) +select 1,'2008-01-12' union +select 2,'2008-02-10' union +select 3,'2008-02-15' union +select 4,'2008-03-10' +select * from orders +--订购项目表(orderItem),列为: +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) +create table orderItem +( + ItemiD int primary key identity(1,1), + orderId int, + itemType varchar(20), + itemName varchar(20), + theNumber int , + theMoney int +) +--添加表二的外键约束 关联表一的order id +alter table orderItem add constraint FK foreign key (orderId) references orders(orderId) +--插入表2数据 +insert into orderItem(orderId,itemType,itemName,theNumber,theMoney) +select 1,'文具','笔',72,2 union +select 1,'文具','尺',10,1 union +select 1,'体育用品','篮球',1,56 union +select 2,'文具','笔',36,2 union +select 2,'文具','固体胶',20,3 union +select 2,'日常用品','透明胶',2,1 union +select 2,'体育用品','羽毛球',20,3 union +select 3,'文具','订书机',20,3 union +select 3,'文具','订书针',10,3 union +select 3,'文具','裁纸刀',5,5 union +select 4,'文具','笔',20,2 union +select 4,'文具','信纸',50,1 union +select 4,'日常用品','毛巾',4,5 union +select 4,'日常用品','透明胶',30,1 union +select 4,'体育用品','羽毛球',20,3 + +--使用上次作业的订单数据库,完成下列题目: +--订单表(orders) 订购项目表(orderItem) +select * from orders +select * from orderItem +--1.查询所有的订单的 订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orderItem.orderId 订单编号,orders.orderDate 日期,itemType 类别,itemName 产品名称,theNumber 数量,theMoney 单价 from orderItem inner join orders on orderItem.orderId=orders.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orderItem.orderId 订单编号,theNumber 数量,orders.orderDate 日期,itemType 类别,itemName 产品名称 from orderItem inner join orders on orderItem.orderId=orders.orderId where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orders.orderDate 日期,itemName 产品名称,theNumber 数量,theMoney 单价 ,theMoney*theNumber 订购总价 +from orderItem inner join orders on orderItem.orderId=orders.orderId + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orderItem.orderId 订单编号,orderDate 日期,itemType 类别,itemName 产品名称,theNumber 数量,theMoney 单价 ,theMoney*theNumber 订购总价 + from orderItem inner join orders on orderItem.orderId=orders.orderId where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderId 编号 ,count(itemName)订购产品数 from orderItem group by orderId + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +select orderId,itemType 类别,count(itemType)次数,sum(theNumber)总数量 from orderItem group by orderId,itemType order by orderId asc +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2323.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2323.sql" new file mode 100644 index 0000000..8277e7b --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/\344\275\234\344\270\2323.sql" @@ -0,0 +1,104 @@ +create database bbs + +on +( + name='bbs', + filename='D:\bbs.mdf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='D:\bbs_log.ldf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +go +use bbs +go +create table bbsUsers +( + UIDD int identity, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +create table bbsSection +( + sIDD int identity, + sName varchar(10) not null, + sUid int +) + +alter table bbsUsers add constraint Pk_bbsUsers_UIDD primary key(UIDD) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uPoint check(uPoint>=0) + +alter table bbsSection add constraint Pk_bbsSection_sIDD primary key(sIDD) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UIDD) + +create table bbsTopic +( + tID int identity primary key, + tUID int foreign key references bbsUsers(UIDD), + tSID int foreign key references bbsSection(sIDD), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int identity primary key, + rUID int foreign key references bbsUsers(UIDD), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'),(3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), +(1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') + +insert into bbsReply values(3,2,'八嘎','2008-7-8'),(1,1,'python','2008-7-8'),(1,3,'上海','2008-7-8') + +--据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 +select sIDD,uName,sName from bbsSection left join bbsUsers on sIDD=UIDD + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID,uName,tTitle,tMsg,tTime from bbsTopic left join bbsUsers on tID=UIDD where tTime > '2008-09-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sIDD,uName,sName,uAge from bbsSection left join bbsUsers on sIDD=UIDD where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select top 1 tUID,uName,tTitle,tMsg,tCount from bbsUsers t left join bbsTopic x on t.UIDD=x.tID order by tCount desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select uName 用户名,sName 版块名称,count(*)发帖总数 from bbsTopic + inner join bbsUsers on bbsTopic.tUID = bbsUsers.UIDD + inner join bbsSection on bbsUsers.UIDD= bbsSection.sUid group by uName,sName + + + + +select * from bbsReply --回帖表 +select * from bbsSection --版块表 +select * from bbsTopic --主帖表 +select * from bbsUsers --用户信息表 + + + + + + -- Gitee From 61cfc41b4aa5df59c6ee1eb4764ca8034d8e8cf8 Mon Sep 17 00:00:00 2001 From: Chenxuqing <8332101+W1902774261@user.noreply.gitee.com> Date: Sun, 28 Mar 2021 23:05:07 +0800 Subject: [PATCH 056/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=99=88=E6=97=AD?= =?UTF-8?q?=E6=B8=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\231\210\346\227\255\346\270\205/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/.keep" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/.keep" "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From e9093bc27c4afe45de17eeca9e99efafe1097da2 Mon Sep 17 00:00:00 2001 From: Chenxuqing <8332101+W1902774261@user.noreply.gitee.com> Date: Sun, 28 Mar 2021 23:05:27 +0800 Subject: [PATCH 057/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?20210326=E4=BD=9C=E4=B8=9A/=E9=99=88=E6=97=AD=E6=B8=85/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\231\210\346\227\255\346\270\205/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/.keep" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/.keep" "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/.keep" deleted file mode 100644 index e69de29..0000000 -- Gitee From e434ac85910e8a82349467bad93efcae69eb69b7 Mon Sep 17 00:00:00 2001 From: Chenxuqing <8332101+W1902774261@user.noreply.gitee.com> Date: Sun, 28 Mar 2021 23:06:12 +0800 Subject: [PATCH 058/195] =?UTF-8?q?=E9=99=88=E6=97=AD=E6=B8=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery10.sql" | 88 ++++++++++++++ .../SQLQuery12.sql" | 115 ++++++++++++++++++ .../SQLQuery8.sql" | 21 ++++ 3 files changed, 224 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery10.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery12.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery8.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery10.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery10.sql" new file mode 100644 index 0000000..85e4b65 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery10.sql" @@ -0,0 +1,88 @@ +create database OrderIno +go + +use OrderIno +go + +create table orders +( + orderID int primary key identity(1,1), + orderDate datetime +) + +create table orderltem +( + ltemID int identity(1,1), + orderID int , + itemType nvarchar(15), + itemName nvarchar(10), + theNumber int , + theMoney money +) + +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 orderltem values +(1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'生活用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书机',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'生活用品','毛巾',4,5), +(4,'生活用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) + + +--使用上次作业的订单数据库,完成下列题目: + +select * from orders --订单表 +select * from orderltem --订购项目表 + +--订单表(orders)列为:订单编号(orderID 主键) 订购日期(orderDate)--订购项目表(orderItem),列为:--项目编号(ItemID)订单编号(orderID)产品类别(itemType)--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderID 订单的编号 ,orderDate 订单日期, itemType 订购产品的类别,itemName 订购的产品名称 from orders +inner join orderltem on orders.orderID =orderltem.orderID + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderID 订单的编号 ,orderDate 订单日期, itemType 订购产品的类别,itemName 订购的产品名称 from orders +inner join orderltem on orders.orderID =orderltem.orderID where orderltem.theNumber >50 + + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderID 订单的编号 ,orderDate 订单日期, itemType 订购产品的类别,itemName 订购的产品名称, theNumber 订购数量 ,theMoney 订购单价 , theNumber*theMoney 订购总价 from orders +inner join orderltem on orders.orderID =orderltem.orderID + + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderID 订单的编号 ,orderDate 订单日期, itemType 订购产品的类别,itemName 订购的产品名称, theNumber 订购数量 ,theMoney 订购单价 , theNumber*theMoney 订购总价 from orders +inner join orderltem on orders.orderID =orderltem.orderID where orderltem.theMoney>=5 and orderltem.theNumber>=50 + + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderID 订单的编号 , count(*)订购产品数 from orderltem group by orderID + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: +-- 订单编号 产品类别 订购次数 总数量 +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + +select orderID 订单的编号 , itemType 产品类别 ,count(*)订购次数 , sum(theNumber) 总数量 + from orderltem group by orderID,itemType order by orderID \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery12.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery12.sql" new file mode 100644 index 0000000..f001f7e --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery12.sql" @@ -0,0 +1,115 @@ +use master +go + +create database bbs +go + +use bbs +go + +create table bbsUsers +( + UID int identity(1,1) , + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +-- +alter table bbsUsers add constraint PK_bbsUser_UID primary key(UID) +-- +alter table bbsUsers add constraint UK_bbsUser_uName unique(uName) +-- +alter table bbsUsers add constraint CK_bbsUser_uSex check(uSex in('男','女')) +-- +alter table bbsUsers add constraint CK_bbsUser_uAge check(uAge>=15 or uAge<=60) +-- +alter table bbsUsers add constraint CK_bbsUser_uPoint check(uPoint>=0) +-- + +create table bbsSection +( + sID int identity(1,1), + sName varchar(10) not null, + sUid int +) + +alter table bbsSection add constraint PK_bbsSection_sID primary key(sID) +-- +alter table bbsSection add constraint FK_bbsSection_sUid foreign key(sUid) references bbsUsers(UID) + + + +create table bbsTopic +( + tID int primary key identity(1,1), + tUID int foreign key references bbsUsers(UID), + tSID int foreign key references bbsSection(sID), + tTItle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) + + +create table bbsReply +( + rID INT primary key identity(1,1), + rUID int foreign key references bbsUsers(UID), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values +('小雨点','女',20,0), +('逍遥','男',18,4), +('七年级生','男',19,2) + + +select * into bbsPoint from bbsUsers + +insert into bbsSection values +('技术交流',1), +('读书世界',3), +('生活百科',1), +('八卦区',3) + +insert into bbsTopic values +(2,4,'今年夏天最流行什么','有谁知道今年夏天最流行什么呀?',2008-9-10,0), +(3,1,'.NET','与JAVA的区别是什么呀?',2008-9-1,2), +(1,3,'范跑跑','谁是范跑跑',2008-7-8,1) + +insert into bbsReply values +(2,1,'不知道',2008-9-10), +(3,2,'不知道',2008-9-1), +(1,3,'不知道',2008-7-8) + +select * from bbsReply --回帖表 +select * from bbsSection --版块表 +select * from bbsTopic --主帖表 +select * from bbsUsers --用户信息表 + +--在论坛数据库中完成以下题目 +--1.查询出 每个版块 的 版主编号, 版主姓名 和版块名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection +inner join bbsUsers on bbsUsers.UID = bbsSection.sUid + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 +select tUID 发帖人编号,uName 发帖人姓名,tTItle 帖子的标题 ,tMsg 帖子的内容,tTime 发帖时间 from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID where tTime>'2008-9-15' + + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 +select sUid 版主编号,uName 版主姓名,sName 版块名称 from bbsSection +inner join bbsUsers on bbsUsers.UID = bbsSection.sUid where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 +select rUID 发帖人编号 , uName 发帖人姓名 ,tTItle 主贴标题 , tMsg 主贴内容 , tCount 回复数量 from bbsReply +inner join bbsTopic on bbsTopic.tUID = bbsReply.rUID +inner join bbsUsers on bbsUsers.UID = bbsReply.rUID where tCount=(select max(tCount) from bbsTopic) + +--5.在主贴表中查询每个版块中每个用户的发帖总数 +select tSID 版块 , uName 发帖人姓名 , count(*) from bbsTopic +inner join bbsUsers on bbsUsers.UID = bbsTopic.tUID +inner join bbsSection on bbsUsers.UID =bbsSection.sID group by tSID ,uName diff --git "a/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery8.sql" "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery8.sql" new file mode 100644 index 0000000..b4640b9 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\231\210\346\227\255\346\270\205/SQLQuery8.sql" @@ -0,0 +1,21 @@ +select*from StuIS +select*from Grate + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName 姓名,StuAge 年龄,WExam 笔试成绩,LabExam 机试成绩 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select WExam,LabExam ,StuIS.StuNO,StuAge from Grate inner join StuIS on StuIS.StuNO=Grate.StuNo Group by WExam,LabExam ,StuAge having WExam>=60 and LabExam>=60 + + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select count(ExamNO),StuName,WExam,LabExam from Grate inner join StuIS on StuIS.StuNO=Grate.StuNo group by count(ExamNo) + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName ,StuAge,Grate.WExam,Grate.LabExam from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo where StuAge>=20 + +--5.查询男女生的机试平均分 +select StuSex,avg(LabExam) from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo group by StuSex + +--6.查询男女生的笔试总分 +select StuSex 性别 ,sum(WExam)笔试总分 from StuIS inner join Grate on StuIS.StuNO=Grate.StuNo group by StuSex \ No newline at end of file -- Gitee From b50ba438087a4c8c7339821ed84cac9a6757407e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=9D=B0=E7=83=A8?= Date: Sun, 28 Mar 2021 23:16:54 +0800 Subject: [PATCH 059/195] =?UTF-8?q?=E9=BB=84=E6=9D=B0=E7=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 84 +++++++++++++++++++ .../SQLQuery2.sql" | 66 +++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/SQLQuery2.sql" diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/SQLQuery1.sql" new file mode 100644 index 0000000..59a3de1 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/SQLQuery1.sql" @@ -0,0 +1,84 @@ +create database Assignment +on +( + name='Assignment', + filename='D:\SQL\Assignment.mdf' +) +log on +( + name='Assignment_log', + filename='D:\SQL\Assignment_log.ldf' +) +go + +use Assignment +go +--drop table orderItem +create table orders +( + orderId int primary key, + orderDate date +) + +create table orderItem +( + ItemiD int identity(1,1) primary key, + orderId int references orders(orderId), + itemType varchar(12), + itemName varchar(12), + theNumber int, + theMoney money +) +insert into orders values + (1,'2008-01-12'), + (2,'2008-02-10'), + (3,'2008-02-15'), + (4,'2008-03-10') +insert into orderItem values + (1,'文具','笔',72,2), + (1,'文具','尺',10,1), + (1,'体育用品','篮球',1,56), + (2,'文具','笔',36,2), + (2,'文具','固体胶',20,3), + (2,'日常用品','透明胶',2,1), + (2,'体育用品','羽毛球',20,3), + (3,'文具','订书机',20,3), + (3,'文具','订书针',10,3), + (3,'文具','裁纸刀',5,5), + (4,'文具','笔',20,2), + (4,'文具','信纸',50,1), + (4,'日常用品','毛巾',4,5), + (4,'日常用品','透明胶',30,1), + (4,'体育用品','羽毛球',20,3) +-- 使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价 +from orders o inner join orderItem i on o.orderId=i.orderId +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称 +from orders o inner join orderItem i on o.orderId=i.orderId +where theNumber>50 +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 +from orders o inner join orderItem i on o.orderId=i.orderId +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select o.orderId 订单编号,orderDate 订单日期,itemType 订购类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 +from orders o inner join orderItem i on o.orderId=i.orderId +where theMoney>=5 and theNumber>=50 +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select o.orderId 订单编号,count(*) from orders o inner join orderItem i on o.orderId=i.orderId group by o.orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 +select o.orderId 订单编号,itemType 订购类别,count(*) 订购次数,sum(theNumber) 总数量 +from orders o inner join orderItem i on o.orderId=i.orderId group by o.orderId,itemType order by o.orderId \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/SQLQuery2.sql" new file mode 100644 index 0000000..0f538c0 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/SQLQuery2.sql" @@ -0,0 +1,66 @@ +create database Student +on +( + name='Student', + filename='D:\SQL\Student.mdf' +) +log on +( + name='Student_log', + filename='D:\SQL\Student_log.ldf' +) +go + +create table StuInfo +( + stuNo char(5) primary key(stuNo), + stuName nvarchar(20), + stuAge int, + stuAddress text, + stuSeat int identity(1,1), + stuSex char(1) check(stuSex in(1,0)) +) + +create table StuExam +( + examNo int identity(1,1), + stuNo char(5), + writtenExam int check(writtenExam>=0 and writtenExam<=100), + labExam int check(labExam>=0 and labExam<=100) +) + + alter table StuExam add constraint RK_StuExam_stuNo foreign key(stuNo) references StuInfo(stuNo) + + insert into StuInfo 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 values + ('s2501',50,70),('s2502',60,65),('s2503',86,85),('s2504',40,80),('s2505',70,90),('s2506',85,90) + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select i.stuNo 学号,stuName 姓名,writtenExam 笔试成绩,labExam 机试成绩 from StuInfo i left join StuExam e +on i.stuNo=e.stuNo where writtenExam>60 and labExam>60 +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i left join StuExam e on i.stuNo=e.stuNo +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select stuName 姓名,stuAge 年龄,writtenExam 笔试成绩,labExam 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +where stuAge>=20 order by writtenExam DESC +--5.查询男女生的机试平均分 +select stuSex 性别,avg(labExam) 机试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo +where stuAge>=20 group by stuSex +--6.查询男女生的笔试总分 +select stuSex 性别,sum(writtenExam) 笔试成绩 +from StuInfo i inner join StuExam e on i.stuNo=e.stuNo group by stuSex \ No newline at end of file -- Gitee From 99adbbc626684a2e94e5e5c49c9ba807763b1b4f Mon Sep 17 00:00:00 2001 From: jckyang <235723419@qq.com> Date: Sun, 28 Mar 2021 23:24:57 +0800 Subject: [PATCH 060/195] sql2-1 --- .../\346\261\237\346\264\213/SQLQuery1.sql" | 84 +++++++++++++++ .../\346\261\237\346\264\213/SQLQuery2.sql" | 97 +++++++++++++++++ .../\346\261\237\346\264\213/SQLQuery3.sql" | 101 ++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery3.sql" diff --git "a/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" "b/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" new file mode 100644 index 0000000..3dde0a6 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" @@ -0,0 +1,84 @@ +create database AKA +on +( + name='D:\AKA', + filename='D:\AKA.mdf', + size=5, + maxsize=50, + filegrowth=5% +) +log +on +( + name='D:\AKA_log', + filename='D:\AKA_log.ldf', + size=5, + maxsize=50, + filegrowth=5% +) +use AKA + + +create table stu +( + stuNo varchar(10) not null primary key, + stuName varchar(10) not null, + stuAge int not null, + stuAddress varchar(10) not null, + stuSeat int identity not null, + stuSex varchar(2) not null +) +create table cjb +( + examNO int identity not null, + stuNo varchar(10) foreign key references stu(stuNo) not null, + writtenExam int not null, + labExam int not null +) +insert into stu(stuNo,stuName,stuAge,stuAddress,stuSex)values +('s2501','张秋利',20,'美国硅谷','男'), +('s2502','李斯文',18,'湖北武汉','女'), +('s2503','马文才',22,'湖南长沙','男'), +('s2504','欧阳俊雄',21,'湖北武汉','女'), +('s2505','梅超风',20,'湖北武汉','男'), +('s2506','陈旋风',19,'美国硅谷','男'), +('s2507','陈风',20,'美国硅谷','女') + +insert into cjb(stuNo,writtenExam,labExam)values +('s2501',50,70), +('s2502',60,65), +('s2503',86,85), +('s2504',40,80), +('s2505',70,90), +('s2506',85,90) + + +select * from stu + +select * from cjb + +--数据如图片1,使用上次作业的数据 + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 + +select stuName,stuAge,writtenExam,labExam from stu left join cjb on stu.stuNo=cjb.stuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 + +select stuName,writtenExam,labExam from stu left join cjb on stu.stuNo=cjb.stuNo where writtenExam>60 and labExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 + +select stu.stuNo,stuName,writtenExam,labExam from stu left join cjb on stu.stuNo=cjb.stuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 + +select stuName,stuAge,writtenExam,labExam from stu left join cjb on stu.stuNo=cjb.stuNo where stuAge>=20 order by writtenExam desc + +--5.查询男女生的机试平均分 + +select stuSex 性别,avg(labExam)机试平均分 from stu inner join cjb on stu.stuNo=cjb.stuNo group by stuSex + +--6.查询男女生的笔试总分 + +select stuSex 男女,sum(writtenExam)笔试总分 from stu inner join cjb on stu.stuNo=cjb.stuNo group by stuSex \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery2.sql" "b/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery2.sql" new file mode 100644 index 0000000..cea7fa2 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery2.sql" @@ -0,0 +1,97 @@ +create database ASA +on( + name='D:\ASA', + filename='D:\ASA.mdf', + size=5, + maxsize=50, + filegrowth=15% +) +log on +( + name='D:\ASA_log', + filename='D:\ASA_log.ldf', + size=5, + maxsize=50, + filegrowth=15% +) +use ASA + +create table orders +( + orderld int not null identity(1,1) primary key , + orderDate datetime not null +) +create table orderltem +( + ltemID int identity not null, + orderld int foreign key references orders(orderld), + itemType varchar(10) not null, + itemName varchar(10) not null, + theNumber int not null, + theMoney int not null, +) +insert into orders 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 orderltem values +(1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'日常用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书针',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'日常用品','毛巾',4,5), +(4,'日常用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) + + + +select * from orders +select * from orderltem + +--使用上次作业的订单数据库,完成下列题目: + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orders.orderld,orderDate,itemType,itemName,theNumber,theMoney from orders left join orderltem on orders.orderld=orderltem.orderld + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 + +select orders.orderld,orderDate,itemType,itemName from orders inner join orderltem on orders.orderld=orderltem.orderld where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orders.orderld,orderDate,itemType,itemName,theNumber,theMoney,theNumber*theMoney 订购总价 from orders left join orderltem on orders.orderld=orderltem.orderld + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 + +select orders.orderld,orderDate,itemType,itemName,theNumber,theMoney,theNumber*theMoney 订购总价 from orders left join orderltem on orders.orderld=orderltem.orderld where theMoney>5 and theNumber>50 + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select * from orders +select * from orderltem +select orderld,count(theNumber)产品数 from orderltem group by orderld + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + +-- 订单编号 产品类别 订购次数 总数量 + +-- 1 文具 2 82 +-- 1 体育用品 1 1 +-- 2 文具 2 56 +-- 2 体育用品 1 2 +-- 2 日常用品 1 20 + + +select orderld,itemType,count(*)次数,sum(theNumber)总数量 from orderltem group by orderld,itemType order by orderld diff --git "a/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery3.sql" "b/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery3.sql" new file mode 100644 index 0000000..abb475f --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery3.sql" @@ -0,0 +1,101 @@ +create database bbs + +on +( + name='bbs', + filename='D:\bbs.mdf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +log on +( + name='bbs_log', + filename='D:\bbs_log.ldf', + size=8mb, + maxsize=100mb, + filegrowth=10mb +) +go +use bbs +go +create table bbsUsers +( + UIDD int identity, + uName varchar(10) not null, + uSex varchar(2) not null, + uAge int not null, + uPoint int not null +) +create table bbsSection +( + sIDD int identity, + sName varchar(10) not null, + sUid int +) + +alter table bbsUsers add constraint Pk_bbsUsers_UIDD primary key(UIDD) +alter table bbsUsers add constraint Uk_bbsUsers_uName unique(uName) +alter table bbsUsers add constraint Ck_bbsUsers_uSex check(uSex='男'or uSex='女') +alter table bbsUsers add constraint Ck_bbsUsers_uAge check(uAge>=15 and uAge<=60) +alter table bbsUsers add constraint Ck_bbsUsers_uPoint check(uPoint>=0) + +alter table bbsSection add constraint Pk_bbsSection_sIDD primary key(sIDD) +alter table bbsSection add constraint Fk_bbsSection_sUid foreign key(sUid) references bbsUsers(UIDD) + +create table bbsTopic +( + tID int identity primary key, + tUID int foreign key references bbsUsers(UIDD), + tSID int foreign key references bbsSection(sIDD), + tTitle varchar(100) not null, + tMsg text not null, + tTime datetime, + tCount int +) +create table bbsReply +( + rID int identity primary key, + rUID int foreign key references bbsUsers(UIDD), + rTID int foreign key references bbsTopic(tID), + rMsg text not null, + rTime datetime +) + +insert into bbsUsers values('小雨点','女',20,0),('逍遥','男',18,4),('七年级生','男',19,2) +select uName,uPoint into bbsPoint from bbsUsers +insert into bbsSection values('技术交流',1),('读书世界',3),('生活百科',1),('八卦区',3) +insert into bbsTopic values(2,4,'范跑跑 ',' 谁是范跑跑 ','2008-7-8','1'),(3,1,'.NET ',' 与JAVA的区别是什么呀? ','2008-9-1 ','2'), +(1,3,'今年夏天最流行什么 ',' 有谁知道今年夏天最流行 ','2008-9-10','0') + +insert into bbsReply values(3,2,'八嘎','2008-7-8'),(1,1,'python','2008-7-8'),(1,3,'上海','2008-7-8') + + +select * from bbsUsers 用户信息表 +select * from bbsSection 版块表 +select * from bbsTopic 主帖表 +select * from bbsReply 回帖表 + +--在论坛数据库中完成以下题目 +--1.查询出每个版块的版主编号,版主姓名和版块名称 + +select sIDD,sName,uName from bbsSection left join bbsUsers on sIDD=uIDD + +--2.查询出主贴的发帖时间在2008-9-15以后的主贴的发帖人编号,发帖人姓名,帖子的标题,帖子的内容和发帖时间 + +select tUID,uName,tTitle,tMsg,tTime from bbsTopic left join bbsUsers on tID=UIdd where tTime>'2008-09-15' + +--3.查询出年龄在20以下的版主的编号,版主的名称和版块的名称 + +select sIDD,uName,sName from bbsSection left join bbsUsers on sIdd=UIDD where uAge<20 + +--4.查询出回复数量最多的主贴的发帖人编号,发帖人姓名,主贴标题,主贴内容和回复数量 + +select top 1 tUID,uName,tTitle,tMsg,tCount from bbsUsers t left join bbsTopic x on t.UIDD=x.tID order by tCount desc + +--5.在主贴表中查询每个版块中每个用户的发帖总数 + +select uName 用户名,sName 版块名称,count(*)发帖总数 from bbsTopic + inner join bbsUsers on bbsTopic.tUID = bbsUsers.UIDD + inner join bbsSection on bbsUsers.UIDD= bbsSection.sUid group by uName,sName + -- Gitee From f9532776e6dfa667d378062d338614324c2d0d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=BE=E5=A4=A7=E6=98=9F=E5=91=80?= <2454478226@qq.com> Date: Mon, 29 Mar 2021 00:18:35 +0800 Subject: [PATCH 061/195] =?UTF-8?q?=E5=88=98=E4=B8=96=E8=BE=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zy.sql" | 474 ++++++++++++++++++ .../zy2.sql" | 90 ++++ .../zy3.sql" | 83 +++ 3 files changed, 647 insertions(+) create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy2.sql" create mode 100644 "20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy3.sql" diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" new file mode 100644 index 0000000..38c0369 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" @@ -0,0 +1,474 @@ +USE [master] +GO +/****** Object: Database [TestDB] Script Date: 2021/3/15 16:11:24 ******/ +CREATE DATABASE [TestDB] + CONTAINMENT = NONE + ON PRIMARY +( NAME = N'TestDB', FILENAME = N'D:\TestDB.mdf' , SIZE = 4288KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) + LOG ON +( NAME = N'TestDB_log', FILENAME = N'D:\TestDB_log.ldf' , SIZE = 1072KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) +GO +ALTER DATABASE [TestDB] SET COMPATIBILITY_LEVEL = 120 +GO +IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) +begin +EXEC [TestDB].[dbo].[sp_fulltext_database] @action = 'enable' +end +GO +ALTER DATABASE [TestDB] SET ANSI_NULL_DEFAULT OFF +GO +ALTER DATABASE [TestDB] SET ANSI_NULLS OFF +GO +ALTER DATABASE [TestDB] SET ANSI_PADDING OFF +GO +ALTER DATABASE [TestDB] SET ANSI_WARNINGS OFF +GO +ALTER DATABASE [TestDB] SET ARITHABORT OFF +GO +ALTER DATABASE [TestDB] SET AUTO_CLOSE OFF +GO +ALTER DATABASE [TestDB] SET AUTO_SHRINK OFF +GO +ALTER DATABASE [TestDB] SET AUTO_UPDATE_STATISTICS ON +GO +ALTER DATABASE [TestDB] SET CURSOR_CLOSE_ON_COMMIT OFF +GO +ALTER DATABASE [TestDB] SET CURSOR_DEFAULT GLOBAL +GO +ALTER DATABASE [TestDB] SET CONCAT_NULL_YIELDS_NULL OFF +GO +ALTER DATABASE [TestDB] SET NUMERIC_ROUNDABORT OFF +GO +ALTER DATABASE [TestDB] SET QUOTED_IDENTIFIER OFF +GO +ALTER DATABASE [TestDB] SET RECURSIVE_TRIGGERS OFF +GO +ALTER DATABASE [TestDB] SET ENABLE_BROKER +GO +ALTER DATABASE [TestDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF +GO +ALTER DATABASE [TestDB] SET DATE_CORRELATION_OPTIMIZATION OFF +GO +ALTER DATABASE [TestDB] SET TRUSTWORTHY OFF +GO +ALTER DATABASE [TestDB] SET ALLOW_SNAPSHOT_ISOLATION OFF +GO +ALTER DATABASE [TestDB] SET PARAMETERIZATION SIMPLE +GO +ALTER DATABASE [TestDB] SET READ_COMMITTED_SNAPSHOT OFF +GO +ALTER DATABASE [TestDB] SET HONOR_BROKER_PRIORITY OFF +GO +ALTER DATABASE [TestDB] SET RECOVERY FULL +GO +ALTER DATABASE [TestDB] SET MULTI_USER +GO +ALTER DATABASE [TestDB] SET PAGE_VERIFY CHECKSUM +GO +ALTER DATABASE [TestDB] SET DB_CHAINING OFF +GO +ALTER DATABASE [TestDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) +GO +ALTER DATABASE [TestDB] SET TARGET_RECOVERY_TIME = 0 SECONDS +GO +ALTER DATABASE [TestDB] SET DELAYED_DURABILITY = DISABLED +GO +EXEC sys.sp_db_vardecimal_storage_format N'TestDB', N'ON' +GO +USE [TestDB] +GO +/****** Object: Table [dbo].[ClassInfo] Script Date: 2021/3/15 16:11:24 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [dbo].[ClassInfo]( + [ClassId] [int] IDENTITY(1,1) NOT NULL, + [ClassName] [nvarchar](20) NOT NULL, +PRIMARY KEY CLUSTERED +( + [ClassId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +) ON [PRIMARY] + +GO +/****** Object: Table [dbo].[CourseInfo] Script Date: 2021/3/15 16:11:24 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [dbo].[CourseInfo]( + [CourseId] [int] IDENTITY(1,1) NOT NULL, + [CourseName] [nvarchar](50) NOT NULL, + [CourseCredit] [int] NULL DEFAULT ((1)), +PRIMARY KEY CLUSTERED +( + [CourseId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +) ON [PRIMARY] + +GO +/****** Object: Table [dbo].[Scores] Script Date: 2021/3/15 16:11:24 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [dbo].[Scores]( + [ScoreId] [int] IDENTITY(1,1) NOT NULL, + [StuId] [int] NULL, + [CourseId] [int] NULL, + [Score] [int] NULL DEFAULT ((0)), +PRIMARY KEY CLUSTERED +( + [ScoreId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +) ON [PRIMARY] + +GO +/****** Object: Table [dbo].[StuInfo] Script Date: 2021/3/15 16:11:24 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [dbo].[StuInfo]( + [StuId] [int] IDENTITY(1,1) NOT NULL, + [ClassId] [int] NULL, + [StuName] [nvarchar](10) NOT NULL, + [StuSex] [nvarchar](1) NULL DEFAULT ('男'), + [StuBrithday] [date] NULL, + [StuPhone] [nvarchar](11) NULL, + [StuProvince] [nvarchar](200) NULL, + [CreateDate] [datetime] NULL DEFAULT (getdate()), + [StuAge] [int] NULL, +PRIMARY KEY CLUSTERED +( + [StuId] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +) ON [PRIMARY] + +GO +SET IDENTITY_INSERT [dbo].[ClassInfo] ON + +GO +INSERT [dbo].[ClassInfo] ([ClassId], [ClassName]) VALUES (1, N'软件1班') +GO +INSERT [dbo].[ClassInfo] ([ClassId], [ClassName]) VALUES (2, N'软件2班') +GO +INSERT [dbo].[ClassInfo] ([ClassId], [ClassName]) VALUES (3, N'软件3班') +GO +INSERT [dbo].[ClassInfo] ([ClassId], [ClassName]) VALUES (4, N'软件4班') +GO +INSERT [dbo].[ClassInfo] ([ClassId], [ClassName]) VALUES (5, N'软件5班') +GO +INSERT [dbo].[ClassInfo] ([ClassId], [ClassName]) VALUES (6, N'软件6班') +GO +INSERT [dbo].[ClassInfo] ([ClassId], [ClassName]) VALUES (7, N'软件7班') +GO +SET IDENTITY_INSERT [dbo].[ClassInfo] OFF +GO +SET IDENTITY_INSERT [dbo].[CourseInfo] ON + +GO +INSERT [dbo].[CourseInfo] ([CourseId], [CourseName], [CourseCredit]) VALUES (1, N'计算机基础', 3) +GO +INSERT [dbo].[CourseInfo] ([CourseId], [CourseName], [CourseCredit]) VALUES (2, N'HTML+CSS网页制作', 5) +GO +INSERT [dbo].[CourseInfo] ([CourseId], [CourseName], [CourseCredit]) VALUES (3, N'JAVA编程基础', 5) +GO +INSERT [dbo].[CourseInfo] ([CourseId], [CourseName], [CourseCredit]) VALUES (4, N'SQL Server数据库基础', 4) +GO +INSERT [dbo].[CourseInfo] ([CourseId], [CourseName], [CourseCredit]) VALUES (5, N'C#面向对象编程', 5) +GO +INSERT [dbo].[CourseInfo] ([CourseId], [CourseName], [CourseCredit]) VALUES (6, N'Winform桌面应用程序设计', 5) +GO +SET IDENTITY_INSERT [dbo].[CourseInfo] OFF +GO +SET IDENTITY_INSERT [dbo].[Scores] ON + +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (1, 1, 1, 80) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (2, 1, 2, 78) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (3, 1, 3, 65) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (4, 1, 4, 90) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (5, 2, 1, 60) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (6, 2, 2, 77) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (7, 2, 3, 68) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (8, 2, 4, 88) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (9, 3, 1, 88) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (10, 3, 2, 45) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (11, 3, 3, 66) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (12, 3, 4, 75) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (13, 4, 1, 56) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (14, 4, 2, 80) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (15, 4, 3, 75) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (16, 4, 4, 66) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (17, 5, 1, 88) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (18, 5, 2, 79) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (19, 5, 3, 72) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (20, 5, 4, 85) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (21, 6, 1, 68) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (22, 6, 2, 88) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (23, 6, 3, 73) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (24, 6, 5, 63) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (25, 7, 1, 84) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (26, 7, 2, 90) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (27, 7, 3, 92) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (28, 7, 5, 78) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (29, 8, 1, 58) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (30, 8, 2, 59) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (31, 8, 3, 65) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (32, 8, 5, 75) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (33, 9, 1, 48) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (34, 9, 2, 67) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (35, 9, 3, 71) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (36, 9, 5, 56) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (37, 9, 5, 56) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (38, 1, 1, 85) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (39, 1, 2, 83) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (40, 1, 3, 70) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (41, 1, 4, 95) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (42, 2, 1, 65) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (43, 2, 2, 82) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (44, 2, 3, 73) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (45, 2, 4, 93) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (46, 3, 1, 93) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (47, 3, 2, 50) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (48, 3, 3, 71) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (49, 3, 4, 80) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (50, 4, 1, 61) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (51, 4, 2, 85) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (52, 4, 3, 80) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (53, 4, 4, 71) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (54, 5, 1, 93) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (55, 5, 2, 84) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (56, 5, 3, 77) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (57, 5, 4, 90) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (58, 6, 1, 73) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (59, 6, 2, 93) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (60, 6, 3, 78) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (61, 6, 5, 68) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (62, 7, 1, 89) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (63, 7, 2, 95) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (64, 7, 3, 97) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (65, 7, 5, 83) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (66, 8, 1, 63) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (67, 8, 2, 64) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (68, 8, 3, 70) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (69, 8, 5, 80) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (70, 9, 1, 53) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (71, 9, 2, 72) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (72, 9, 3, 76) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (73, 9, 5, 61) +GO +INSERT [dbo].[Scores] ([ScoreId], [StuId], [CourseId], [Score]) VALUES (74, 9, 5, 61) +GO +SET IDENTITY_INSERT [dbo].[Scores] OFF +GO +SET IDENTITY_INSERT [dbo].[StuInfo] ON + +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (1, 1, N'刘正', N'男', CAST(N'2002-08-02' AS Date), N'13245678121', N'广西省', CAST(N'2021-03-14 16:46:00.887' AS DateTime), 19) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (2, 1, N'黄贵', N'男', CAST(N'2003-07-02' AS Date), N'13345678121', N'江西省', CAST(N'2021-03-14 16:46:00.887' AS DateTime), 18) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (3, 1, N'陈美', N'女', CAST(N'2002-07-22' AS Date), N'13355678125', N'福建省', CAST(N'2021-03-14 16:46:00.887' AS DateTime), 19) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (4, 2, N'江文', N'男', CAST(N'2001-07-02' AS Date), N'13347678181', N'湖南省', CAST(N'2021-03-14 16:46:00.887' AS DateTime), 20) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (5, 2, N'钟琪', N'女', CAST(N'2004-01-13' AS Date), N'13345778129', N'安徽省', CAST(N'2021-03-14 16:46:00.887' AS DateTime), 17) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (6, 3, N'曾小林', N'男', CAST(N'2005-05-15' AS Date), N'13345378563', N'安徽省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 16) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (7, 3, N'欧阳天天', N'女', CAST(N'2000-08-19' AS Date), N'13347878121', N'湖北省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 21) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (8, 3, N'李逍遥', N'男', CAST(N'1999-09-02' AS Date), N'13345678557', N'广东省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 22) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (9, 4, N'刘德华', N'男', CAST(N'1995-06-11' AS Date), N'15345679557', N'福建省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 26) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (10, 4, N'刘翔', N'男', CAST(N'1996-07-09' AS Date), N'18346679589', N'江西省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 25) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (11, 4, N'曾小贤', N'男', CAST(N'2003-07-02' AS Date), N'18348979589', N'湖南省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 18) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (12, 5, N'刘德华', N'男', CAST(N'2002-07-02' AS Date), N'18348979509', N'湖北省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 19) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (13, 5, N'陈天翔', N'男', CAST(N'2003-07-02' AS Date), N'18348079509', N'湖北省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 18) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (14, 5, N'刘能', N'男', CAST(N'2005-08-02' AS Date), N'13245678122', N'广西省', CAST(N'2021-03-14 16:46:00.890' AS DateTime), 16) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (15, 5, N'钟馗', N'男', CAST(N'2004-08-02' AS Date), N'13245678123', N'广西省', CAST(N'2021-03-14 16:46:00.893' AS DateTime), 17) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (16, 5, N'钟吴艳', N'女', CAST(N'2002-08-02' AS Date), N'13245678124', N'广西省', CAST(N'2021-03-14 16:46:00.893' AS DateTime), 19) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (17, 5, N'刘欢', N'男', CAST(N'2001-07-02' AS Date), N'13245678125', N'湖南省', CAST(N'2021-03-14 16:46:00.893' AS DateTime), 20) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (18, 5, N'张庭', N'女', CAST(N'2000-07-02' AS Date), N'13245678126', N'江西省', CAST(N'2021-03-14 16:46:00.893' AS DateTime), 21) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (19, 5, N'曹植', N'男', CAST(N'2000-08-02' AS Date), N'13245678127', N'福建省', CAST(N'2021-03-14 16:46:00.893' AS DateTime), 21) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (20, 5, N'曹操', N'男', CAST(N'2002-08-02' AS Date), N'13245678128', N'', CAST(N'2021-03-14 16:46:00.893' AS DateTime), 19) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (21, 5, N'孙尚香', N'女', CAST(N'2003-08-02' AS Date), N'13245678129', N'', CAST(N'2021-03-14 16:46:00.893' AS DateTime), 18) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (22, 3, N'老1', N'女', CAST(N'2002-08-02' AS Date), N'13245678130', N'广东省', CAST(N'2021-03-14 17:02:36.347' AS DateTime), 19) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (24, 2, N'老2', N'男', CAST(N'2002-08-03' AS Date), N'13345678945', NULL, CAST(N'2021-03-14 17:03:37.733' AS DateTime), 19) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (25, 4, N'老3', N'男', NULL, N'13645987545', N'广东省', CAST(N'2021-03-14 17:03:43.307' AS DateTime), NULL) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (28, 5, N'老4', N'男', CAST(N'2006-03-05' AS Date), N'13456987456', NULL, CAST(N'2021-03-14 17:04:03.957' AS DateTime), 15) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (29, 5, N'老5', N'女', CAST(N'1998-04-12' AS Date), N'15978456123', NULL, CAST(N'2021-03-14 17:04:47.103' AS DateTime), 23) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (30, 4, N'老6', N'男', CAST(N'1996-08-06' AS Date), N'18945674561', NULL, CAST(N'2021-03-14 17:05:04.990' AS DateTime), 25) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (31, 3, N'老7', N'女', CAST(N'1997-04-06' AS Date), N'18845678912', NULL, CAST(N'2021-03-14 17:05:20.570' AS DateTime), 24) +GO +INSERT [dbo].[StuInfo] ([StuId], [ClassId], [StuName], [StuSex], [StuBrithday], [StuPhone], [StuProvince], [CreateDate], [StuAge]) VALUES (32, 2, N'老10', N'女', CAST(N'1998-08-09' AS Date), N'19945645612', NULL, CAST(N'2021-03-14 17:06:08.107' AS DateTime), 23) +GO +SET IDENTITY_INSERT [dbo].[StuInfo] OFF +GO +SET ANSI_PADDING ON + +GO +/****** Object: Index [UQ__CourseIn__9526E2773AB7BECE] Script Date: 2021/3/15 16:11:24 ******/ +ALTER TABLE [dbo].[CourseInfo] ADD UNIQUE NONCLUSTERED +( + [CourseName] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +GO +SET ANSI_PADDING ON + +GO +/****** Object: Index [UQ__StuInfo__2D85FC63AF6FC6FA] Script Date: 2021/3/15 16:11:24 ******/ +ALTER TABLE [dbo].[StuInfo] ADD UNIQUE NONCLUSTERED +( + [StuPhone] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] +GO +ALTER TABLE [dbo].[Scores] WITH CHECK ADD FOREIGN KEY([CourseId]) +REFERENCES [dbo].[CourseInfo] ([CourseId]) +GO +ALTER TABLE [dbo].[Scores] WITH CHECK ADD FOREIGN KEY([StuId]) +REFERENCES [dbo].[StuInfo] ([StuId]) +GO +ALTER TABLE [dbo].[StuInfo] WITH CHECK ADD FOREIGN KEY([ClassId]) +REFERENCES [dbo].[ClassInfo] ([ClassId]) +ON DELETE SET NULL +GO +ALTER TABLE [dbo].[CourseInfo] WITH CHECK ADD CHECK (([CourseCredit]>=(1) AND [CourseCredit]<=(5))) +GO +ALTER TABLE [dbo].[StuInfo] WITH CHECK ADD CHECK ((len([StuPhone])=(11))) +GO +ALTER TABLE [dbo].[StuInfo] WITH CHECK ADD CHECK (([StuSex]='女' OR [StuSex]='男')) +GO +USE [master] +GO +ALTER DATABASE [TestDB] SET READ_WRITE +GO + + +--统计每个班的男生数 + select ClassId 班,count(StuSex) 数 from StuInfo where StuSex='男' group by ClassId + +--统计每个班的男、女生数 +select ClassId 班,StuSex 性别,count(StuSex) 数 from StuInfo group by ClassId,StuSex + +--统计每个班的福建人数StuProvince +select ClassId 班,count(StuName) 人数,StuProvince from StuInfo group by ClassId,StuProvince having StuProvince='福建省' + +--统计每个班的各个省的总人数 +select ClassId 班,StuProvince 省,count(StuName) from StuInfo group by ClassId,StuProvince + +--统计每个省的女生数 +select StuProvince,count(StuName) 数,StuSex 省 from StuInfo group by StuProvince,StuSex having StuSex='女' + + +--统计每个省的男、女生数 +select StuProvince,count(StuName) 数,StuSex 省 from StuInfo group by StuProvince,StuSex + +--统计每个学生的考试总分、平均分 +select StuId 学生,sum(Score) 总分,AVG(Score) 平均分 from Scores group by StuId + +--统计出考试总分大于620的学生的考试总分 +select StuId 学生,sum(Score) from Scores group by StuId having sum(Score)>620 + +--统计出每门考试成绩最高分和最低分 +select top 1 Score from Scores order by Score--低 +select top 1 Score from Scores order by Score desc --高 + +--统计出 每个学生的各门成绩的平均分 +select CourseId 课程,AVG(Score) 平均分 from Scores group by CourseId + +select itemName,count(*)订购次数,sum(theNumber) 订购总数量,avg(theMoney)平均单价 from orderItem group by itemName \ No newline at end of file diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy2.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy2.sql" new file mode 100644 index 0000000..06236a0 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy2.sql" @@ -0,0 +1,90 @@ +create database Student +on +( + FileName='D:\Student.mdf', + Name='Student', + size=5MB, + maxsize=5MB, + filegrowth=3MB +) +log on +( + FileName='D:\Student_log.ldf', + Name='Student_log', + size=5MB, + maxsize=5MB, + filegrowth=3MB +) +go + +use Student + +go + +create table Student +( + StuNo varchar(10) primary key not null, + StuName nvarchar(10) not null, + StuAge int, + StuAddress nvarchar(20), + StuSeat int, + StuSex int check(StuSex=1 or StuSex=0) not null +) + +create table Score +( + ExamNo int primary key identity(1,1) not null, + StuNo varchar(10) not null, + WrittenExam int default(0) not null, + LabExam int not null +) + + +insert into Student values +('s2501','张秋利',20,'美国硅谷',1,1), +('s2502','李斯文',18,'湖北武汉',2,0), +('s2503','马文才',22,'湖南长沙',3,1), +('s2504','欧阳俊雄',21,'湖北武汉',4,0), +('s2505','梅超风',20,'湖北武汉',5,1), +('s2506','陈旋风',19,'美国硅谷',6,1), +('s2507','陈风',20,'美国硅谷',7,0), +('s2508','陈风',20,'美国硅谷',7,0) + + +delete from Student + +select * from Student + + +insert into Score values +('s2501',50,70), +('s2502',60,65), +('s2503',86,85), +('s2504',40,80), +('s2505',70,90), +('s2506',85,90), +('s2507',85,90) + +delete from Score + + + + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from Student St inner join Score S on St.StuNo=S.StuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from Student St inner join Score S on St.StuNo=S.StuNo where WrittenExam>60 and LabExam>60 + +--3.查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select St.StuNO 学号,StuName 姓名,WrittenExam 笔试成绩,LabExam 机试成绩 from Student St left join Score S on St.StuNo=S.StuNo + +--4.查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select StuName 姓名,StuAge 年龄,WrittenExam 笔试成绩,LabExam 机试成绩 from Student St inner join Score S on St.StuNo=S.StuNo where StuAge>=20 order by WrittenExam DESC + +--5.查询男女生的机试平均分 +select AVG(LabExam) from Student St inner join Score S on St.StuNo=S.StuNo + +--6.查询男女生的笔试总分 + +select sum(WrittenExam) from Student St inner join Score S on St.StuNo=S.StuNo diff --git "a/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy3.sql" "b/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy3.sql" new file mode 100644 index 0000000..e2efae7 --- /dev/null +++ "b/20210326\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy3.sql" @@ -0,0 +1,83 @@ +create database OrderForm +on +( + FileName='D:\OrderForm.mdf', + Name='OrderForm', + size=5MB, + Maxsize=5MB, + Filegrowth=1MB +) +log on +( + FileName='D:\OrderForm_log.ldf', + Name='OrderForm_log', + size=5MB, + Maxsize=5MB, + Filegrowth=1MB +) +go + +use OrderForm +go + +create table orders +( + orderID int primary key identity(1,1), + orderDate datetime +) + +create table orderltem +( + ltemID int identity(1,1), + orderID int , + itemType nvarchar(15), + itemName nvarchar(10), + theNumber int , + theMoney money +) + +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 orderltem values +(1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'生活用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书机',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'生活用品','毛巾',4,5), +(4,'生活用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3) + + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select OS.orderID 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价 from orderltem OS inner join orders O on OS.orderID=O.orderID + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select OS.orderID 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称 from orderltem OS inner join orders O on OS.orderID=O.orderID where theNumber>50 + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select OS.orderID 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 from orderltem OS inner join orders O on OS.orderID=O.orderID + + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select OS.orderID 订单的编号,orderDate 订单日期,itemType 订购产品的类别,itemName 订购的产品名称,theNumber 订购数量,theMoney 订购单价,theNumber*theMoney 订购总价 from orderltem OS inner join orders O on OS.orderID=O.orderID where theMoney>=5 and theNumber>=50 + + + +--5.查询每个订单分别订购了几个产品,例如: +-- 编号 订购产品数 +-- 1 3 +-- 2 4 +select orderID 订单编号,theNumber 订购产品数 from orderltem group by orderID,theNumber \ No newline at end of file -- Gitee From 4268a5f58edbf983c2bc1479ebdf5299068b0caf Mon Sep 17 00:00:00 2001 From: putar Date: Mon, 29 Mar 2021 11:09:30 +0800 Subject: [PATCH 062/195] 2021-3-29 11:09 --- .../SQLQuery1.sql" | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" new file mode 100644 index 0000000..54c5341 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" @@ -0,0 +1,83 @@ +use master +go + +create database Student +go + +use Student +go + +create table stuInfo +( + stuID int primary key identity(1,1), + stuName varchar(10), + stuAge int, + stuSex int check(stuSex in(0,1)), + [time] datetime +) +go + +create table courseInfo +( + courseID int primary key identity(1,1), + courseName char(20), + courseMarks int +) +go + +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int +) +go + +insert into stuInfo(stuName,stuAge,stuSex) values ('Tom',19,1), +('Jack',20,0),('Rose',21,1),('Lulu',19,1), +('Lili',21,0) +insert into StuInfo values ('abc',20,1,'2007-01-07 01:11:36.590') + +insert into courseInfo values ('JavaBase',4), +('HTML',2),('JavaScript',2),('SqlBase',2) + +insert into scoreInfo 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 stuName,COUNT(CI.courseID) 选课数量,AVG(score)平均分 from stuInfo SI +left join scoreInfo SC on SI.stuID = SC.stuID +left join courseInfo CI on CI.courseID = SC.courseID group by stuName +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName,COUNT(SC.stuID)选修学生人数,SUM(score)考试总分 from stuInfo SI inner join scoreInfo SC on SI.stuID = SC.stuID +inner join courseInfo CI on CI.courseID = SC.courseID group by CI.courseName +--3.查询出性别一样并且年龄一样的学生的信息 +select * from stuInfo A inner join stuInfo B on A.stuAge = B.stuAge +where (A.stuSex = B.stuSex) and (A.stuName != B.stuName) +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A inner join courseInfo B on A.courseMarks = B.courseMarks +where (A.courseName != B.courseName) and (A.courseMarks = B.courseMarks) +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select SI.stuID,SI.stuName,CI.courseID,SC.score from stuInfo SI +inner join scoreInfo SC on SI.stuID = SC.stuID +inner join courseInfo CI on SC.courseID = CI.courseID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select SI.stuID,SI.stuName,CI.courseID,CI.courseMarks,SC.score from stuInfo SI +inner join scoreInfo SC on SI.stuID = SC.stuID +inner join courseInfo CI on SC.courseID = CI.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select stuID,stuName from stuInfo +except +select distinct SI.stuID,SI.stuName from stuInfo SI +inner join scoreInfo SC on SI.stuID = SC.stuID +inner join courseInfo CI on SC.courseID = CI.courseID +--8.查询出是周六周天来报到的学生 +select * from stuInfo where DATEPART(dw,[time]) in(0,1) +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select SI.stuID,AVG(score)考试平均分,COUNT(SC.stuID)选修课程数量 from stuInfo SI +inner join scoreInfo SC on SI.stuID = SC.stuID +inner join courseInfo CI on SC.courseID = CI.courseID + group by SI.stuID having COUNT(SC.stuID) > 2 and AVG(score) > 70 \ No newline at end of file -- Gitee From 86d8850e534296109e7fa1cb19b0d5c64456d75c Mon Sep 17 00:00:00 2001 From: EoL <1179233990@qq.com> Date: Mon, 29 Mar 2021 11:21:10 +0800 Subject: [PATCH 063/195] 1 --- .../\344\275\234\344\270\232/1.bmp" | Bin 0 -> 1110294 bytes .../\344\275\234\344\270\232/2.bmp" | Bin 0 -> 1116774 bytes .../\344\275\234\344\270\232\344\270\200.txt" | 23 +++++++ .../\344\275\234\344\270\232\344\272\214.txt" | 47 ++++++++++++++ .../SQLQuery1.sql" | 60 ++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/1.bmp" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/2.bmp" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.txt" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.txt" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/1.bmp" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/1.bmp" new file mode 100644 index 0000000000000000000000000000000000000000..65b6cf3101996a4c52218b7a5dad3fa9880001ad GIT binary patch literal 1110294 zcmeIbO|mRIu4Z>tB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~ggg`bpL12hT z6X9aEKmHt0`ywC$BCwhOKY{u2%f4wmy&*gx48y7~4o7<7^0<*oTYR2!hktt7Dzce` zD+zkA5o`y6jjGzJNG^b5*f%{`7|OtM!?Sr{TAkQPo57$SKV+`{S`P5DJY1VrG+ z3GhRhAHVFI#?u?Z1Hv$@`r>e;mr$Pdf={zMo8=`w%s=y5jrPiOyk4b z!8E}>wENiF{jdtNgM}fvFXSyav-_A00>e-eCr6A6`^g{QJ^bVre*8J0_C-JhL|`=m zeggC3mwnUr=ynI9ISi}5IPCY*e-n9+=(Iny9udhpn{XgFzG5}lNOQSw#M^lod`!VX zp2|T$zc7TE2)n?6pPjHfM@~rUU-nJofe+yU zVHj3@aX8XTXu*2%56bQgZHmJx%^9+02N{AGY$VjfnK9)i4{a}w#1Jt}$15Bx%rp2B zWD7%Vhhp4ezrO_WSc1LSK@u0-!jC@()V>IafC#K6z)xU){IYKv4{Zn!2*a@Ii^Gv# zuC&07S9+vSqxvYjZvmhdXpgXN8caSN+&H02io5fFhNC%}(o ze*Cg;8V`I3Hbd|eh9kXro!rr2<^3i7*|5c7@L(gIJe{df%tyn)!Yt>B0&EGdV*OE( z{a|k4$DadgUj#%z1XdH^2Qoi?**A>`{$Hdt!eq8h8m;E>DZF+fZBaba? z{EsWQ@Z-+`wJ!o9AOfoi@WYuOzwEzJZ_~?T8+mMD<9}Sah1EBj@{527h`^5%;D<9m ze%XJc-lmtwHuBiQ#{al-3qSrGQ2Qbv0wQoT0sMXRH}AV*yKQ=TY$J~?Z2XVY1}%&? zt4I+L0TK8j0ejx+BLX5I0wS=8z!x9y+FAr2MZkWgtd9tYfCz}dA_9+k;HwxB_#%Pv z|FK(2z+|)4944kQ?Or7KB`j{BLX5I0wN#+BJeE&|363w B#IpbZ literal 0 HcmV?d00001 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.txt" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.txt" new file mode 100644 index 0000000..5a119a7 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.txt" @@ -0,0 +1,23 @@ +有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +题目: +1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 + +2.查询出每门课程的选修的学生的个数和学生考试的总分 + +3.查询出性别一样并且年龄一样的学生的信息 + +4.查询出学分一样的课程信息 + +5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +7.查询出没有参加考试的学生的学号和姓名 + +8.查询出是周六周天来报到的学生 + +9.查询出姓名中有字母a的学生的信息 + +10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.txt" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.txt" new file mode 100644 index 0000000..67f84f7 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.txt" @@ -0,0 +1,47 @@ +首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: + +表一为上网卡信息表(tbl_card) +id: 卡号,主键 +passWord:密码 +balance:卡上的余额 +userName:该上网卡所属的用户名 + +表2为网吧机器说明表(tbl_computer) +id:机器编号,主键 +onUse:该机器是否正在使用,0为未使用,1为正在使用 +note:该机器的说明 + + +表3为上网记录表(tbl_record): +id:记录编号,主键 +cardId:本次上网的卡号,外键 +ComputerId:本次上网记录所使用的机器号,外键 +beginTime:本次上网记录的开始时间 +endTime:本次上网记录的结束时间 +fee:本次上网的费用 + + +请完成以下题目: +1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 + +2. 查询出每台机器上的上网次数和消费的总金额 + +3. 查询出所有已经使用过的上网卡的消费总金额 + +4. 查询出从未消费过的上网卡的卡号和用户名 + +5. 将密码与用户名一样的上网卡信息查询出来 + +6. 查询出使用次数最多的机器号和使用次数 + +7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + +8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + + + + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" new file mode 100644 index 0000000..613d827 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" @@ -0,0 +1,60 @@ +use master +go +create database student +on +( +name='student', +filename='D:\SQL\student.mdf', +size=10mb, +maxsize=100mb, +filegrowth=5mb +) +log on +( +name='student_log', +filename='D:\SQL\student_log.mdf', +size=10mb, +maxsize=100mb, +filegrowth=5mb +) +use student +go +create table stuinfo +( +stuid int primary key identity, +stuname nvarchar(10), +stuage int, +stusex char(1) check(stusex=0 or stusex=1), +time datetime, +) +create table courseinfo +( +courseid int primary key identity, +coursename nvarchar(10), +coursemarks int, +) +create table sores +( +scoreid int primary key identity, +stuid int, +courseid int, +score int +) +insert into stuinfo values('Tom',19,1,''),('Jack',20,0,''),('Rose',21,1,''),('Lulu',19,1,''),('Lili',21,0,''),('abc',20,1,'2007-01-07 01:11:36.590') +insert into courseinfo values('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) +insert into sores 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) +select * from stuinfo +select * from courseinfo +select * from sores +select stuname,count(*) 课程数量,AVG(score) 平均分 from stuinfo s1 left join sores s2 on s1.stuid=s2.stuid group by stuname +select coursename,count(stuid) 学生个数,sum(score) 总分 from courseinfo c left join sores s2 on c.courseid=s2.courseid group by coursename +select A.* from stuinfo A inner join stuinfo B on A.stuage=B.stuage where A.stusex=B.stusex and A.stuname != B.stuname and A.stuage=B.stuage +select distinct A.* from courseinfo A inner join courseinfo B on A.coursemarks=B.coursemarks where A.coursemarks=B.coursemarks and A.courseid !=B.courseid +select s1.stuid,stuname,c.courseid,score from stuinfo s1 inner join sores s2 on s1.stuid=s2.stuid inner join courseinfo c on s2.courseid=c.courseid +select s1.stuid,c.courseid,coursename,coursemarks,score from stuinfo s1 inner join sores s2 on s1.stuid=s2.stuid inner join courseinfo c on s2.courseid=c.courseid +select s1.stuid,stuname from stuinfo s1 left join sores s2 on s1.stuid=s2.stuid left join courseinfo c on s2.courseid=c.courseid +except +select s1.stuid,stuname from stuinfo s1 inner join sores s2 on s1.stuid=s2.stuid inner join courseinfo c on s2.courseid=c.courseid +select * from stuinfo where DATEPARt(dw,time) in (0,1) +select * from stuinfo where stuname like '%a%' +select s1.stuid,AVG(s2.score) 平均分,count(coursename) 课程数量 from stuinfo s1 inner join sores s2 on s1.stuid=s2.stuid inner join courseinfo c on s2.courseid=c.courseid group by s1.stuid having count(coursename)>=2 and AVG(score)>=70 \ No newline at end of file -- Gitee From 5d0248064193db643442e7b120828339d4d8ea84 Mon Sep 17 00:00:00 2001 From: putar Date: Mon, 29 Mar 2021 11:25:55 +0800 Subject: [PATCH 064/195] 2021-3-29 11:25 --- .../SQLQuery2.sql" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" new file mode 100644 index 0000000..c005cb2 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" @@ -0,0 +1,36 @@ +use master +go + +create database InternetBar +go + +use InternetBar +go + +create table tbl_card +( + id char(8) primary key, + password nchar(10), + balance money, + userName nchar(2) +) +go + +create table tbl_computer +( + id int primary key, + onUse int check(onUse in(0,1)), + note text +) +go + +create table tbl_record +( + id int primary key, + cardID char(8) references tbl_card(id), + ComputerID int references tbl_computer(ID), + beginTime datetime, + endTime datetime, + fee money +) +go -- Gitee From d4c49349902f9686645f1c4af171b987d275640b Mon Sep 17 00:00:00 2001 From: putar Date: Mon, 29 Mar 2021 11:34:38 +0800 Subject: [PATCH 065/195] 2021-03-29 11:34 --- .../\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" | 5 +++++ 1 file changed, 5 insertions(+) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" index c005cb2..66385d8 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" @@ -34,3 +34,8 @@ create table tbl_record fee money ) go + +insert into tbl_card values('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张峻') -- Gitee From 0821bd4fe0046303b29191c768b20440f9f8f696 Mon Sep 17 00:00:00 2001 From: zhangyife2020 <1599857331@qq.com> Date: Mon, 29 Mar 2021 17:50:39 +0800 Subject: [PATCH 066/195] =?UTF-8?q?=E7=AC=AC11=E6=AC=A1=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git commit -m绗11娆′綔涓氣 --- .../SQLQuery1.sql" | 97 +++++++++++++ .../SQLQuery2.sql" | 131 ++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" new file mode 100644 index 0000000..44b8c4f --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" @@ -0,0 +1,97 @@ +use wb +go +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +create table stuInfo +( + stuID int primary key identity, + stuName char(10), + stuAge int, + stuSex int, + time datetime +) +create table courseInfo +( + courseID int primary key identity, + courseName char(20), + courseMarks int +) +create table scoreInfo +( + scoreID int primary key identity, + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int +) +insert into stuInfo values('Tom',19,1,''),('Jack',20,0,''),('Rose',21,1,''), + ('Lulu',19,1,''),('Lili',21,0,''),('abc',20,1,'2007-01-07 01:11:36.590') + +insert into courseInfo values('JavaBase',4),('HTML',2), + ('JavaScript',2),('SqlBase',2) + +insert into scoreInfo 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) +--题目: +select*from stuInfo +select*from courseInfo +select*from scoreInfo + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuName 学生姓名,count(courseID)选课数量, avg(score)所选课考试的平均分 + from scoreInfo + join stuInfo + on scoreInfo.stuID = stuInfo.stuID + group by stuInfo.stuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName 课程名称, count(stuID)学生个数 ,sum(score)考试总分 + from scoreInfo + join courseInfo + on courseInfo.courseID=scoreInfo.courseID + group by courseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A ,stuInfo B + where A.stuSex=B.stuSex + and A.stuAge=B.stuAge + and A.stuID != B.stuID + +--4.查询出学分一样的课程信息 + +select*from courseInfo + where courseMarks in ( select courseMarks from courseInfo + group by courseMarks + having count(courseMarks)>=2 + ) + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuInfo.stuID 学号,stuName 姓名,courseID 课程号,score 分数 + from stuInfo + join scoreInfo + on stuInfo.stuID=scoreInfo.stuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuInfo.stuID 学号,stuName 姓名, scoreInfo .courseID 课程号,courseName 课程名,courseMarks 课程学分,score 分数 + from stuInfo + join scoreInfo + on stuInfo.stuID=scoreInfo.stuID + join courseInfo + on courseInfo.courseID=scoreInfo.courseID + +--7.查询出没有参加考试的学生的学号和姓名 + +select stuID 学号,stuName 姓名 from stuInfo where stuID in +( + select stuID from stuInfo + except + select stuID from scoreInfo +) + +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select*from stuInfo where stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuID 学号,count(courseID)课程数, avg(score)考试平均分 from scoreInfo group by stuID having count(courseID)>=2 and avg(score)>=70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery2.sql" new file mode 100644 index 0000000..d48b68d --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery2.sql" @@ -0,0 +1,131 @@ +use master +go +create database wb +on +( name='wb', + filename='D:\wb-mdf', + size=5, + maxsize=500, + filegrowth=1 +) + log on +( name='wb_log', + filename='D:\wb_log-ldf', + size=5, + maxsize=500, + filegrowth=1 +) +go +use wb +go +create table tbl_card +( + id varchar(8) primary key, + passWord varchar(15) not null, + balance money not null, + userName nchar(5) +) +create table tbl_computer +( + id char(5) primary key, + onUse int not null, + note text not null +) +create table tbl_record +( + id int primary key, + cardld varchar(8) references tbl_card(id), + ComputerId char(5) references tbl_computer(id), + beginTime datetime , + endTime datetime, + fee money not null +) +insert into tbl_card values('0023_ABC','555',99,'张军'),('0025_bbd','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳'),('0045_YGR','0045_YGR',58,'验证'),('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张俊') + +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'888888'),('06',0,'688878'),('B01',0,'558558') + + +insert into tbl_record values('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), + ('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), + ('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), + ('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), + ('47','0023_ABC','03','2006-12-23 15:26:00','2007-12-23 22:55:00','50'), + ('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), + ('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), + ('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), + ('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), + ('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +select*from tbl_card +select*from tbl_computer +select*from tbl_record +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select cardld 卡号, userName 用户名, beginTime 开始时间, endTime 结束时间, fee 消费金额 + from tbl_record + join tbl_computer + on tbl_computer.id=tbl_record.ComputerId + join tbl_card + on cardld=tbl_card.id + where userName='张军' + order by fee + + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId, count(ComputerId) 上网次数,sum(fee) 消费总金额 + from tbl_record + group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardld 网卡, sum(fee) 消费总金额 from tbl_record group by cardld + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id 卡号 , userName 用户名 + from tbl_card + where id not in (select cardld from tbl_record ) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select T.id 卡号,T.passWord 密码,T.balance 卡上的余额,T.userName 用户名 + from tbl_card,tbl_card T + where tbl_card.passWord=T.userName + +select T.* + from tbl_card,tbl_card T + where tbl_card.passWord=T.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号, count(ComputerId) 使用次数 + from tbl_record + group by ComputerId + order by count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,fee 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + where cardld like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + where datediff(HOUR,beginTime,endTime)>=12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + order by fee desc + + + + -- Gitee From b8af0ae507d7822cec639a5b7f89436c3536aaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0=E6=96=B0?= <2523868292@qq.com> Date: Mon, 29 Mar 2021 21:52:52 +0800 Subject: [PATCH 067/195] =?UTF-8?q?=E7=BD=97=E5=AE=87=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery14.sql" | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" new file mode 100644 index 0000000..f1b5ecd --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" @@ -0,0 +1,195 @@ +create database Student +on +( +name='Student', +filename='D:\sql.mdl', +size=5mb, +maxsize=50mb, +filegrowth=10mb +) +log on +( +name='Student_log', +filename='D:\sql.ldf', +size=5mb, +maxsize=50mb, +filegrowth=10mb +) +go +use Student +go + +create table stuInfo +( +stuID int primary key identity(1,1) not null, +stuName varchar(20) not null, +stuAge int not null, +stuSex char(2) not null, +time datetime +) + +create table courseInfo +( +courseID int primary key identity(1,1) not null, +courseName varchar(20) not null, +courseMarks int not null +) + +create table scoreInfo +( +scoreID int primary key identity(1,1) not null, +stuID int not null, +courseID int not null, +score int not null, +) + +insert into stuInfo(stuName,stuAge,stuSex) values ('Tom','19','1'),('Jack','20','0'), +('Rose','21','1'),('Lulu','19','1'),('Lili','21','0') +insert into stuInfo values('abc','20','1','2007-01-07 01:11:36.590') + +insert into courseInfo values ('JavaBase','4'),('HTML','2'),('JavaScript','2'),('SqlBase','2') + +insert into scoreInfo 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 stuID 学生,count(courseID) 数量,AVG(score) 平均分 from scoreInfo group by stuID + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + +select courseName 课程,count(stuID) 学生个数,sum(score) 总分 from scoreInfo inner join courseInfo +on scoreInfo.courseID=courseInfo.courseID group by courseInfo.courseID,courseName + +--3.查询出性别一样并且年龄一样的学生的信息 + +select * from stuInfo where stuAge in (select stuAge from stuInfo +group by stuAge,stuSex having count(stuAge)>1)--法1 + +select + +--4.查询出学分一样的课程信息 + +select * from courseInfo where courseMarks in (select courseMarks from courseInfo +group by courseMarks having count(courseMarks)>1) + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程,score 分数 +from scoreInfo inner join stuInfo on scoreInfo.stuID=stuInfo.stuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +select stuID 学号,courseInfo.courseID 课程号,courseName 课程名,courseMarks 学分,score 分数 +from courseInfo inner join scoreInfo on courseInfo.courseID=scoreInfo.courseID + +--7.查询出没有参加考试的学生的学号和姓名 +select stuID,stuName from stuInfo +EXCEPT +select stuInfo.stuID,stuName from scoreInfo +inner join stuInfo on scoreInfo.stuID=stuInfo.stuID + +--8.查询出是周六周天来报到的学生 +select stuname,time from stuInfo where time =CONVERT(datetime,time) group by time,stuname + +select * from stuInfo +select * from courseInfo +select * from scoreInfo + +--9.查询出姓名中有字母a的学生的信息 + +select * from stuInfo where stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select stuID,avg(score) 平均分,count(courseID) 选修课程数量 from scoreInfo group by stuID +having avg(score) >70 and count(courseID)>2 + + + +--首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: +create database wbfee +on +( + name='wbfee', + filename='D:\wbfee.mdf', + size=10Mb, + maxsize=50Mb, + filegrowth=10% +) +log on +( + name='wbfee_log', + filename='D:\wbfee_log.ldf', + size=10Mb, + maxsize=50Mb, + filegrowth=10% +) +go + +use wbfee +go +--表一为上网卡信息表(tbl_card) +--id: 卡号,主键 +--passWord:密码 +--balance:卡上的余额 +--userName:该上网卡所属的用户名 +create table tbl_card +( + ID varchar(8) primary key, + PassWord nvarchar(50) not null, + Balance int, + UserName nvarchar(20) +) +insert into tbl_card values +('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',68,'证验'), +('0078_RJV','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张峻') +--表2为网吧机器说明表(tbl_computer) +--id:机器编号,主键 +--onUse:该机器是否正在使用,0为未使用,1为正在使用 +--note:该机器的说明 +create table tbl_computer +( + ID varchar(3) primary key, + OnUse varchar(1) check(OnUse='1' or OnUse='0'), + Note varchar(20) +) +insert into tbl_computer values +('02','0','25555'), +('03','1','55555'), +('04','0','66666'), +('05','1','88888'), +('06','0','688878'), +('B01','0','558558') +--表3为上网记录表(tbl_record): +--id:记录编号,主键 +--cardId:本次上网的卡号,外键 +--ComputerId:本次上网记录所使用的机器号,外键 +--beginTime:本次上网记录的开始时间 +--endTime:本次上网记录的结束时间 +--fee:本次上网的费用 +create table tbl_record +( + ID int primary key, + CardID varchar(8) references tbl_card(ID), + ComputerID varchar(3) references tbl_computer(ID), + BeginTime datetime, + EndTime datetime, + Fee int +) +insert into tbl_record values +(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2007-07-21 15:26:00','2007-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), +(65,'0025_bbd','02','2006-12-28 18:00:00','2007-12-28 22:00:00',23), +(98,'0025_bbd','B01','2007-12-26 18:00:00','2007-12-26 22:00:00',23) \ No newline at end of file -- Gitee From ec23b4a96718209d15a55eaf8bb27cfd41a96f6a Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 29 Mar 2021 22:20:57 +0800 Subject: [PATCH 068/195] 777 --- .../\347\273\203\344\271\2401.sql" | 104 +++++++++++++++++ .../\347\273\203\344\271\2402.sql" | 107 ++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2401.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2401.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2401.sql" new file mode 100644 index 0000000..e561233 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2401.sql" @@ -0,0 +1,104 @@ +drop database Stuinfo +create database Stuinfo + +on +( + name='Stuinfo', + filename='F:\Stuinfo.mdf' +) +log on +( + name='Stuinfo_log', + filename='F:\Stuinfo.ldf_log' +) +use Stuinfo +create table stuInfo +( + stuID int primary key , + stuName varchar(20), + stuAge int , + stuSex nvarchar(1), + stime datetime +) + +create table courseInfo +( + courseID int primary key , + courseName varchar(25), + courseMarks varchar(5) +) +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int foreign key references stuInfo(stuID) , + courseID int foreign key references courseInfo(courseID), + score int +) +--学生信息表 +insert into stuInfo(stuID,stuName,stuAge,stuSex) +select 1,'Tom',19,1 union +select 2,'Jack',20,0union +select 3,'Rose',21,1union +select 4,'Lulu',19,1 union +select 5,'Lili',21,0union +select 6,'abc',20,1 + +update stuInfo set stime='2007-01-07 01:11:36.590'where stuName='abc' +--课程表 +insert into courseInfo(courseID,courseName,courseMarks) +select 1,'JavaBase',4 union +select 2,'HTML',2 union +select 3,'JavaScript',2 union +select 4,'SqlBase',2 +-- 成绩表 +insert into scoreInfo(stuID,courseID,score) +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +select * from stuInfo --学生信息表 +select * from courseInfo --课程表 +select * from scoreInfo -- 成绩表 +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseID 课程, count(courseID)选修个数, sum(score)总分 from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A, stuInfo B +where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stuID!=B.stuID +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks AND A.courseID!=B.courseID +--5.查询出参加了 考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo +left join stuInfo on scoreInfo.stuID=stuInfo.stuID group by scoreInfo.stuID,stuName,courseID,score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo +left join courseInfo on scoreInfo.courseID=courseInfo.courseID +--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 stuName like '%a%' +--10.查询出 选修了2门课程 以上的 并且 考试平均分 在70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo +group by stuID +having avg(score)>=70 and count(courseID)>=2 + +select * from courseInfo --课程表 +select * from scoreInfo -- 成绩表 +select * from stuInfo --学生信息表 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" new file mode 100644 index 0000000..3709fb8 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" @@ -0,0 +1,107 @@ +create database wb +on +( + name='wb', + filename='F:\wb.mdf' +) +log on +( + name='wb_log', + filename='F:\wb_log.ldf' +) +use wb +go + +create table card +( + id varchar(30) primary key, + pasword varchar(30), + balance money, + userName varchar(50) +) +create table computer +( + id varchar(30) primary key, + onUse varchar(2) check(onUse=0 or onUse=1), + note ntext +) +create table record +( + id varchar(30) primary key, + cardId varchar(30) foreign key references card(id), + ComputerId varchar(30) foreign key references computer(id), + beginTime datetime, + endTime datetime, + fee money +) + --上网卡信息表 +insert into card(ID,pasword,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' +--网吧机器说明表 +insert into computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' +--上网记录表 +insert into record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from card --上网卡信息表 +select * from computer --网吧机器说明表 +select * from record --上网记录表 +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号, +--用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select card.id 卡号, card.userName 用户名 ,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from card inner join record on card.id=record.cardId where userName='张军' order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 from record group by cardId,ComputerId +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId,sum(record.fee) 总金额 from record group by cardId +--4. 查询出从未消费过的上网卡的卡号和用户名 +select * from card where (select record.id from record) +--5. 将密码与用户名一样的上网卡信息查询出来 + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId)使用次数 from record +group by ComputerId order By count(ComputerId) desc + +select * from card --上网卡信息表 +select * from record --上网记录表 +select * from computer --网吧机器说明表 + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 +from record inner join card on record.cardId=card.id where record.cardId like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号, +--用户名,机器号,开始时间、结束时间和消费金额 +--超纲 +--9. 查询成一次上网时间超过12小时的的上网记录, +--要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +--超纲 +--10. 查询除消费金额排列前三名(最高)的上网记录, +--要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc + + +select * from card --上网卡信息表 +select * from computer --网吧机器说明表 +select * from record --上网记录表 +select cardId from record group by cardId--上网记录表 + -- Gitee From 368d3c87a500f0771bc2249ec62145e29beb23dc Mon Sep 17 00:00:00 2001 From: chenshuaihui <1926162199@qq.com> Date: Tue, 30 Mar 2021 16:19:07 +0800 Subject: [PATCH 069/195] 3.30 --- .../SQLQuery1.sql" | 79 ++++++++++++++++++ .../SQLQuery2.sql" | 82 +++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" new file mode 100644 index 0000000..228d65a --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" @@ -0,0 +1,79 @@ +use master +go +create database Student +go +use Student +go +create table stuInfo +( + stuID int primary key identity, + stuName varchar(20)not null, + stuAge int not null, + stuSex int check (stuSex=0 or stuSex=1), + time datetime , +) +insert into stuInfo +select 'Tom',19,1,null union +select 'Jack',20,0,null union +select 'Rose',21,1,null union +select 'Lulu',19,1,null union +select 'Lili',21,0,null union +select 'abc',20,1,'2007-01-07' +select * from stuInfo + +create table courseInfo +( + courseID int primary key identity, + courseName varchar(20) not null, + courseMarks int +) +insert into courseInfo values ('JavaBase',4),('HTML',2),('JavaScipt',2),('SqBase',2) +select * from courseInfo +create table scoreInfo +( + scoreID int primary key identity, + stuID int references stuInfo (stuID), + coureID int references courseInfo (courseID), + score int +) +insert into scoreInfo 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) +select * from scoreInfo +select * from courseInfo +select * from stuInfo + + + + + + + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuInfo.stuID 学生 ,count(courseMarks) 课程数量,avg(score) 平均分 from scoreInfo + inner join stuInfo on stuInfo.stuID=scoreInfo.stuID inner join courseInfo on scoreInfo.stuID=courseInfo.courseID group by stuInfo.stuID + + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName 课程, count(stuID)个数,sum(score) 总分 from scoreInfo inner join courseInfo on courseInfo.courseID=scoreInfo.coureID group by courseName +--3.查询出性别一样并且年龄一样的学生的信息 +select a.stuName 学生信息 ,a.stuAge 年龄,a.stuSex 性别 from stuInfo a ,stuInfo b where a.stuAge = b.stuAge and b.stuSex=a.stuSex and a.stuID!=b.stuID + +--4.查询出学分一样的课程信息 +select distinct a.courseMarks 学分, a.courseName 课程 from courseInfo a, courseInfo b where a.courseMarks=b.courseMarks and a.courseName!=b.courseName +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID 学号,stuName 姓名,coureID 课程号,score 分数 from scoreInfo inner join stuInfo on scoreInfo.stuID=stuInfo.stuID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuID 学号,courseID 课程号,courseName 课程名, courseMarks 课程学分, score 分数 from courseInfo inner join scoreInfo on courseInfo.courseID=scoreInfo.coureID +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuID 学号,stuInfo.stuName 姓名 from scoreInfo A right join stuInfo on stuInfo.stuID=A.stuID where A.score is null +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +SELECT *FROM stuInfo where stuName like '%a%' + + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生 的学号 和考试平均分 以及选修课程的数量 +select count(stuID) 课程数量,avg(score) 平均分,stuID 学号 from scoreInfo group by stuID having avg(score)>70 and count(stuID)>2 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery2.sql" new file mode 100644 index 0000000..20f5cd8 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery2.sql" @@ -0,0 +1,82 @@ +use master +go +create database cybercaf +go +use cybercaf +go +create table tbl_card +( + cardid varchar(10) primary key , + passWord varchar(10), + balance money , + userName varchar(10) +) +insert into tbl_card values('0023_ABC','555','98','张军'), +('0025_bbb','abe','300','朱骏'), +('0036_CCD','何柳','100','何柳'), +('0045_YGR','0045_YGR','58','验证'), +('0078_RJV','5585fg','600','校庆'), +('0089_EDE','zhang','134','张俊') +create table tbl_computer +( + computerid varchar(10) primary key , + onUse int check(onUse=0 or onUse=1), + note int +) +insert into tbl_computer values('02',0,25555), +('03',1,55555), +('04',0,66666), +('05',1,88888), +('06',0,688878), +('B01',0,558558) +create table tbl_record +( + recordid int primary key , + cardId varchar(10) references tbl_card(cardid ), + ComputerId varchar(10) references tbl_computer(computerid), + beginTime datetime , + endTime datetime, + fee money +) +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +(34,'0025_bbb','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), +(65,'0025_bbb','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +(98,'0025_bbb','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +--请完成以下题目: + +select * from tbl_card +select * from tbl_computer +select * from tbl_record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select userName 有户名,tbl_card.cardid 卡号,computerid 机器编号, beginTime 开始时间, endtime 结束时间,fee 消费金额 from tbl_card left join tbl_record on tbl_card.cardid=tbl_record.cardid where userName='张军' order by fee DESC +--2. 查询出每台机器上的上网次数和消费的总金额 +select count(*) 机器次数,tbl_computer.computerid 机器, sum(fee)总金额 from tbl_computer left join tbl_record on tbl_computer.computerid=tbl_record.computerid group by tbl_computer.computerid +--3. 查询出所有已经使用过的上网卡的消费总金额 +select tbl_card.cardid 卡, sum(fee) 消费总金额 from tbl_card left join tbl_record on tbl_card.cardid=tbl_record.cardid group by tbl_card.cardid having sum(fee) is not null +--4. 查询出从未消费过的上网卡的卡号和用户名 +select tbl_card.cardid 卡号, userName 用户名, sum(fee) 消费总金额 from tbl_card left join tbl_record on tbl_card.cardid=tbl_record.cardid group by tbl_card.cardid,userName having sum(fee) is null +--5. 将密码与用户名一样的上网卡信息查询出来 +select cardid 卡号,passWord 密码,userName 用户名,balance from tbl_card where passWord=userName +--6. 查询出使用次数最多的机器号和使用次数 +select computerid 机器号,count(computerid) 次数 from tbl_record group by computerid having computerid='03' +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_record.cardId 卡号,userName 用户名, ComputerId 机器号,fee 消费金额 from tbl_record left join tbl_card on +tbl_record.cardId=tbl_card.cardId group by tbl_record.cardId ,userName,ComputerId,fee having tbl_record.cardId like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_record.cardId 卡号,userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from + tbl_record left join tbl_card on tbl_record.cardId=tbl_card.cardid where (endTime-beginTime)>'12:00:00' +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 7 tbl_record.cardId 卡号,userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +left join tbl_card on tbl_record.cardId=tbl_card.cardid order by fee asc + + + -- Gitee From aeef8e7564d103fd16e6f371cabcf4dcea17a0cc Mon Sep 17 00:00:00 2001 From: lazy-scholar-cat <2220771866@qq.com> Date: Tue, 30 Mar 2021 16:59:30 +0800 Subject: [PATCH 070/195] cat --- .../SQLQuery3.29.1.sql" | 117 ++++++++++++++++ .../SQLQuery3.29.sql" | 130 ++++++++++++++++++ 2 files changed, 247 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.1.sql" new file mode 100644 index 0000000..3dd191a --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.1.sql" @@ -0,0 +1,117 @@ +create database System +on +( + fileName='F:\homework\System.mdf', + name='System', + size=5MB, + Maxsize=5MB, + filegrowth=5MB +) +log on +( + fileName='F:\homework\System_log.ldf', + name='System_log', + size=5MB, + Maxsize=5MB, + filegrowth=5MB +) +go +use System + +go + +create table tbl_card +( + id nvarchar(10) primary key, + passWord nvarchar(15), + balance money , + userName nvarchar(10) +) + +create table tbl_computer +( + id nvarchar(10) primary key, + onUse int check(onUse in (1,0)), + note text +) + +create table tbl_record +( + id nvarchar(10) primary key, + cardId nvarchar(10) foreign key references tbl_card(id), + ComputerId nvarchar(10) foreign key references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee money +) + + +insert into tbl_card values +('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'), +('0036_CCD','',100,'何柳'), +('0045_YGR','0045_YGR',58,'验证'), +('0078_RJV','55885tg',600,'校庆'), +('0089_EDE','zhang',134,'张峻') + + + +insert into tbl_computer values +('02',0,'25555'), +('03',1,'55555'), +('04',0,'66666'), +('05',1,'88888'), +('06',0,'688878'), +('B01',0,'558558') + +insert into tbl_record values +(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','300'), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + + +--tbl_record,tbl_computer ,tbl_card +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select C.id 显示卡号,userName 用户名,P.id 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record R +inner join tbl_card C on C.id=cardId +inner join tbl_computer P on P.id=R.ComputerId where userName='张军' order by fee DESC +--2. 查询出每台机器上的上网次数和消费的总金额 +select C.id 机器,count(ComputerId) 上网次数,sum(fee) 消费的总金额 from tbl_record R +inner join tbl_computer C on C.id=R.ComputerId group by C.id + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId 上网卡,sum(fee) 消费总金额 from tbl_record group by cardId + + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id,userName from tbl_card where id not in(select distinct cardId from tbl_record) + + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card where id=password +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 C.id,count(ComputerId) from tbl_record R inner join tbl_computer C on C.id=ComputerId group by C.id order by count(ComputerId) DESC +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select userName,P.id,fee from tbl_record R inner join tbl_computer P on ComputerId=P.id inner join tbl_card C on C.id=cardId where cardId like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,P.id,beginTime,endTime,fee from tbl_record inner join tbl_computer P on ComputerId=P.id inner join tbl_card C on C.id=cardId where datepart(weekday,beginTime)=1 or datepart(weekday,beginTime)=7 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,P.id,beginTime,endTime,fee from tbl_record inner join tbl_computer P on ComputerId=P.id inner join tbl_card C on C.id=cardId where datediff(hour,beginTime,endTime)>12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,P.id,beginTime,endTime,fee from tbl_record inner join tbl_computer P on ComputerId=P.id inner join tbl_card C on C.id=cardId where fee not in(select top 3 fee from tbl_record order by fee DESC) + + + + + + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.sql" new file mode 100644 index 0000000..1c6f6a1 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.sql" @@ -0,0 +1,130 @@ +create database School +on +( + fileName='F:\homework\School.mdf', + Name='School', + size=5MB, + MAXsize=5MB, + filegrowth=5MB +) +log on +( + fileName='F:\homework\School_log.ldf', + Name='School_log', + size=5MB, + MAXsize=5MB, + filegrowth=5MB +) + +go + +use School + +go + + +create table stuInfo +( + StuID int primary key identity, + StuName nvarchar(10) not null, + StuAge int not null, + StuSex int , + time date +) + +create table courseInfo +( + courseID int identity, + courseName nvarchar(10), + courseMarks int +) + +create table scoreInfo +( + scoreID int identity, + StuID int , + courseID int , + 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 values +('JavaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) + + +insert into scoreInfo 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) + + +--stuInfo courseInfo scoreInfo + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select StuName 学生,count(S.StuID) 课程的数量,AVG(score) 考试的平均分 from scoreInfo S inner join stuInfo SI on S.StuID=SI.StuID +inner join courseInfo C on S.courseID=C.courseID group by StuName +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName,count(StuName) 学生的个数,sum(score) 考试的总分 from scoreInfo S inner join stuInfo SI on S.StuID=SI.StuID +inner join courseInfo C on S.courseID=C.courseID group by courseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select * from stuInfo where StuAge + in (select StuAge 年龄 from stuInfo group by StuSex,StuAge having count(StuAge)>1) + +--4.查询出学分一样的课程信息 +select * from courseInfo where courseMarks in (select courseMarks from courseInfo group by courseMarks having count(courseMarks)>1) + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select StuName 姓名,SI.StuID 学号,courseID 课程号,score 分数 from scoreInfo S inner join stuInfo SI on S.StuID=SI.StuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select StuName 姓名,SI.StuID 学号,C.courseID 课程号,courseName 课程名,courseMarks 课程学分,score 分数 from scoreInfo S inner join stuInfo SI on S.StuID=SI.StuID inner join courseInfo C on C.courseID= S.courseID + + +--7.查询出没有参加考试的学生的学号和姓名 +select S.StuID,StuName from stuInfo S left join scoreInfo SI on S.StuID=SI.StuID where score is null + +--8.查询出是周六周天来报到的学生 +select * from stuInfo where datepart(weekday,time)=1 or datepart(weekday,time)=7 + + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where StuName like '%a%' + + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select StuID 学生的学号,AVG(score) 考试平均分,count(courseID) 选修课程的数量 from scoreInfo group by StuID having count(courseID)>2 and AVG(score)>70 + + + + + + + + + + + + + + + + -- Gitee From b2cc4e800c24fa20f488fd706600b0e2e6397f10 Mon Sep 17 00:00:00 2001 From: putar Date: Tue, 30 Mar 2021 17:12:20 +0800 Subject: [PATCH 071/195] 2021-3-30 17:12 --- .../SQLQuery1.sql" | 2 +- .../SQLQuery2.sql" | 42 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" index 54c5341..23e1091 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" @@ -73,7 +73,7 @@ select distinct SI.stuID,SI.stuName from stuInfo SI inner join scoreInfo SC on SI.stuID = SC.stuID inner join courseInfo CI on SC.courseID = CI.courseID --8.查询出是周六周天来报到的学生 -select * from stuInfo where DATEPART(dw,[time]) in(0,1) +select * from stuInfo where DATEPART(dw,[time]) in(1,7) --9.查询出姓名中有字母a的学生的信息 select * from stuInfo where stuName like '%a%' --10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" index 66385d8..b0d36a8 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" @@ -18,7 +18,7 @@ go create table tbl_computer ( - id int primary key, + id char(3) primary key, onUse int check(onUse in(0,1)), note text ) @@ -28,7 +28,7 @@ create table tbl_record ( id int primary key, cardID char(8) references tbl_card(id), - ComputerID int references tbl_computer(ID), + ComputerID char(3) references tbl_computer(id), beginTime datetime, endTime datetime, fee money @@ -39,3 +39,41 @@ insert into tbl_card values('0023_ABC','555',98,' ('0025_bbd','abe',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), ('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885fg',600,'校庆'), ('0089_EDE','zhang',134,'张峻') +go + +insert into tbl_computer values ('02',0,'25555'), +('03',1,'55555'),('04',0,'66666'),('05',1,'88888'), +('06',0,'688878'),('B01',0,'558558') +go + +insert into tbl_record values (23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',300), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) +go + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select TC.id 卡号,userName 用户名,ComputerID 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record TR inner join tbl_card TC on TR.cardID = TC.id where cardID = (select id from tbl_card where userName = '张军') order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerID,COUNT(ComputerID) 上网次数,SUM(fee)消费总金额 from tbl_record group by ComputerID +--3. 查询出所有已经使用过的上网卡的消费总金额 +select TC.id,SUM(fee)消费总金额 from tbl_card TC inner join tbl_record TR on TC.id = TR.cardID where TC.id = TR.cardID group by TC.id +--4. 查询出从未消费过的上网卡的卡号和用户名 + +--5. 将密码与用户名一样的上网卡信息查询出来 + +--6. 查询出使用次数最多的机器号和使用次数 + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 \ No newline at end of file -- Gitee From 6ee9a8caa51a4d89120add31c639450f5878bccb Mon Sep 17 00:00:00 2001 From: putar Date: Tue, 30 Mar 2021 17:44:01 +0800 Subject: [PATCH 072/195] 2021-3-30 17:45 --- .../SQLQuery2.sql" | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" index b0d36a8..c9d1019 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery2.sql" @@ -65,15 +65,17 @@ select ComputerID,COUNT(ComputerID) --3. 查询出所有已经使用过的上网卡的消费总金额 select TC.id,SUM(fee)消费总金额 from tbl_card TC inner join tbl_record TR on TC.id = TR.cardID where TC.id = TR.cardID group by TC.id --4. 查询出从未消费过的上网卡的卡号和用户名 - +select TC.id,userName from tbl_card TC left join tbl_record TR on TC.id = TR.cardID where TC.id not in(select cardID from tbl_record) --5. 将密码与用户名一样的上网卡信息查询出来 - +select * from tbl_card where userName = password --6. 查询出使用次数最多的机器号和使用次数 - +select Top 1 ComputerID,COUNT(ComputerID)使用次数 from tbl_record group by ComputerID order by COUNT(ComputerID) desc --7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 - +select TC.id,userName,ComputerID,fee from tbl_card TC inner join tbl_record TR on TC.id = TR.cardID where TC.id like '%ABC' --8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - +select cardID,userName,ComputerID,beginTime,endTime,fee from tbl_record TR inner join tbl_card TC on TR.cardID = TC.id where DATEPART(dw,beginTime) in(1,7) --9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - ---10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 \ No newline at end of file +select cardID,userName,ComputerID,beginTime,endTime,fee from tbl_record TR inner join tbl_card TC on TR.cardID = TC.id where DATEDIFF(hh,beginTime,endTime) > 12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardID,userName,ComputerID,beginTime,endTime,fee from tbl_record TR inner join tbl_card TC on TR.cardID = TC.id +where fee not in(select top 3 fee from tbl_record order by fee desc) \ No newline at end of file -- Gitee From 7dfad0804ff0053fb003bd5af0f7bc1257cdf8f1 Mon Sep 17 00:00:00 2001 From: wang-jiawen-rjjs <2903977615@qq.com> Date: Tue, 30 Mar 2021 17:53:46 +0800 Subject: [PATCH 073/195] =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 90 +++++++++++++++++++ .../\344\275\234\344\270\2321.sql" | 84 +++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\344\275\234\344\270\2321.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/SQLQuery1.sql" new file mode 100644 index 0000000..d8fa2a3 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/SQLQuery1.sql" @@ -0,0 +1,90 @@ +use master +go +create database Demo_03 +on( + name='Demo_03', + filename='C:\TEXT\Demo_03.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +log on( + name='Demo_03_log', + filename='C:\TEXT\Demo_03_log.ldf', + size=5, + maxsize=100, + filegrowth=10% +) +go +use Demo_03 +go +create table tbl_card +( + ID varchar(20) primary key , + passWord nvarchar(10), + banlance int, + userName nvarchar(10), +) +create table tbl_computer +( + Id varchar(5) primary key , + onUse int , + note text, +) +create table tbl_record +( + ID int primary key , + cardId varchar(20) references tbl_card(ID), + ComputerId varchar(5) references tbl_computer(Id), + beginTime datetime, + endTime datetime, + fee int, +) + +select * from tbl_computer +select * from tbl_card +select * from tbl_record +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abe',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张峻') +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'), +('06',0,'688878'),('B01',0,'558558') +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select tbl_card.ID 卡号,tbl_card.userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID where tbl_card.userName='张军' order by fee DESC +--2. 查询出每台机器上的上网次数和消费的总金额 +select tbl_computer.Id,count(*)上网的次数,sum(fee)总金额 from tbl_record +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id group by tbl_computer.Id +--3. 查询出所有已经使用过的上网卡的消费总金额 +select tbl_record.cardId,sum(fee)总金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID group by tbl_record.cardId +--4. 查询出从未消费过的上网卡的卡号和用户名 +select ID 卡号,userName 用户名 from tbl_card where ID not in(select distinct cardId from tbl_record) +--5. 将密码与用户名一样的上网卡信息查询出来 +select A.* from tbl_card A ,tbl_card B where A.userName=B.passWord +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 tbl_record.ComputerId,count(*) 使用次数 from tbl_record +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id group by tbl_record.ComputerId order by count(*) DESC +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_card.ID 卡号,tbl_card.userName 用户名,tbl_computer.Id 上网的机器号,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id where tbl_card.ID like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.ID 上网的卡号,tbl_card.userName 用户名,tbl_computer.Id 机器号,beginTime 开始时间,endTime 结束时间,DATEDIFF(hh,beginTime,endTime) 相差的时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id where DATEDIFF(hh,beginTime,endTime)>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 30 percent tbl_card.ID 上网的卡号,tbl_card.userName 用户名,tbl_computer.Id 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id order by fee DESC diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\344\275\234\344\270\2321.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..e3a339e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/\344\275\234\344\270\2321.sql" @@ -0,0 +1,84 @@ +use master +go +create database Demo_02 +on( + name='Demo_02', + filename='C:\text\Demo_02.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +log on( + name='Demo_02_log', + filename='C:\text\Demo_02_log.;df', + size=5, + maxsize=100, + filegrowth=10% +) +go +use Demo_02 +go +create table stuInfo +( + stuID int primary key identity(1,1) not null, + stuName nvarchar(10) not null, + stuAge int not null , + stuSex int not null , + time datetime, +) +create table courseInfo +( + courseID int primary key identity(1,1) not null, + coueseName nvarchar(20) not null, + courseMarks int not null, +) +create table scoreInfo +( + scoreID int primary key identity(1,1) not null, + stuID int references stuInfo(stuID) not null, + courseID int references courseInfo(courseID) not null, + score int not null, +) +select * from stuInfo +select * from courseInfo +select * from scoreInfo +insert into stuInfo(stuName,stuAge,stuSex) values('Tom',19,1),('Jack',20,0),('Rose',21,1), +('Lulu',19,1),('lii',21,0) +insert into stuInfo values('abc',20,1,'2007-01-07 01:11:36.590') +insert into courseInfo values('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) +insert into scoreInfo 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,stuInfo.stuName 姓名,count(*) 所选修的课程,avg(score)考试平均分 from scoreInfo +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID +inner join stuInfo on stuInfo.stuID=scoreInfo.stuID group by stuInfo.stuName , stuInfo.stuID +--2.查询出 每门课程 的选修的学生的个数 和 学生考试的总分 +select scoreInfo.courseID,count(*) 课程选修的人数,sum(score)总分 from scoreInfo +left join stuInfo on stuInfo.stuID=scoreInfo.scoreID +inner join courseInfo on courseInfo.courseID=scoreInfo.courseID group by scoreInfo.courseID +--3.查询出 性别一样 并且 年龄一样 的学生的信息 +select A.* from stuInfo A,stuInfo B where A.stuSex=B.stuSex and A.stuAge=B.stuAge and A.stuID != B.stuID +--4.查询出学分一样的课程信息 +select distinct B.* from courseInfo A, courseInfo B where A.courseMarks= B.courseMarks and A.coueseName != B.coueseName +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuInfo.stuID 学号,stuInfo.stuName 姓名,courseInfo.courseID 课程号,score 分数 from scoreInfo +inner join stuInfo on stuInfo.stuID=scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID= courseInfo.courseID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuInfo.stuID 学号,stuInfo.stuName 姓名,courseInfo.courseID 课程号,courseInfo.coueseName 课程名称,courseInfo.courseMarks 课程学分,score 分数 from scoreInfo +inner join stuInfo on stuInfo.stuID=scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID= courseInfo.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuID 学号,stuInfo.stuName 姓名 from scoreInfo +right join stuInfo on scoreInfo.stuID=stuInfo.stuID +except +select stuInfo.stuID 学号,stuInfo.stuName 姓名 from scoreInfo +right join stuInfo on scoreInfo.stuID=stuInfo.stuID where score is not null +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出 选修了2门课程以上 的并且 考试平均分在70以上的学生的学号 和 考试平均分 以及 选修课程的数量 +select stuInfo.stuID,stuInfo.stuName 姓名,count(*) 所选修的课程,avg(score)考试平均分 from scoreInfo +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID +inner join stuInfo on stuInfo.stuID=scoreInfo.stuID group by stuInfo.stuName , stuInfo.stuID having count(*)>2 and avg(score)>70 \ No newline at end of file -- Gitee From d631f897c1285f85875a64e3ff7b2794a105f61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=BF=E6=A3=AE?= <2287431003@qq.com> Date: Tue, 30 Mar 2021 18:27:24 +0800 Subject: [PATCH 074/195] sql --- .../\346\273\225\351\221\253/SQLQuery1.sql" | 65 ++++++++++++++++++ .../\346\273\225\351\221\253/SQLQuery2.sql" | 66 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" new file mode 100644 index 0000000..e94a03f --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" @@ -0,0 +1,65 @@ +create database tx +on +( + name ='tx', + size=10, + filename='D:\tx.mdf', + maxsize=100, + filegrowth=10 +) +log on +( + name ='tx_log', + size=10, + filename='D:\tx_log.ldf', + maxsize=100, + filegrowth=10 +) +go +use tx +go +create table stuInfo +( + stuID int primary key identity, + stuName nvarchar(8), + stuAge int, + stuSex nchar(2), + time datetime +) +create table courseInfo +( + courseID int primary key identity, + courseName nvarchar(12), + courseMarks int +) +create table scoreInfo +( + scoreID int primary key identity, + stuID int, + courseID int, + score int +) +insert into stuInfo(stuName,stuAge,stuSex,time) values ('Tom',19,'男',''),('Jack',20,'女',''),('Rose',21,'男',''), +('Lulu',19,'男',''),('Lili',21,'女',''),('abc',20,'男','2007-01-07 01:11:36.590') +insert into courseInfo values('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) +insert into scoreInfo 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) +select stuName,count(a.courseID) 选课数量,avg(score) 所选课考试的平均分 from stuInfo t inner join courseInfo x on t.stuID=x.courseID left join scoreInfo a on t.stuID=a.stuID group by stuName + +select courseName,count(StuName) 学生的个数,sum(score) 考试的总分 from scoreInfo t inner join stuInfo x on t.StuID=x.StuID inner join courseInfo a on t.courseID=a.courseID group by courseName + +select t.* from stuInfo t,stuInfo x where t.stuSex=x.stuSex and t.stuAge=x.stuAge and t.stuID!=x.stuID + +select distinct t.* from courseInfo t,courseInfo x where t.courseMarks=x.courseMarks and t.courseID!=x.courseID + +select t.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo t left join stuInfo x on t.stuID=x.stuID group by t.stuID,stuName,courseID,score + +select t.stuID 学号, t.courseID 课程号,x.courseName 课程名,courseMarks 学分,t.score 分数 from scoreInfo t left join courseInfo x on t.courseID=x.courseID + +select t.stuID 学号,t.stuName 姓名 from stuInfo t left join scoreInfo x on t.stuID=x.stuID where score is null + +select * from stuInfo where datepart(weekday,time)=6 or datepart(weekday,time)=7 + +select * from stuInfo where stuName like '%a%' + +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID having avg(score)>=70 and count(courseID)>=2 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" new file mode 100644 index 0000000..5482d0d --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" @@ -0,0 +1,66 @@ +create database txa +on +( + name ='txa', + size=10, + filename='D:\txa.mdf', + maxsize=100, + filegrowth=10 +) +log on +( + name ='txa_log', + size=10, + filename='D:\txa_log.ldf', + maxsize=100, + filegrowth=10 +) +go +use txa +go +create table tbl_card +( + id nvarchar(10) primary key, + passWord nvarchar(18), + balance int, + userName nvarchar(20) +) +create table tbl_computer +( + id nvarchar(10) primary key, + onUse int, + note nvarchar(200) +) +create table tbl_record +( + id nvarchar(10) primary key, + cardid nvarchar(10) foreign key references tbl_card(id), + Computerid nvarchar(10) foreign key references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee int +) +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885lg',600,'校庆'),('0089_EDE','zhang',134,'张峻') +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'),('06',0,'688878'),('B01',0,'558558') +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20),(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23),(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50),(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6),(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6),(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50),(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',30),(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23),(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) +select cardid,userName,Computerid,beginTime,endTime,fee from tbl_card t inner join tbl_record x on t.id=cardid where userName='张军' order by fee desc + +select x.id,count(ComputerId) 上网次数,sum(fee) 消费的总金额 from tbl_record t inner join tbl_computer x on t.ComputerId=x.id group by x.id + +select cardId 上网卡,sum(fee) 消费总金额 from tbl_record group by cardId + +select id,userName from tbl_card where id not in(select distinct cardId from tbl_record) + +select * from tbl_card where id=password + +select top 1 x.id,count(ComputerId) from tbl_record t inner join tbl_computer x on t.Computerid=x.id group by x.id order by count(ComputerId) DESC + +select userName,x.id,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where cardId like '%ABC' + +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on t.ComputerId=x.id inner join tbl_card a on a.id=t.cardId where datepart(weekday,beginTime)=6 or datepart(weekday,beginTime)=7 + +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where datediff(hour,beginTime,endTime)>12 + +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where fee not in(select top 3 fee from tbl_record order by fee DESC) -- Gitee From cda70259290f45d041d4985e71c1f72f11737e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=86=E7=93=9Ca?= <1991416367@qq.com> Date: Tue, 30 Mar 2021 18:27:53 +0800 Subject: [PATCH 075/195] zy --- .../SQLQuery1.sql" | 81 +++++++++++++++++++ .../SQLQuery2.sql" | 78 ++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" new file mode 100644 index 0000000..4a7e650 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" @@ -0,0 +1,81 @@ +use master +go +create database py2 +go +use py2 +go +create table card +( + id varchar(30) primary key, + pasword varchar(30), + balance money, + userName varchar(50) +) +create table computer +( + id varchar(30) primary key, + onUse varchar(2) check(onUse=0 or onUse=1), + note ntext +) +create table record +( + id varchar(30) primary key, + cardId varchar(30) foreign key references card(id), + ComputerId varchar(30) foreign key references computer(id), + beginTime datetime, + endTime datetime, + fee money +) + --上网卡信息表 +insert into card(ID,pasword,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' +--网吧机器说明表 +insert into computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' +--上网记录表 +insert into record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from card +select * from computer +select * from record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select b.id 卡号,b.userName 用户名,c.id 机器编号, a.beginTime 开始时间,a.endTime 结束时间,a.fee 消费金额 from record a inner join card b on a.cardId=b.id +inner join computer c on c.id=a.ComputerId where b.userName='张军' order by a.fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select b.id 机器,count(*)上网次数,sum(c.fee)消费的总金额 from computer b left join record c on b.id=c.ComputerId group by b.id,c.fee order by c.fee desc +--3. 查询出所有已经使用过的上网卡的消费总金额 +select b.id, sum(b.fee)消费总金额 from card a inner join record b on a.id=b.cardId group by b.id +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id,userName from card where id in (select id from record group by id ) +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from card where userName = pasword +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 max(ComputerId) 机器号,count(*)次数 from record group by ComputerId order by count(*) desc +----7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.fee 消费金额 from card a inner join record b on a.id=b.cardId where a.id like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.beginTime 开始时间,b.endTime 结束时间 ,b.fee 消费金额 from card a inner join record b on a.id=b.cardId where b.beginTime =CONVERT(datetime,b.beginTime) group by b.beginTime,a.id,a.userName,b.ComputerId,b.beginTime,b.endTime,b.fee +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.beginTime 开始时间,b.endTime 结束时间,b.fee 消费金额 from card a inner join record b on a.id=b.cardId where b.beginTime-b.endTime>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.beginTime 开始时间,b.endTime 结束时间,b.fee 消费金额 from card a inner join record b on a.id=b.cardId order by b.fee desc \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery2.sql" new file mode 100644 index 0000000..1e5ce9e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery2.sql" @@ -0,0 +1,78 @@ +use master +go +create database py +go +use py +go +create table stuInfo +( +stuid int primary key identity(1,1), +stuname nvarchar(20) not null, +stuage int, +stusex int , +time datetime +) +create table courseInfo +( +courseid int primary key identity(1,1), +coursename nvarchar(20) not null, +coursemarkes int +) +create table scoreInfo +( +scoreid int primary key identity(1,1), +stuid int references stuInfo(stuid), +courseid int not null, +score int not null +) + +insert into stuInfo +select 'tom','19','1', NULL union +select 'jack','20','0', NULL union +select 'rose','21','1', NULL union +select 'lulu','19','1', NULL union +select 'lili','21','0', NULL union +select 'abc','20','1','2007-01-07 01:11:36.590' +INSERT INTO courseInfo +select 'javabase','4' union +select 'html','2' union +select 'javascript','2' union +select 'sqlbase','2' +insert into scoreInfo +select '1','1','80'union +select '1','2','85'union +select '1','4','50'union +select '2','1','75'union +select '2','3','45'union +select '2','4','75'union +select '3','1','45'union +select '4','1','95'union +select '4','2','75'union +select '4','3','90'union +select '4','4','45' +select * from stuInfo +select * from courseInfo +select * from scoreInfo +--1.查询出每个学生所选修的课程的数量 和 所选修的课程的考试的平均分 +select stuid,count(*)数量,avg(score) from scoreInfo group by stuid +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select c.courseid,count(*)数量,sum(s.score)总分 from courseInfo c inner join scoreInfo s on c.courseid=s.courseid group by c.courseid +--3.查询出性别一样并且年龄一样的学生的信息 +select a.* from stuInfo a, stuInfo b where a.stuage= b.stuage and a.stusex=b.stusex and a.stuid !=b.stuid +--4.查询出学分一样的课程信息 +select a.* from courseInfo a, courseInfo b where a.coursemarkes=b.coursemarkes and a.coursename!=b.coursename +union +select a.* from courseInfo a, courseInfo b where a.coursemarkes=b.coursemarkes and a.coursename!=b.coursename +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select b.stuid,a.stuname,b.courseid,b.score from stuInfo a inner join scoreInfo b on a.stuid=b.stuid +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select s.stuid,c.courseid,c.coursename,c.coursemarkes,s.score from courseInfo c inner join scoreInfo s on c.courseid=s.courseid +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuid,stuInfo.stuname from stuInfo left join scoreInfo on stuInfo.stuid= scoreInfo .stuid where score is null +select stuid,stuname from stuInfo where stuid not in (select stuid from scoreInfo group by stuid,courseid ) +--8.查询出是周六周天来报到的学生 +select stuname,time from stuInfo where time =CONVERT(datetime,time) group by time,stuname +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuname like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuid 学号 ,count(*) 数量 ,avg(score) 平均分 from scoreInfo group by stuid having count(*)>=2 and avg(score)>=70 -- Gitee From 5ea260236c12987a773fc6fd0fbce5710c4df589 Mon Sep 17 00:00:00 2001 From: li-qingcai <2811189126@qq.com> Date: Tue, 30 Mar 2021 22:08:59 +0800 Subject: [PATCH 076/195] 3.30 --- .../SQLQuery1.sql" | 72 +++++++++++ .../SQLQuery2.sql" | 121 ++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery1.sql" new file mode 100644 index 0000000..3ff73f4 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery1.sql" @@ -0,0 +1,72 @@ +use master +go +create database stu +go +use stu +go + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +create table stuInfo +( + stuID int primary key identity, + stuName varchar(20) , + stuAge int , + dtuSex int check(dtuSex=0 or dtuSex=1), + time datetime +) +create table courseInfo +( + courseID int primary key identity, + courseName varchar(20) , + courseMarks int +) +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,dtuSex,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) +--题目: +select*from stuInfo +select*from courseInfo +select*from scoreInfo +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuInfo.stuName 名字,count(courseMarks) 选课数量,avg(score) 考试平均分 from scoreInfo,courseInfo,stuInfo +where courseInfo.courseID=scoreInfo.courseID and stuInfo.stuID=scoreInfo.stuID group by stuName +--2.查询出每门课程的选修的学生的个数 和学生考试的总分 +select courseName 课程名字,count(stuID) 人数,sum(score) 总分 from scoreInfo +inner join courseInfo on courseInfo.courseID=scoreInfo.courseID group by courseName +--3.查询出性别一样并且年龄一样的学生的信息 + +select a.stuName 姓名,b.stuAge 年龄,b.dtuSex 性别 from stuInfo a,stuInfo b +where a.stuAge=b.stuAge and a.dtuSex=b.dtuSex and a.stuID<>b.stuID +--4.查询出学分一样的课程信息 +select distinct a.courseName,a.courseMarks from courseInfo a,courseInfo b +where a.courseMarks=b.courseMarks and a.courseName<>b.courseName +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuInfo.stuID,stuName,courseID,score from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号 ,scoreInfo.courseID 课程号 ,courseName 课程名 ,courseMarks 课程学分, scoreInfo.score 分数 +from scoreInfo inner join courseInfo on courseInfo.courseID=scoreInfo.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuID 学号,stuName 姓名 ,score +from stuInfo left join scoreInfo on stuInfo.stuID=scoreInfo.stuID +where score is null +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuID 学号, count(stuID)课程数目,avg(score) 平均分 from scoreInfo group by stuID having count(stuID)>=2 and avg(score)>=70 + + + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery2.sql" new file mode 100644 index 0000000..6256c4f --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery2.sql" @@ -0,0 +1,121 @@ +use master +go +create database wb +on +( name='wb', + filename='D:\wb-mdf', + size=5, + maxsize=500, + filegrowth=1 +) + log on +( name='wb_log', + filename='D:\wb_log-ldf', + size=5, + maxsize=500, + filegrowth=1 +) +go +use wb +go +create table tbl_card +( + id varchar(8) primary key, + passWord varchar(15) not null, + balance money not null, + userName nchar(5) +) +create table tbl_computer +( + id char(5) primary key, + onUse int not null, + note text not null +) +create table tbl_record +( + id int primary key, + cardld varchar(8) references tbl_card(id), + ComputerId char(5) references tbl_computer(id), + beginTime datetime , + endTime datetime, + free money not null +) +insert into tbl_card values('0023_ABC','555',99,'张军'),('0025_bbd','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳') +,('0045_YGR','0045_YGR',58,'验证'),('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张俊') + +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'888888'),('06',0,'688878'),('B01',0,'558558') + + +insert into tbl_record values('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), + ('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), + ('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), + ('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), + ('47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), + ('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), + ('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), + ('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), + ('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), + ('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +select*from tbl_card +select*from tbl_computer +select*from tbl_record + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select cardld 卡号, userName 用户名, beginTime 开始时间, endTime 结束时间, free 消费金额 + from tbl_record + join tbl_computer + on tbl_computer.id=tbl_record.ComputerId + join tbl_card + on cardld=tbl_card.id + where userName='张军' + order by free desc + + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId, count(ComputerId) 上网次数,sum(free) 消费总金额 + from tbl_record + group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardld 网卡, sum(free) 消费总金额 from tbl_record group by cardld + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id 卡号 , userName 用户名 + from tbl_card + where id not in (select cardld from tbl_record ) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select T.id 卡号,T.passWord 密码,T.balance 卡上的余额,T.userName 用户名 + from tbl_card,tbl_card T + where tbl_card.passWord=T.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号, count(ComputerId) 使用次数 + from tbl_record + group by ComputerId + order by count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,free 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + where cardld like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, free 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + where datediff(HOUR,beginTime,endTime)>=12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + select top 7 cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, free 消费金额 + from tbl_record join tbl_card on tbl_card.id=cardld + order by free asc + + -- Gitee From 3bf469e84b03f5d53d016b8196b60ca9260934c2 Mon Sep 17 00:00:00 2001 From: zyq520lcx <2642587822@qq.com> Date: Wed, 31 Mar 2021 10:30:16 +0800 Subject: [PATCH 077/195] frsit commit --- .../\344\275\234\344\270\2321.sql" | 118 ++++++++++++++++++ .../\344\275\234\344\270\2322.sql" | 112 +++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2321.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2322.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2321.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..0d35fc7 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2321.sql" @@ -0,0 +1,118 @@ +use master +go + +create database student +go + +use student +go + +drop table stuInfo +drop table courseInfo +drop table scoreInfo + +create table stuInfo +( + stuID int primary key identity(1,1), + stuName nvarchar(20) not null, + stuAge int not null, + stuSex nchar(2) default(1) check(stuSex='1' or stuSex='0') not null, + time datetime +) + +create table courseInfo +( + courseID int primary key identity(1,1), + courseName nvarchar(20) not null, + courstMarks int +) + +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int not null +) + +insert into stuInfo +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-01 01:11:36.590') + + +insert into courseInfo +values ('JavaBase',4) , ('HTML',2) , ('JavaScript',2) , ('SqlBase',2) + +select *from stuInfo + +insert into scoreInfo +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +--1.查询出 每个学生 所选修的 课程的数量 和所 选修的课程的考试的平均分 +select * from stuInfo +select * FROM courseInfo +select * from scoreInfo + +select stuID 学生ID ,count(CO.courseID) 课程数量,avg(score)考试平均分 from scoreInfo SC +inner join courseInfo CO on SC.courseID=CO.courseID group by stuID + +--2.查询出 每门课程 的 选修的学生的个数 和 学生考试的总分 +select courseName 每门课程 , count(stuID)学生个数, sum(score)考试总分 from courseInfo +inner join scoreInfo on scoreInfo.courseID=courseInfo.courseID group by courseName + +--3.查询出 性别一样 并且 年龄一样的 学生的信息 + +select b1.* from stuInfo as b1,stuInfo as b2 +where b2.stuAge=b1.stuAge and b2.stuSex=b1.stuSex and b1.stuID!=b2.stuID + +--4.查询出学分一样的课程信息 +select * from courseInfo + +select distinct A.* from courseInfo A,courseInfo B where A.courstMarks=B.courstMarks AND A.courseID!=B.courseID + +--5.查询出参加了 考试的学生的学号 , 姓名, 课程号 和分数 +select * from courseInfo + + select stuInfo.stuID 学号,stuName 姓名,courseInfo.courseID 课程号,score 分数 from scoreInfo + inner join courseInfo on courseInfo.courseID=scoreInfo.courseID + inner join stuInfo on stuInfo.stuID=scoreInfo.stuID + + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +select stuInfo.stuID 学号,courseInfo.courseID 课程号,courseName 课程名,courstMarks 课程学分,score 分数 from scoreInfo + inner join courseInfo on courseInfo.courseID=scoreInfo.courseID + inner join stuInfo on stuInfo.stuID=scoreInfo.stuID + +--7.查询出 没有参加考试的 学生的学号 和 姓名 +select * from stuInfo +select * from scoreInfo + +select stuInfo.stuID 学号,stuName 姓名 from stuInfo +left join scoreInfo on stuInfo.stuID=scoreInfo.stuID where score is null + +--8.查询出是周六周天来报到的学生 +--不知道啊啊啊啊 +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like 'a%' +--10.查询出选修了 2门课程以上 的并且 考试平均分在70以上的 学生的学号 和 考试平均分以及 选修课程的数量 +select * from scoreInfo + +select stuInfo.stuID 学号,avg(score)考试平均分,count(scoreInfo.courseID)选修课数量 from stuInfo +inner join scoreInfo on scoreInfo.stuID=stuInfo.stuID group by stuInfo.stuID +having avg(score) >70 and count(scoreInfo.courseID)>2 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2322.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..2e62622 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/\344\275\234\344\270\2322.sql" @@ -0,0 +1,112 @@ +use master +go + +create database tbl +go + +use tbl +go + +create table tbl_card --表一为上网卡信息表 +( + id nvarchar(20) primary key, --id: 卡号,主键 + passWord nvarchar(20), --passWord:密码 + balance int not null, --balance:卡上的余额 + userName nvarchar(20) not null --userName:该上网卡所属的用户名) +) + +create table tbl_computer --表2为网吧机器说明表(tbl_computer) +( + id nvarchar(20) primary key, --id:机器编号,主键 + onUse nchar(2) check(onUse='0' or onUse='1'),--onUse:该机器是否正在使用,0为未使用,1为正在使用 + note text not null --note:该机器的说明 +) + +create table tbl_record --表3为上网记录表(tbl_record): +( + id int primary key not null, --id:记录编号,主键 + cardId nvarchar(20) references tbl_card(id),--cardId:本次上网的卡号,外键 + computerId nvarchar(20) references tbl_computer(id),--ComputerId:本次上网记录所使用的机器号,外键 + beginTime datetime, --beginTime:本次上网记录的开始时间 + endTime datetime, --endTime:本次上网记录的结束时间 + fee money --fee:本次上网的费用 +) + + +insert into tbl_card --表tbl_card的数据 +values('0023_ABC','555',98,'张军'), + ('0025_bbd','abe',300,'朱俊'), + ('0036_CCD','何柳',100,'何柳'), + ('0045_YGR','0045_YGR',58,'证验'), + ('0078_RJV','55885fg',600,'校庆'), + ('0089_EDE','zhang',134,'张峻') + +insert into tbl_computer --表tbl_computer的数据 +values('02','0','25555'), + ('03','1','55555'), + ('04','0','66666'), + ('05','1','88888'), + ('06','0','688878'), + ('B01','0','558558') + +insert into tbl_record --表tbl_record的数据 +values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), + (34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), + (45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), + (46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), + (47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), + (48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), + (55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), + (64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','300'), + (65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), + (98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') +select * from tbl_record + + + + +--首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: +--请完成以下题目: +--1. 查询出用户名为 '张军' 的上网卡的 上网记录,要求 显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select C.id 卡号,userName 用户名, O.id 机器编号 ,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_card C +inner join tbl_record R on C.id=R.cardId +inner join tbl_computer O on o.id=R.computerId +where userName like '张军' order by fee desc +--2. 查询出 每台机器上 的 上网次数 和 消费的总金额 +select * from tbl_record + +select count(computerId)上网次数,sum(fee)消费总金额 from tbl_record group by computerId + +--3. 查询出 所有已经使用过 的上 网卡的 消费总金额 +select C.id 卡号,SUM(R.fee) 消费总金额 from tbl_card C +inner join tbl_record R on C.id=R.cardId GROUP BY C.id +--4. 查询出从未消费过的上网卡的 卡号 和 用户名 ???? +select id 卡号,userName 用户名 from tbl_card where id not in(select distinct cardId from tbl_record) + +--5. 将 密码 与 用户名 一样的上网卡信息查询出来 +select distinct A.* from tbl_card A , tbl_card B WHERE A.passWord=B.userName + + +--6. 查询出使用次数最多的 机器号 和 使用次数 +select * from tbl_record +select top 1 computerId 机器号 ,count(computerId)使用次数 from tbl_record +group by computerId order by count(computerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select C.id 卡号,userName 用户名, computerId 机器号,fee 消费金额 from tbl_card C +inner join tbl_record R on C.id=R.cardId where C.id like '_____ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId 卡号,userName 用户名,computerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record +inner join tbl_card on tbl_card.id=tbl_record.cardId + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的 卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId 卡号,userName 用户名,computerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record +inner join tbl_card on tbl_card.id=tbl_record.cardId + + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的 卡号, 用户名, 机器号 ,开始时间、 结束时间 和 消费金额 +select top 3 cardId 卡号,userName 用户名,computerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record +inner join tbl_card on tbl_card.id=tbl_record.cardId order by fee desc + + + -- Gitee From 89c2814431e0b3470e3082ae3444551b2a63eb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=93=A6=E7=89=B9=E5=8F=91?= <3144531710@qq.com> Date: Wed, 31 Mar 2021 10:47:41 +0800 Subject: [PATCH 078/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\346\275\230\345\256\207/SQLQuery11.sql" | 102 ++++++++++++++++++ .../\346\275\230\345\256\207/SQLQuery12.sql" | 101 +++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery11.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery12.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery11.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery11.sql" new file mode 100644 index 0000000..2cf8c28 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery11.sql" @@ -0,0 +1,102 @@ +use master +go +create database ttbs +on +( +name='dada', +size=5, +filename='D:\dada.mdf', +maxsize=50, +filegrowth=1 +) +log on +( +name='dada_log', +size=5, +filename='D:\dada_log.ldf', +maxsize=50, +filegrowth=1 +) +go +use ttbs +go +create table student +( +stuID int primary key identity(1,1), +stuName varchar(20) not null, +stuAge int not null, +stuSex int , +time nvarchar(30) +) +go +create table course +( +courseID int primary key identity(1,1), +courseName varchar(20) not null, +courseMaks int not null +) +go +create table scoreop +( +scoreID int primary key identity(1,1), +sluID int not null , +courseID int not null, +score int not null +) +go +select * from student +select * from course +select * from scoreop +insert into student (stuName,stuAge,stuSex,time) + values('Tom',19,1,NULL), + ('Jack',20,0,NULL), + ('Rose',21,1,NULL), + ('Lulu',19,1,NULL), + ('li',21,0,NULL), + ('abc',20,1,'2007-01-07 01:11:36.590') + +insert into course (courseName,courseMaks) + values('JavaBase',4), + ('HTML',2), + ('javaScipt',2), + ('SqlBase',2) +insert into scoreop (sluID,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) +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +select * from student +select * from course +select * from scoreop +--1.查询出每个学生所选修的课程 的数量 和所选修的课程 的考试的平均分 +select sluID,count(courseID),avg(score) from scoreop group by sluID +--2.查询出 每门课程 的选修的学生的个数 和 学生考试的总分 +select courseID,count(sluID),sum(score) from scoreop group by courseID +--3.查询出性别一样并且年龄一样的学生的信息 +select * from student A,student B where A.StuAge=B.StuAge and A.StuSex=B.StuSex AND A.stuID != B.stuID +--4.查询出学分一样的课程信息 +SELECT A.* FROM course A, course B WHERE A.courseMaks=B.courseMaks AND A.courseName!=B.courseName +UNION +SELECT A.* FROM course A, course B WHERE A.courseMaks=B.courseMaks AND A.courseName!=B.courseName +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +SELECT B.sluID,A.stuName,B.courseID,B.score FROM student A INNER JOIN scoreop B ON A.stuID=B.sluID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +SELECT B.stuName,C.courseID,C.score,A.courseMaks,A.courseName FROM student B INNER JOIN scoreop C ON B.stuID= C.sluID INNER JOIN course A ON C.courseID=A.courseID +--7.查询出没有参加考试的学生的学号和姓名 +SELECT stuID,stuName FROM student WHERE stuID NOT IN (SELECT sluID FROM scoreop GROUP BY sluID,courseID) +--8.查询出是周六周天来报到的学生 +SELECT A.time,stuName FROM student A GROUP BY time,stuName +--9.查询出姓名中有字母a的学生的信息 +select * FROM student WHERE stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select COUNT(*),sluID,AVG(score) from scoreop GROUP BY sluID HAVING COUNT(*)>=2 AND AVG(score)>=70 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery12.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery12.sql" new file mode 100644 index 0000000..0c1e7ec --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery12.sql" @@ -0,0 +1,101 @@ +use master +go +create database TBSE +on +( name='TA', + filename='D:\TA.mdf', + size=5, + maxsize=500, + filegrowth=1 +) + log on +( name='TA_log', + filename='D:\TA_log.ldf', + size=5, + maxsize=500, + filegrowth=1 +) +go +use TA +go +create table tbl_card +( + id varchar(8) primary key, + passWord varchar(15) not null, + balance money not null, + userName nchar(5) +) +create table tbl_computer +( + id char(5) primary key, + onUse int not null, + note text not null +) +create table tbl_record +( + id int primary key, + cardld varchar(8) references tbl_card(id), + ComputerId char(5) references tbl_computer(id), + beginTime datetime , + endTime datetime, + fee money not null +) +insert into tbl_card values('0023_ABC','555',99,'张军'), + ('0025_bbd','abc',300,'朱俊'), + ('0036_CCD','何柳',100,'何柳'), + ('0045_YGR','0045_YGR',58,'验证'), + ('0078_RJV','55885fg',600,'校庆'), + ('0089_EDE','zhang',134,'张俊') + +insert into tbl_computer values('02',0,'25555'), + ('03',1,'55555'), + ('04',0,'66666'), + ('05',1,'888888'), + ('06',0,'688878'), + ('B01',0,'558558') + + +insert into tbl_record values('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), + ('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), + ('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), + ('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), + ('47','0023_ABC','03','2006-12-23 15:26:00','2007-12-23 22:55:00','50'), + ('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), + ('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), + ('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), + ('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), + ('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') +--请完成以下题目: +select*from tbl_card +select*from tbl_computer +select*from tbl_record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select cardld 卡号, userName 用户名, beginTime 开始时间, endTime 结束时间, fee 消费金额 from tbl_record join tbl_computer on tbl_computer.id=tbl_record.ComputerId + join tbl_card on cardld=tbl_card.id where userName='张军' order by fee +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId, count(ComputerId) 上网次数,sum(fee) 消费总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardld 网卡, sum(fee) 消费总金额 from tbl_record group by cardld +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id 卡号 , userName 用户名 from tbl_card where id not in (select cardld from tbl_record ) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select T.id 卡号,T.passWord 密码,T.balance 卡上的余额,T.userName 用户名 from tbl_card,tbl_card T where tbl_card.passWord=T.userName + +select T.* from tbl_card,tbl_card T where tbl_card.passWord=T.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号, count(ComputerId) 使用次数 from tbl_record group by ComputerId order by count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,fee 消费金额 from tbl_record join tbl_card on tbl_card.id=cardld where cardld like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record join tbl_card on tbl_card.id=cardld + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record join tbl_card on tbl_card.id=cardld where datediff(HOUR,beginTime,endTime)>=12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record join tbl_card on tbl_card.id=cardld order by fee desc \ No newline at end of file -- Gitee From c2f96b6c8288b320a18014b9e20ad9ae875b6682 Mon Sep 17 00:00:00 2001 From: linghuanye <1271919148@qq.com> Date: Wed, 31 Mar 2021 12:46:25 +0800 Subject: [PATCH 079/195] first commit --- .../\344\275\234\344\270\2321.sql" | 117 ++++++++++++++++ .../\344\275\234\344\270\2322.sql" | 125 ++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2321.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2322.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2321.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..511404b --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2321.sql" @@ -0,0 +1,117 @@ +use master +go + +create database TestDB01 +on +( + name='ordersystem', + filename='E:\数据库\TestDB01.mdf', + size=5mb, + maxsize=100mb, + filegrowth=15% +) + +log on +( + name='bank_log', + filename='E:\数据库\TestDB01_log.ldf', + size=5mb, + maxsize=100mb, + filegrowth=15% +) + +use TestDB01 +go + +create table stuInfo +( + stuID int primary key identity(1,1), + stuName nvarchar(10) not null, + stuAge nchar(3) not null, + stuSex nvarchar(2) not null, + time datetime +) + +create table courseInfo +( + courseID int primary key identity(1,1), + courseName nchar(20) not null, + courseMarks int +) + +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int foreign key references stuInfo(stuID), + courseID int foreign key references courseInfo(courseID), + score int not null +) +select * from stuInfo +insert into stuInfo(stuName,stuAge,stuSex) values +('Tom','19','1'),('Jack','20','0'), +('Rose','21','1'),('Lulu','19','1'), +('Lili','21','0'),('abc','20','1') +update stuInfo set time='2007-01-07 01:11:36.590' where stuID='6' + +select * from courseInfo +insert into courseInfo values +('JavaBase',4),('HTML',2),('JavaaScript',2),('SqlBase',2) + +select * from scoreInfo +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') + + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +select * from stuInfo +select * from courseInfo +select * from scoreInfo +--题目: +--1.查询出 每个学生 所选修的课程的数量 和 所选修的课程的 考试的平均分 +select stuInfo.stuID,stuName,COUNT(scoreInfo.courseID)数量,AVG(score)平均分 from stuInfo inner join scoreInfo on stuInfo.stuID= scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID group by stuInfo.stuID,stuName + +--2.查询出 每门课程的选修的 学生的个数 和 学生考试的总分 +select cu.courseID,courseName,COUNT(st.stuID)学生的个数,SUM(score)总分 from stuInfo st inner join scoreInfo sc on st.stuID= sc.stuID +inner join courseInfo cu on sc.courseID=cu.courseID group by cu.courseID,courseName + +--3.查询出 性别 一样并且 年龄 一样的学生的信息 +select A.* from StuInfo A ,stuInfo B where +A.stuSex=B.stuSex and A.stuAge=B.stuAge and A.stuID!=B.stuID + +--4.查询出学分一样的课程信息 +select A.courseID,A.courseName,A.courseMarks from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks and A.courseID!=B.courseID +group by A.courseID,A.courseName,A.courseMarks + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select A.stuID,stuName,C.courseID,courseName,score from stuInfo A inner join scoreInfo B +on A.stuID=B.stuID inner join courseInfo C on B.courseID=C.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select A.stuID,C.courseID,courseName,courseMarks,score from stuInfo A inner join scoreInfo B +on A.stuID=B.stuID inner join courseInfo C on B.courseID=C.courseID + + +--7.查询出没有参加考试的学生的学号和姓名 +select A.stuID,stuName from stuInfo A left join scoreInfo B +on A.stuID=B.stuID left join courseInfo C on B.courseID=C.courseID group by A.stuID,stuName +except +select A.stuID,stuName from stuInfo A inner join scoreInfo B +on A.stuID=B.stuID inner join courseInfo C on B.courseID=C.courseID group by A.stuID,stuName + +--8.查询出是周六周天来报到的学生 +select * from stuInfo where time='2007-01-07 01:11:36.590' + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like 'a%' + +--10.查询出选修了 2门课程以上 的并且 考试平均分在 70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 +select * from stuInfo +select * from courseInfo +select * from scoreInfo + +select stuInfo.stuID,stuName,AVG(score)平均分,COUNT(scoreInfo.courseID)数量 from stuInfo inner join scoreInfo on stuInfo.stuID= scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID group by stuInfo.stuID,stuName having COUNT(scoreInfo.courseID)>2 and AVG(score)>70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2322.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..9055f40 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/\344\275\234\344\270\2322.sql" @@ -0,0 +1,125 @@ +--首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: +use master +go + +create database cybercaf +on +( + name='cybercaf', + filename='E:\数据库\cybercaf.mdf', + size=5MB, + maxsize=100MB, + filegrowth=10% +) + +log on +( + name='cybercaf_log', + filename='E:\数据库\cybercaf_log.ldf', + size=5MB, + maxsize=100MB, + filegrowth=10% +) + +use cybercaf +go + +--表一为上网卡信息表(tbl_card) +--id: 卡号,主键 +--passWord:密码 +--balance:卡上的余额 +--userName:该上网卡所属的用户名 +create table tbl_card +( + id nchar(15) primary key not null, + password nchar(20) not null, + balance nchar(10) not null, + userName nvarchar(10) not null +) + +--表2为网吧机器说明表(tbl_computer) +--id:机器编号,主键 +--onUse:该机器是否正在使用,0为未使用,1为正在使用 +--Note:该机器的说明 +create table tbl_computer +( + id nchar(5) primary key not null, + onUse nchar(1) not null, + Note nchar(20) +) + +--表3为上网记录表(tbl_record): +--id:记录编号,主键 +--cardId:本次上网的卡号,外键 +--ComputerId:本次上网记录所使用的机器号,外键 +--beginTime:本次上网记录的开始时间 +--endTime:本次上网记录的结束时间 +--fee:本次上网的费用 +create table tbl_record +( + id int primary key not null, + cardId nchar(15) foreign key references tbl_card(id), + ComputerId nchar(5) foreign key references tbl_computer(id), + beginTime datetime not null, + endTime datetime not null, + fee int not null +) + +select * from tbl_card +insert into tbl_card values +('0023_ABC','555','98','张军'),('0025_bbd','abe','300','朱俊'), +('0036_CCD','何柳','100','何柳'),('0045_YGR','0045_YGR','58','证验'), +('0078_RJV','55885fg','600','校庆'),('0089_EDE','zhang','134','张峻') + +select * from tbl_computer +insert into tbl_computer values ('02','0','25555'),('03','1','55555'), +('04','0','66666'),('05','1','88888'),('06','0','688878'),('B01','0','558558') + +select * from tbl_record +insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values +(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(24,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select A.id,userName,ComputerId,beginTime,endTime,fee from tbl_card A inner join tbl_record on A.id=cardId where userName='张军' order by fee + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId,COUNT(ComputerId)上网次数,SUM(fee)消费的总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select onUse,sum(fee)消费总金额 from tbl_computer A inner join tbl_record B on A.id=ComputerId where onUse='1' group by onUse + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select A.id,userName from tbl_card A inner join tbl_record B on A.id=B.cardId +inner join tbl_computer C on B.ComputerId=C.id where onUse='0' + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card where password=userName + +--6. 查询出 使用次数最多的机器号和使用次数 +select ComputerId,COUNT(ComputerId)使用次数 from tbl_computer A inner join tbl_record B on A.id = B.ComputerId group by ComputerId +having COUNT(ComputerId)=5 + +--7. 查询出卡号是以'ABC'结尾的 卡号,用户名,上网的机器号和消费金额 +select A.id,userName,ComputerId,fee from tbl_card A inner join tbl_record B on A.id=B.cardId where A.id like '%ABC%' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select B.id,userName,ComputerId,beginTime,endTime,fee from tbl_record A inner join tbl_card B on A.cardId=B.id + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select B.id,userName,ComputerId,beginTime,endTime,fee from tbl_record A inner join tbl_card B on A.cardId=B.id +where endTime-beginTime>'1900-01-01 12:00:00.000' + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select B.id,userName,ComputerId,beginTime,endTime,fee from tbl_record A inner join tbl_card B on A.cardId=B.id +where fee!=50 order by fee DESC + + -- Gitee From fe8c1817ba8b32a2a74f6b2a692e0b6a3f61e84a Mon Sep 17 00:00:00 2001 From: PilRio <2535341085@qq.com> Date: Wed, 31 Mar 2021 18:47:55 +0800 Subject: [PATCH 080/195] sql --- .../SQLQuery1.sql" | 96 +++++++++++++++ .../SQLQuery2.sql" | 110 ++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" new file mode 100644 index 0000000..41eb48f --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" @@ -0,0 +1,96 @@ +use master +create database excise +on +( + name = 'excise', + filename = 'D:\数据库\excise.mdf' +) +log on +( + name = 'excise_log', + filename = 'D:\数据库\excise_log.ldf' +) + +use excise + +create table stuInfo +( + stuID int identity primary key, + stuName varchar(10)not null, + stuAge int , + stuSex nvarchar(1) check(stuSex in('男','女')), + time datetime +) +insert into stuInfo values +('Tom',19,'男',null), +('Jack',20,'女',null), +('Rose',21,'男',null), +('Lulu',19,'男',null), +('Lili',21,'女',null), +('abc',20,'男','2007-01-07 01:11:36.590') +select * from stuInfo + +create table courseInfo +( + courseID int identity primary key, + courseName varchar(20) not null, + courseMarks int +) +insert into courseInfo values +('JavaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) +select * from courseInfo + +create table scoreInfo +( + scoreID int identity, + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int +) + +insert into scoreInfo 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) +select * from scoreInfo +select * from courseInfo +select * from stuInfo + +--.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuInfo.stuName 姓名,count(courseName)选修课程数量,avg(score)平均分 from stuInfo,courseInfo,scoreInfo where +stuInfo.stuID = courseInfo.courseID and +courseInfo.courseID =scoreInfo.stuID group by stuInfo.stuName,courseName + +--2.查询出 每门课程 的选修的 学生的个数和学生考试的总分 +select courseID 课程,COUNT(distinct stuID)学生个数,SUM(score)总分 from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 +select a.* from stuInfo a,stuInfo b where a.stuAge=b.stuAge and a.stuSex = b.stuSex and a.stuID != b.stuID + +--4.查询出学分一样的课程信息 +select a.courseName,a.courseMarks from courseInfo a, courseInfo b +where a.courseMarks = b.courseMarks and a.courseID != B.courseID +group by a.courseName,a.courseMarks + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +--7.查询出没有参加考试的学生的学号和姓名 + +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery2.sql" new file mode 100644 index 0000000..2fa093d --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery2.sql" @@ -0,0 +1,110 @@ +create database wb +on +( + name = 'wb', + filename = 'D:\数据库\wb.mdf' +) +log on +( + name = 'wb_log', + filename = 'D:\数据库\wb_log.ldf' +) + +use wb + +create table tbl_card +( + id varchar(10) primary key, + PassWord nvarchar(10) not null, + balance int not null, + userName nvarchar(2) not null +) +insert into tbl_card values +('0023_ABC','555','98','张军'), +('0025_bbb','abe','300','朱俊'), +('0036_CCD','何柳','100','何柳'), +('0045_YGR','0045_YGR','58','证验'), +('0078_RJV','55885fg','600','校庆'), +('0089_EDE','zhang','134','张峻') +select * from tbl_card + +create table tbl_computer +( + id varchar(3) primary key, + onUser int check(onUser in ('0','1')), + Note int +) +insert into tbl_computer values +('02',0,25555), +('03',1,55555), +('04',0,66666), +('05',1,88888), +('06',0,688878), +('B01',0,558558) +select * from tbl_computer + +create table tbl_record +( + id int primary key, + cardId varchar(10) references tbl_card(id), + ComputerId varchar(3) references tbl_computer(id), + beginTime datetime not null, + endTime datetime not null, + free int not null +) +insert into tbl_record values +(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +(34,'0025_bbb','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), +(65,'0025_bbb','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +(98,'0025_bbb','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +--1. 查询出用户名为'张军'的上网卡的上网记录, +--要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select a.id 卡号,userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间, free 金额 from tbl_card a +left join tbl_record b on b.cardId = a.id +left join tbl_computer c on c.id = b.cardId +where userName = '张军' order by free desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器编号,count(id) 次数,sum(free) 总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select a.id 卡号,sum(free) 金额 from tbl_card a right join tbl_record b on a.id = b.cardId group by a.id + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select a.id 卡号,a.userName 用户名, b.free from tbl_card a +left join tbl_record b on a.id = b.cardId +where free is null +group by a.id,a.userName,b.free + +--5. 将密码与用户名一样的上网卡信息查询出来 +select a.* from tbl_card a +inner join tbl_card b on a.PassWord = b.PassWord and a.userName != b.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId) 次数 from tbl_record group by ComputerId order by count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select b.userName 用户名,a.ComputerId 机器号,count(cardId) 次数,sum(free) 金额 from tbl_record a +left join tbl_card b on a.cardId = b.id +where a.cardId like '%ABC' +group by b.userName,a.ComputerId + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select * from tbl_card +select * from tbl_computer +select * from tbl_record +select top 7 a.id 卡号, a.userName 用户名, b.ComputerId 机器号,b.beginTime 开始时间,b.endTime 结束时间, max(b.free) 金额 from tbl_card a +left join tbl_record b on a.id = b.cardId +left join tbl_computer c on c.id = b.cardId +group by a.id, b.ComputerId,b.beginTime,b.endTime,a.userName order by max(b.free) -- Gitee From 5fc0281f3befd39e59854aaf058525d7f86ec0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=93=A6=E7=89=B9=E5=8F=91?= <3144531710@qq.com> Date: Wed, 31 Mar 2021 19:04:00 +0800 Subject: [PATCH 081/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\346\275\230\345\256\207/SQLQuery1.sql" | 102 +++++++++++++++++ .../\346\275\230\345\256\207/SQLQuery2.sql" | 104 ++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery1.sql" new file mode 100644 index 0000000..f48c38e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery1.sql" @@ -0,0 +1,102 @@ +use master +go +create database ttbs +on +( +name='dada', +size=5, +filename='D:\dada.mdf', +maxsize=50, +filegrowth=1 +) +log on +( +name='dada_log', +size=5, +filename='D:\dada_log.ldf', +maxsize=50, +filegrowth=1 +) +go +use ttbs +go +create table student +( +stuID int primary key identity(1,1), +stuName varchar(20) not null, +stuAge int not null, +stuSex int , +time nvarchar(30) +) +go +create table course +( +courseID int primary key identity(1,1), +courseName varchar(20) not null, +courseMaks int not null +) +go +create table scoreop +( +scoreID int primary key identity(1,1), +sluID int not null , +courseID int not null, +score int not null +) +go +select * from student +select * from course +select * from scoreop +insert into student (stuName,stuAge,stuSex,time) + values('Tom',19,1,NULL), + ('Jack',20,0,NULL), + ('Rose',21,1,NULL), + ('Lulu',19,1,NULL), + ('li',21,0,NULL), + ('abc',20,1,'2007-01-07 01:11:36.590') + +insert into course (courseName,courseMaks) + values('JavaBase',4), + ('HTML',2), + ('javaScipt',2), + ('SqlBase',2) +insert into scoreop (sluID,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) +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +select * from student +select * from course +select * from scoreop +--1.查询出每个学生所选修的课程 的数量 和所选修的课程 的考试的平均分 +select sluID,count(courseID),avg(score) from scoreop group by sluID +--2.查询出 每门课程 的选修的学生的个数 和 学生考试的总分 +select courseID,count(sluID),sum(score) from scoreop group by courseID +--3.查询出性别一样并且年龄一样的学生的信息 +select * from student A,student B where A.StuAge=B.StuAge and A.StuSex=B.StuSex AND A.stuID != B.stuID +--4.查询出学分一样的课程信息 +SELECT A.* FROM course A, course B WHERE A.courseMaks=B.courseMaks AND A.courseName!=B.courseName +UNION +SELECT A.* FROM course A, course B WHERE A.courseMaks=B.courseMaks AND A.courseName!=B.courseName +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +SELECT B.sluID,A.stuName,B.courseID,B.score FROM student A INNER JOIN scoreop B ON A.stuID=B.sluID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +SELECT B.stuName,C.courseID,C.score,A.courseMaks,A.courseName FROM student B INNER JOIN scoreop C ON B.stuID= C.sluID INNER JOIN course A ON C.courseID=A.courseID +--7.查询出没有参加考试的学生的学号和姓名 +SELECT stuID,stuName FROM student WHERE stuID NOT IN (SELECT sluID FROM scoreop GROUP BY sluID,courseID) +--8.查询出是周六周天来报到的学生 +SELECT A.time,stuName FROM student A GROUP BY time,stuName +--9.查询出姓名中有字母a的学生的信息 +select * FROM student WHERE stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select COUNT(*),sluID,AVG(score) from scoreop GROUP BY sluID HAVING COUNT(*)>=2 AND AVG(score)>=70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" new file mode 100644 index 0000000..a693254 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" @@ -0,0 +1,104 @@ +use master +go +create database TBSE +on +( name='TA', + filename='D:\TA.mdf', + size=5, + maxsize=500, + filegrowth=1 +) + log on +( name='TA_log', + filename='D:\TA_log.ldf', + size=5, + maxsize=500, + filegrowth=1 +) +go +use TBSE +go +create table tbl_card +( + id varchar(8) primary key, + passWord varchar(15) not null, + balance money not null, + userName nchar(5) +) +go +create table tbl_computer +( + id char(5) primary key, + onUse int not null, + note text not null +) +go +create table tbl_record +( + id int primary key, + cardld varchar(8) references tbl_card(id), + ComputerId char(5) references tbl_computer(id), + beginTime datetime , + endTime datetime, + fee money not null +) +go +insert into tbl_card values('0023_ABC','555',99,'张军'), + ('0025_bbd','abc',300,'朱俊'), + ('0036_CCD','何柳',100,'何柳'), + ('0045_YGR','0045_YGR',58,'验证'), + ('0078_RJV','55885fg',600,'校庆'), + ('0089_EDE','zhang',134,'张俊') + +insert into tbl_computer values('02',0,'25555'), + ('03',1,'55555'), + ('04',0,'66666'), + ('05',1,'888888'), + ('06',0,'688878'), + ('B01',0,'558558') + + +insert into tbl_record values('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), + ('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), + ('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), + ('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), + ('47','0023_ABC','03','2006-12-23 15:26:00','2007-12-23 22:55:00','50'), + ('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), + ('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), + ('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), + ('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), + ('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') +--请完成以下题目: +select*from tbl_card +select*from tbl_computer +select*from tbl_record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select cardld 卡号, userName 用户名, beginTime 开始时间, endTime 结束时间, fee 消费金额 from tbl_record join tbl_computer on tbl_computer.id=tbl_record.ComputerId + join tbl_card on cardld=tbl_card.id where userName='张军' order by fee +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId, count(ComputerId) 上网次数,sum(fee) 消费总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardld 网卡, sum(fee) 消费总金额 from tbl_record group by cardld +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id 卡号 , userName 用户名 from tbl_card where id not in (select cardld from tbl_record ) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select T.id 卡号,T.passWord 密码,T.balance 卡上的余额,T.userName 用户名 from tbl_card,tbl_card T where tbl_card.passWord=T.userName + +select T.* from tbl_card,tbl_card T where tbl_card.passWord=T.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号, count(ComputerId) 使用次数 from tbl_record group by ComputerId order by count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,fee 消费金额 from tbl_record join tbl_card on tbl_card.id=cardld where cardld like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record join tbl_card on tbl_card.id=cardld + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record join tbl_card on tbl_card.id=cardld where datediff(HOUR,beginTime,endTime)>=12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record join tbl_card on tbl_card.id=cardld order by fee desc \ No newline at end of file -- Gitee From adde0d6e4c2471e0cd3b5dd09014483f5792634e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0=E6=96=B0?= <2523868292@qq.com> Date: Wed, 31 Mar 2021 19:10:50 +0800 Subject: [PATCH 082/195] =?UTF-8?q?=E7=BD=97=E5=AE=87=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery14.sql" | 168 ++++++++++-------- 1 file changed, 97 insertions(+), 71 deletions(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" index f1b5ecd..6e84744 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" @@ -53,62 +53,62 @@ insert into scoreInfo values ('1','1','80'),('1','2','85'),('1','4','50'),('2',' ('3','1','45'),('4','1','95'),('4','2','75'),('4','3','90'),('4','4','45') ---1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +--1.鏌ヨ鍑烘瘡涓鐢熸墍閫変慨鐨勮绋嬬殑鏁伴噺鍜屾墍閫変慨鐨勮绋嬬殑鑰冭瘯鐨勫钩鍧囧垎 -select stuID 学生,count(courseID) 数量,AVG(score) 平均分 from scoreInfo group by stuID +select stuID 瀛︾敓,count(courseID) 鏁伴噺,AVG(score) 骞冲潎鍒 from scoreInfo group by stuID ---2.查询出每门课程的选修的学生的个数和学生考试的总分 +--2.鏌ヨ鍑烘瘡闂ㄨ绋嬬殑閫変慨鐨勫鐢熺殑涓暟鍜屽鐢熻冭瘯鐨勬诲垎 -select courseName 课程,count(stuID) 学生个数,sum(score) 总分 from scoreInfo inner join courseInfo +select courseName 璇剧▼,count(stuID) 瀛︾敓涓暟,sum(score) 鎬诲垎 from scoreInfo inner join courseInfo on scoreInfo.courseID=courseInfo.courseID group by courseInfo.courseID,courseName ---3.查询出性别一样并且年龄一样的学生的信息 +--3.鏌ヨ鍑烘у埆涓鏍峰苟涓斿勾榫勪竴鏍风殑瀛︾敓鐨勪俊鎭 select * from stuInfo where stuAge in (select stuAge from stuInfo -group by stuAge,stuSex having count(stuAge)>1)--法1 +group by stuAge,stuSex having count(stuAge)>1)--娉1 -select +select A.* from stuInfo A,stuInfo B where ---4.查询出学分一样的课程信息 +--4.鏌ヨ鍑哄鍒嗕竴鏍风殑璇剧▼淇℃伅 select * from courseInfo where courseMarks in (select courseMarks from courseInfo group by courseMarks having count(courseMarks)>1) ---5.查询出参加了考试的学生的学号,姓名,课程号和分数 +--5.鏌ヨ鍑哄弬鍔犱簡鑰冭瘯鐨勫鐢熺殑瀛﹀彿锛屽鍚嶏紝璇剧▼鍙峰拰鍒嗘暟 -select scoreInfo.stuID 学号,stuName 姓名,courseID 课程,score 分数 +select scoreInfo.stuID 瀛﹀彿,stuName 濮撳悕,courseID 璇剧▼,score 鍒嗘暟 from scoreInfo inner join stuInfo on scoreInfo.stuID=stuInfo.stuID ---6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +--6.鏌ヨ鍑哄弬鍔犱簡鑰冭瘯鐨勫鐢熺殑瀛﹀彿锛岃绋嬪彿锛岃绋嬪悕锛岃绋嬪鍒嗗拰鍒嗘暟 -select stuID 学号,courseInfo.courseID 课程号,courseName 课程名,courseMarks 学分,score 分数 +select stuID 瀛﹀彿,courseInfo.courseID 璇剧▼鍙,courseName 璇剧▼鍚,courseMarks 瀛﹀垎,score 鍒嗘暟 from courseInfo inner join scoreInfo on courseInfo.courseID=scoreInfo.courseID ---7.查询出没有参加考试的学生的学号和姓名 +--7.鏌ヨ鍑烘病鏈夊弬鍔犺冭瘯鐨勫鐢熺殑瀛﹀彿鍜屽鍚 select stuID,stuName from stuInfo EXCEPT select stuInfo.stuID,stuName from scoreInfo inner join stuInfo on scoreInfo.stuID=stuInfo.stuID ---8.查询出是周六周天来报到的学生 +--8.鏌ヨ鍑烘槸鍛ㄥ叚鍛ㄥぉ鏉ユ姤鍒扮殑瀛︾敓 select stuname,time from stuInfo where time =CONVERT(datetime,time) group by time,stuname select * from stuInfo select * from courseInfo select * from scoreInfo ---9.查询出姓名中有字母a的学生的信息 +--9.鏌ヨ鍑哄鍚嶄腑鏈夊瓧姣峚鐨勫鐢熺殑淇℃伅 select * from stuInfo where stuName like '%a%' ---10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +--10.鏌ヨ鍑洪変慨浜2闂ㄨ绋嬩互涓婄殑骞朵笖鑰冭瘯骞冲潎鍒嗗湪70浠ヤ笂鐨勫鐢熺殑瀛﹀彿鍜岃冭瘯骞冲潎鍒嗕互鍙婇変慨璇剧▼鐨勬暟閲 -select stuID,avg(score) 平均分,count(courseID) 选修课程数量 from scoreInfo group by stuID +select stuID,avg(score) 骞冲潎鍒,count(courseID) 閫変慨璇剧▼鏁伴噺 from scoreInfo group by stuID having avg(score) >70 and count(courseID)>2 ---首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: +--棣栧厛鍒涘缓缃戝惂璁¤垂绯荤粺鐨勬暟鎹簱锛岃〃缁撴瀯鍜屾暟鎹2.bmp鎵绀猴紝琛ㄧ殑璇存槑濡備笅锛 create database wbfee on ( @@ -130,66 +130,92 @@ go use wbfee go ---表一为上网卡信息表(tbl_card) ---id: 卡号,主键 ---passWord:密码 ---balance:卡上的余额 ---userName:该上网卡所属的用户名 create table tbl_card ( - ID varchar(8) primary key, - PassWord nvarchar(50) not null, - Balance int, - UserName nvarchar(20) + id nvarchar(10) primary key, + passWord nvarchar(15), + balance money , + userName nvarchar(10) ) -insert into tbl_card values -('0023_ABC','555',98,'张军'), -('0025_bbd','abe',300,'朱俊'), -('0036_CCD','何柳',100,'何柳'), -('0045_YGR','0045_YGR',68,'证验'), -('0078_RJV','55885fg',600,'校庆'), -('0089_EDE','zhang',134,'张峻') ---表2为网吧机器说明表(tbl_computer) ---id:机器编号,主键 ---onUse:该机器是否正在使用,0为未使用,1为正在使用 ---note:该机器的说明 + create table tbl_computer ( - ID varchar(3) primary key, - OnUse varchar(1) check(OnUse='1' or OnUse='0'), - Note varchar(20) + id nvarchar(10) primary key, + onUse int check(onUse in (1,0)), + note text ) -insert into tbl_computer values -('02','0','25555'), -('03','1','55555'), -('04','0','66666'), -('05','1','88888'), -('06','0','688878'), -('B01','0','558558') ---表3为上网记录表(tbl_record): ---id:记录编号,主键 ---cardId:本次上网的卡号,外键 ---ComputerId:本次上网记录所使用的机器号,外键 ---beginTime:本次上网记录的开始时间 ---endTime:本次上网记录的结束时间 ---fee:本次上网的费用 + create table tbl_record ( - ID int primary key, - CardID varchar(8) references tbl_card(ID), - ComputerID varchar(3) references tbl_computer(ID), - BeginTime datetime, - EndTime datetime, - Fee int + id nvarchar(10) primary key, + cardId nvarchar(10) foreign key references tbl_card(id), + ComputerId nvarchar(10) foreign key references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee money ) + + +insert into tbl_card values +('0023_ABC','555',98,'寮犲啗'), +('0025_bbd','abe',300,'鏈变繆'), +('0036_CCD','',100,'浣曟煶'), +('0045_YGR','0045_YGR',58,'楠岃瘉'), +('0078_RJV','55885tg',600,'鏍″簡'), +('0089_EDE','zhang',134,'寮犲郴') + + + +insert into tbl_computer values +('02',0,'25555'), +('03',1,'55555'), +('04',0,'66666'), +('05',1,'88888'), +('06',0,'688878'), +('B01',0,'558558') + insert into tbl_record values -(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), -(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), -(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), -(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), -(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), -(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), -(55,'0023_ABC','03','2007-07-21 15:26:00','2007-07-21 22:55:00',50), -(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), -(65,'0025_bbd','02','2006-12-28 18:00:00','2007-12-28 22:00:00',23), -(98,'0025_bbd','B01','2007-12-26 18:00:00','2007-12-26 22:00:00',23) \ No newline at end of file +(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','300'), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + + +--tbl_record,tbl_computer ,tbl_card +--1. 鏌ヨ鍑虹敤鎴峰悕涓'寮犲啗'鐨勪笂缃戝崱鐨勪笂缃戣褰曪紝瑕佹眰鏄剧ず鍗″彿锛岀敤鎴峰悕锛屾満鍣ㄧ紪鍙枫佸紑濮嬫椂闂淬佺粨鏉熸椂闂达紝鍜屾秷璐归噾棰濓紝骞舵寜娑堣垂閲戦闄嶅簭鎺掑垪 +select C.id 鏄剧ず鍗″彿,userName 鐢ㄦ埛鍚,P.id 鏈哄櫒缂栧彿,beginTime 寮濮嬫椂闂,endTime 缁撴潫鏃堕棿,fee 娑堣垂閲戦 from tbl_record R +inner join tbl_card C on C.id=cardId +inner join tbl_computer P on P.id=R.ComputerId where userName='寮犲啗' order by fee DESC +--2. 鏌ヨ鍑烘瘡鍙版満鍣ㄤ笂鐨勪笂缃戞鏁板拰娑堣垂鐨勬婚噾棰 +select C.id 鏈哄櫒,count(ComputerId) 涓婄綉娆℃暟,sum(fee) 娑堣垂鐨勬婚噾棰 from tbl_record R +inner join tbl_computer C on C.id=R.ComputerId group by C.id + +--3. 鏌ヨ鍑烘墍鏈夊凡缁忎娇鐢ㄨ繃鐨勪笂缃戝崱鐨勬秷璐规婚噾棰 +select cardId 涓婄綉鍗,sum(fee) 娑堣垂鎬婚噾棰 from tbl_record group by cardId + + +--4. 鏌ヨ鍑轰粠鏈秷璐硅繃鐨勪笂缃戝崱鐨勫崱鍙峰拰鐢ㄦ埛鍚 +select id,userName from tbl_card where id not in(select distinct cardId from tbl_record) + + +--5. 灏嗗瘑鐮佷笌鐢ㄦ埛鍚嶄竴鏍风殑涓婄綉鍗′俊鎭煡璇㈠嚭鏉 +select * from tbl_card where id=password +--6. 鏌ヨ鍑轰娇鐢ㄦ鏁版渶澶氱殑鏈哄櫒鍙峰拰浣跨敤娆℃暟 +select top 1 C.id,count(ComputerId) from tbl_record R inner join tbl_computer C on C.id=ComputerId group by C.id order by count(ComputerId) DESC +--7. 鏌ヨ鍑哄崱鍙锋槸浠'ABC'缁撳熬鐨勫崱鍙凤紝鐢ㄦ埛鍚嶏紝涓婄綉鐨勬満鍣ㄥ彿鍜屾秷璐归噾棰 +select userName,P.id,fee from tbl_record R inner join tbl_computer P on ComputerId=P.id inner join tbl_card C on C.id=cardId where cardId like '%ABC' + +--8. 鏌ヨ鍑烘槸鍛ㄥ叚銆佸懆澶╀笂缃戠殑璁板綍锛岃姹傛樉绀轰笂缃戠殑鍗″彿锛岀敤鎴峰悕锛屾満鍣ㄥ彿锛屽紑濮嬫椂闂淬佺粨鏉熸椂闂村拰娑堣垂閲戦 +select cardId,userName,P.id,beginTime,endTime,fee from tbl_record inner join tbl_computer P on ComputerId=P.id inner join tbl_card C on C.id=cardId where datepart(weekday,beginTime)=1 or datepart(weekday,beginTime)=7 + +--9. 鏌ヨ鎴愪竴娆′笂缃戞椂闂磋秴杩12灏忔椂鐨勭殑涓婄綉璁板綍锛岃姹傛樉绀轰笂缃戠殑鍗″彿锛岀敤鎴峰悕锛屾満鍣ㄥ彿锛屽紑濮嬫椂闂淬佺粨鏉熸椂闂村拰娑堣垂閲戦 +select cardId,userName,P.id,beginTime,endTime,fee from tbl_record inner join tbl_computer P on ComputerId=P.id inner join tbl_card C on C.id=cardId where datediff(hour,beginTime,endTime)>12 + +--10. 鏌ヨ闄ゆ秷璐归噾棰濇帓鍒楀墠涓夊悕(鏈楂)鐨勪笂缃戣褰曪紝瑕佹眰鏄剧ず涓婄綉鐨勫崱鍙凤紝鐢ㄦ埛鍚嶏紝鏈哄櫒鍙凤紝寮濮嬫椂闂淬佺粨鏉熸椂闂村拰娑堣垂閲戦 +select cardId,userName,P.id,beginTime,endTime,fee from tbl_record inner join tbl_computer P on ComputerId=P.id inner join tbl_card C on C.id=cardId where fee not in(select top 3 fee from tbl_record order by fee DESC) -- Gitee From 32d647912243a1602de14c5a4ba3ca5bba8bbcb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0=E6=96=B0?= <2523868292@qq.com> Date: Wed, 31 Mar 2021 19:21:26 +0800 Subject: [PATCH 083/195] =?UTF-8?q?=E7=BD=97=E5=AE=87=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" index 6e84744..dbfcd73 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" @@ -67,7 +67,7 @@ on scoreInfo.courseID=courseInfo.courseID group by courseInfo.courseID,courseNam select * from stuInfo where stuAge in (select stuAge from stuInfo group by stuAge,stuSex having count(stuAge)>1)--娉1 -select A.* from stuInfo A,stuInfo B where +select A.* from stuInfo A,stuInfo B where A.stuAge=B.stuAge and A.stuSex=B.stuSex and A.stuID!=b.stuID--娉2 --4.鏌ヨ鍑哄鍒嗕竴鏍风殑璇剧▼淇℃伅 -- Gitee From cc015317f60bef77998dc25f514b80abe695939e Mon Sep 17 00:00:00 2001 From: PilRio <2535341085@qq.com> Date: Wed, 31 Mar 2021 19:29:04 +0800 Subject: [PATCH 084/195] sql --- .../SQLQuery1.sql" | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" index 41eb48f..a1e2ec0 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" @@ -3,12 +3,12 @@ create database excise on ( name = 'excise', - filename = 'D:\数据库\excise.mdf' + filename = 'D:\excise.mdf' ) log on ( name = 'excise_log', - filename = 'D:\数据库\excise_log.ldf' + filename = 'D:\excise_log.ldf' ) use excise @@ -63,9 +63,6 @@ insert into scoreInfo values (4,2,75), (4,3,90), (4,4,45) -select * from scoreInfo -select * from courseInfo -select * from stuInfo --.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 select stuInfo.stuName 姓名,count(courseName)选修课程数量,avg(score)平均分 from stuInfo,courseInfo,scoreInfo where @@ -84,13 +81,31 @@ where a.courseMarks = b.courseMarks and a.courseID != B.courseID group by a.courseName,a.courseMarks --5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select st.stuID 学号,st.stuName 姓名,co.courseID 课程号,sc.score 分数 from stuInfo st +left join scoreInfo sc on st.stuID = sc.stuID +left join courseInfo co on sc.courseID = co.courseID +where sc.score is not null --6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select st.stuID 学号,st.stuName 姓名,co.courseID 课程号,co.courseName 课程名, sc.score 分数 from stuInfo st +left join scoreInfo sc on st.stuID = sc.stuID +left join courseInfo co on sc.courseID = co.courseID +where sc.score is not null --7.查询出没有参加考试的学生的学号和姓名 +select st.stuID 学号,st.stuName from stuInfo st +left join scoreInfo sc on st.stuID = sc.stuID +where sc.score is null --8.查询出是周六周天来报到的学生 --9.查询出姓名中有字母a的学生的信息 - ---10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select * from stuInfo where stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的 学号 和 考试平均分 以及 选修课程的数量 +select * from scoreInfo +select * from courseInfo +select * from stuInfo +select st.stuID 学号,avg(sc.score)平均分,count(co.courseID) 选修数量 from stuInfo st +left join scoreInfo sc on st.stuID = sc.stuID +left join courseInfo co on sc.courseID = co.courseID +group by st.stuID having avg(sc.score)>70 and count(co.courseID)>=2 \ No newline at end of file -- Gitee From 733ff88c6938c9e45709f05bf4fa2450f2996b8c Mon Sep 17 00:00:00 2001 From: PilRio <2535341085@qq.com> Date: Wed, 31 Mar 2021 19:30:17 +0800 Subject: [PATCH 085/195] sql --- .../\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" index a1e2ec0..ca04c58 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" @@ -101,10 +101,8 @@ where sc.score is null --9.查询出姓名中有字母a的学生的信息 select * from stuInfo where stuName like '%a%' + --10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的 学号 和 考试平均分 以及 选修课程的数量 -select * from scoreInfo -select * from courseInfo -select * from stuInfo select st.stuID 学号,avg(sc.score)平均分,count(co.courseID) 选修数量 from stuInfo st left join scoreInfo sc on st.stuID = sc.stuID left join courseInfo co on sc.courseID = co.courseID -- Gitee From 9a6dd3281dbb77cd54fec98da3274c964584a816 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 31 Mar 2021 19:39:19 +0800 Subject: [PATCH 086/195] 44444 --- .../\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" index 3709fb8..069c26b 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/\347\273\203\344\271\2402.sql" @@ -75,9 +75,11 @@ select ComputerId --3. 查询出所有已经使用过的上网卡的消费总金额 select cardId,sum(record.fee) 总金额 from record group by cardId --4. 查询出从未消费过的上网卡的卡号和用户名 -select * from card where (select record.id from record) +select card.id,userName from card +left join record on card.id=record.cardId +where fee is null group by userName,card.id --5. 将密码与用户名一样的上网卡信息查询出来 - +select A.* from card A,card B where A.pasword=B.userName --6. 查询出使用次数最多的机器号和使用次数 select top 1 ComputerId 机器号,count(ComputerId)使用次数 from record group by ComputerId order By count(ComputerId) desc -- Gitee From 00da785dfdf7c5735693113be0336f12140e1171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0=E6=96=B0?= <2523868292@qq.com> Date: Wed, 31 Mar 2021 19:59:03 +0800 Subject: [PATCH 087/195] =?UTF-8?q?=E7=BD=97=E5=AE=87=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" index dbfcd73..13012d9 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery14.sql" @@ -91,7 +91,7 @@ select stuInfo.stuID,stuName from scoreInfo inner join stuInfo on scoreInfo.stuID=stuInfo.stuID --8.鏌ヨ鍑烘槸鍛ㄥ叚鍛ㄥぉ鏉ユ姤鍒扮殑瀛︾敓 -select stuname,time from stuInfo where time =CONVERT(datetime,time) group by time,stuname +select stuname,time from stuInfo where DATEPART(dw,time)=1 or DATEPART(dw,time)=7 select * from stuInfo select * from courseInfo -- Gitee From c8caa96eb4321402f9a20533d8b3408826316bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BB=BA=E5=B3=B0?= <357616491@qq.com> Date: Wed, 31 Mar 2021 20:00:16 +0800 Subject: [PATCH 088/195] ljf --- .../\344\275\234\344\270\2321.sql" | 77 ++++++++++++ .../\344\275\234\344\270\2322.sql" | 113 ++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..a1d5a54 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" @@ -0,0 +1,77 @@ +create table stuInfo +( +stulD int not null, +stuName varchar(20) not null, +stuAge int not null, +stuSex int not null, +time datetime not null +) +create table courseInfo +( +courselD int not null, +courseName varchar(20) not null, +courseMarks int not null +) +create table scoreInfo +( +scoreID int not null, +stuID int not null, +courseID int not null, +score int not null +) + +insert into stuInfo values +('1','Tom','19','1',''),('2','jack','20','0',''), +('3','Rose','21','1',''),('4','Lulu','19','1','') +,('5','Lili','21','0',''),('6','abc','20','1','2007-01-07 01:11:36.590') + + +insert into courseInfo values +('1','javaBase','4'),('2','HTML','2') +,('3','javaScript','2'),('4','SqIBase','2') + + +insert into scoreInfo values +('1','1','1','80'),('2','1','2','85'), +('3','1','4','50'),('4','2','1','75'), +('5','2','3','45'),('6','2','4','75'), +('7','3','1','45'),('8','4','1','95'), +('9','4','2','75'),('10','4','3','90'), +('11','4','4','45') + +select * from stuInfo +select * from courseInfo +select * from scoreInfo + + + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseID 课程, count(courseID)选修个数, sum(score)总分 from scoreInfo group by courseID +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A, stuInfo B +where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stulD!=B.stulD +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks AND A.courselD!=B.courselD +--5.查询出参加了 考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo +left join stuInfo on scoreInfo.stuID=stuInfo.stulD group by scoreInfo.stuID,stuName,courseID,score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo +left join courseInfo on scoreInfo.courseID=courseInfo.courselD +--7.查询出没有参加考试的学生的学号和姓名 +select Stuinfo.stulD 学号,stuInfo.stuName 姓名 from stuInfo +left join scoreInfo on stuInfo.stulD=scoreInfo.stuID +where score is null +--8.查询出是周六周天来报到的学生 + --超纲了!!!!!!!!!!!!!!!! +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出 选修了2门课程 以上的 并且 考试平均分 在70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo +group by stuID +having avg(score)>=70 and count(courseID)>=2 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..141af55 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" @@ -0,0 +1,113 @@ +use master +go +create database wb +on +( + name='wb', + filename='D:\wb.mdf' +) +log on +( + name='wb_log', + filename='D:\wb_log.ldf' +) +go +use wb +go + +create table card +( + id varchar(30) primary key, + pasword varchar(30), + balance money, + userName varchar(50) +) +create table computer +( + id varchar(30) primary key, + onUse varchar(2) check(onUse=0 or onUse=1), + note ntext +) +create table record +( + id varchar(30) primary key, + cardId varchar(30) foreign key references card(id), + ComputerId varchar(30) foreign key references computer(id), + beginTime datetime, + endTime datetime, + fee money +) + + +insert into card(ID,pasword,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' + + +insert into computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' + + +insert into record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + + + +select * from card +select * from computer +select * from record + + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号, +--用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select card.id 卡号, card.userName 用户名 ,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from card inner join record on card.id=record.cardId where userName='张军' order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 from record group by cardId,ComputerId +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId,sum(record.fee) 总金额 from record group by cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id,userName from card where id not in(select distinct cardId from record) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from card where id=pasword + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId)使用次数 from record +group by ComputerId order By count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 +from record inner join card on record.cardId=card.id where record.cardId like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号, +--用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,P.id,beginTime,endTime,fee from record inner join computer P +on ComputerId=P.id inner join card C on C.id=cardId where datepart(weekday,beginTime)=1 or datepart(weekday,beginTime)=7 + +--9. 查询成一次上网时间超过12小时的的上网记录, +--要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,P.id,beginTime,endTime,fee from record inner join computer P on ComputerId=P.id inner join card C on C.id=cardId where datediff(hour,beginTime,endTime)>12 + +--10. 查询除消费金额排列前三名(最高)的上网记录, +--要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc -- Gitee From 80a8d6d24df152ed5056f0e1b7d5ef3bf453a5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=BF=E6=A3=AE?= <2287431003@qq.com> Date: Wed, 31 Mar 2021 20:02:51 +0800 Subject: [PATCH 089/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/?= =?UTF-8?q?=E6=BB=95=E9=91=AB/SQLQuery2.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\346\273\225\351\221\253/SQLQuery2.sql" | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" deleted file mode 100644 index 5482d0d..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" +++ /dev/null @@ -1,66 +0,0 @@ -create database txa -on -( - name ='txa', - size=10, - filename='D:\txa.mdf', - maxsize=100, - filegrowth=10 -) -log on -( - name ='txa_log', - size=10, - filename='D:\txa_log.ldf', - maxsize=100, - filegrowth=10 -) -go -use txa -go -create table tbl_card -( - id nvarchar(10) primary key, - passWord nvarchar(18), - balance int, - userName nvarchar(20) -) -create table tbl_computer -( - id nvarchar(10) primary key, - onUse int, - note nvarchar(200) -) -create table tbl_record -( - id nvarchar(10) primary key, - cardid nvarchar(10) foreign key references tbl_card(id), - Computerid nvarchar(10) foreign key references tbl_computer(id), - beginTime datetime, - endTime datetime, - fee int -) -insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), -('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885lg',600,'校庆'),('0089_EDE','zhang',134,'张峻') -insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'),('06',0,'688878'),('B01',0,'558558') -insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20),(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23),(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50),(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6),(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), -(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6),(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50),(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',30),(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23),(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) -select cardid,userName,Computerid,beginTime,endTime,fee from tbl_card t inner join tbl_record x on t.id=cardid where userName='张军' order by fee desc - -select x.id,count(ComputerId) 上网次数,sum(fee) 消费的总金额 from tbl_record t inner join tbl_computer x on t.ComputerId=x.id group by x.id - -select cardId 上网卡,sum(fee) 消费总金额 from tbl_record group by cardId - -select id,userName from tbl_card where id not in(select distinct cardId from tbl_record) - -select * from tbl_card where id=password - -select top 1 x.id,count(ComputerId) from tbl_record t inner join tbl_computer x on t.Computerid=x.id group by x.id order by count(ComputerId) DESC - -select userName,x.id,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where cardId like '%ABC' - -select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on t.ComputerId=x.id inner join tbl_card a on a.id=t.cardId where datepart(weekday,beginTime)=6 or datepart(weekday,beginTime)=7 - -select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where datediff(hour,beginTime,endTime)>12 - -select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where fee not in(select top 3 fee from tbl_record order by fee DESC) -- Gitee From 9bcc381a1aacc5bf8c9cd5227c53be0213bf0c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=BF=E6=A3=AE?= <2287431003@qq.com> Date: Wed, 31 Mar 2021 20:04:18 +0800 Subject: [PATCH 090/195] sql --- .../\346\273\225\351\221\253/SQLQuery2.sql" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" new file mode 100644 index 0000000..6a9fa2e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery2.sql" @@ -0,0 +1,66 @@ +create database txa +on +( + name ='txa', + size=10, + filename='D:\txa.mdf', + maxsize=100, + filegrowth=10 +) +log on +( + name ='txa_log', + size=10, + filename='D:\txa_log.ldf', + maxsize=100, + filegrowth=10 +) +go +use txa +go +create table tbl_card +( + id nvarchar(10) primary key, + passWord nvarchar(18), + balance int, + userName nvarchar(20) +) +create table tbl_computer +( + id nvarchar(10) primary key, + onUse int, + note nvarchar(200) +) +create table tbl_record +( + id nvarchar(10) primary key, + cardid nvarchar(10) foreign key references tbl_card(id), + Computerid nvarchar(10) foreign key references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee int +) +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885lg',600,'校庆'),('0089_EDE','zhang',134,'张峻') +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'),('06',0,'688878'),('B01',0,'558558') +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20),(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23),(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50),(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6),(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6),(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50),(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',30),(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23),(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) +select cardid,userName,Computerid,beginTime,endTime,fee from tbl_card t inner join tbl_record x on t.id=cardid where userName='张军' order by fee desc + +select x.id,count(ComputerId) 上网次数,sum(fee) 消费的总金额 from tbl_record t inner join tbl_computer x on t.ComputerId=x.id group by x.id + +select cardId 上网卡,sum(fee) 消费总金额 from tbl_record group by cardId + +select id,userName from tbl_card where id not in(select distinct cardId from tbl_record) + +select * from tbl_card where password=userName + +select top 1 x.id,count(ComputerId) from tbl_record t inner join tbl_computer x on t.Computerid=x.id group by x.id order by count(ComputerId) DESC + +select userName,x.id,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where cardId like '%ABC' + +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on t.ComputerId=x.id inner join tbl_card a on a.id=t.cardId where datepart(weekday,beginTime)=6 or datepart(weekday,beginTime)=7 + +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where datediff(hour,beginTime,endTime)>12 + +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where fee not in(select top 3 fee from tbl_record order by fee DESC) -- Gitee From 59f633ff2fb33ab78fb4422c10ade69e00bebec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BB=BA=E5=B3=B0?= <357616491@qq.com> Date: Wed, 31 Mar 2021 20:07:21 +0800 Subject: [PATCH 091/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/?= =?UTF-8?q?=E5=88=98=E5=BB=BA=E5=B3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\275\234\344\270\2321.sql" | 77 ------------ .../\344\275\234\344\270\2322.sql" | 113 ------------------ 2 files changed, 190 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" deleted file mode 100644 index a1d5a54..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" +++ /dev/null @@ -1,77 +0,0 @@ -create table stuInfo -( -stulD int not null, -stuName varchar(20) not null, -stuAge int not null, -stuSex int not null, -time datetime not null -) -create table courseInfo -( -courselD int not null, -courseName varchar(20) not null, -courseMarks int not null -) -create table scoreInfo -( -scoreID int not null, -stuID int not null, -courseID int not null, -score int not null -) - -insert into stuInfo values -('1','Tom','19','1',''),('2','jack','20','0',''), -('3','Rose','21','1',''),('4','Lulu','19','1','') -,('5','Lili','21','0',''),('6','abc','20','1','2007-01-07 01:11:36.590') - - -insert into courseInfo values -('1','javaBase','4'),('2','HTML','2') -,('3','javaScript','2'),('4','SqIBase','2') - - -insert into scoreInfo values -('1','1','1','80'),('2','1','2','85'), -('3','1','4','50'),('4','2','1','75'), -('5','2','3','45'),('6','2','4','75'), -('7','3','1','45'),('8','4','1','95'), -('9','4','2','75'),('10','4','3','90'), -('11','4','4','45') - -select * from stuInfo -select * from courseInfo -select * from scoreInfo - - - ---有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) - ---1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 -select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID ---2.查询出每门课程的选修的学生的个数和学生考试的总分 -select courseID 课程, count(courseID)选修个数, sum(score)总分 from scoreInfo group by courseID ---3.查询出性别一样并且年龄一样的学生的信息 -select A.* from stuInfo A, stuInfo B -where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stulD!=B.stulD ---4.查询出学分一样的课程信息 -select distinct A.* from courseInfo A,courseInfo B -where A.courseMarks=B.courseMarks AND A.courselD!=B.courselD ---5.查询出参加了 考试的学生的学号,姓名,课程号和分数 -select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo -left join stuInfo on scoreInfo.stuID=stuInfo.stulD group by scoreInfo.stuID,stuName,courseID,score ---6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 -select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo -left join courseInfo on scoreInfo.courseID=courseInfo.courselD ---7.查询出没有参加考试的学生的学号和姓名 -select Stuinfo.stulD 学号,stuInfo.stuName 姓名 from stuInfo -left join scoreInfo on stuInfo.stulD=scoreInfo.stuID -where score is null ---8.查询出是周六周天来报到的学生 - --超纲了!!!!!!!!!!!!!!!! ---9.查询出姓名中有字母a的学生的信息 -select * from stuInfo where stuName like '%a%' ---10.查询出 选修了2门课程 以上的 并且 考试平均分 在70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 -select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo -group by stuID -having avg(score)>=70 and count(courseID)>=2 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" deleted file mode 100644 index 141af55..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" +++ /dev/null @@ -1,113 +0,0 @@ -use master -go -create database wb -on -( - name='wb', - filename='D:\wb.mdf' -) -log on -( - name='wb_log', - filename='D:\wb_log.ldf' -) -go -use wb -go - -create table card -( - id varchar(30) primary key, - pasword varchar(30), - balance money, - userName varchar(50) -) -create table computer -( - id varchar(30) primary key, - onUse varchar(2) check(onUse=0 or onUse=1), - note ntext -) -create table record -( - id varchar(30) primary key, - cardId varchar(30) foreign key references card(id), - ComputerId varchar(30) foreign key references computer(id), - beginTime datetime, - endTime datetime, - fee money -) - - -insert into card(ID,pasword,balance,userName) -select '0023_ABC','555','98','张军'union -select '0025_bbd','abe','300','朱俊'union -select '0036_CCD','何柳','100','何柳'union -select '0045_YGR','0045_YGR','58','证验'union -select '0078_RJV','55885fg','600','校庆'union -select '0089_EDE','张','134','张峻' - - -insert into computer(id,onUse,note) -select '02','0','25555' union -select '03','1','55555' union -select '04','0','66666' union -select '05','1','88888' union -select '06','0','688878' union -select 'B01','0','558558' - - -insert into record(ID,cardId,ComputerId,beginTime,endTime,fee) -select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union -select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union -select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union -select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union -select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union -select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union -select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union -select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union -select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union -select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' - - - -select * from card -select * from computer -select * from record - - ---1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号, ---用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 -select card.id 卡号, card.userName 用户名 ,beginTime 开始时间,endTime 结束时间,fee 消费金额 -from card inner join record on card.id=record.cardId where userName='张军' order by fee desc ---2. 查询出每台机器上的上网次数和消费的总金额 -select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 from record group by cardId,ComputerId ---3. 查询出所有已经使用过的上网卡的消费总金额 -select cardId,sum(record.fee) 总金额 from record group by cardId - ---4. 查询出从未消费过的上网卡的卡号和用户名 -select id,userName from card where id not in(select distinct cardId from record) - ---5. 将密码与用户名一样的上网卡信息查询出来 -select * from card where id=pasword - ---6. 查询出使用次数最多的机器号和使用次数 -select top 1 ComputerId 机器号,count(ComputerId)使用次数 from record -group by ComputerId order By count(ComputerId) desc - ---7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 -select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 -from record inner join card on record.cardId=card.id where record.cardId like '%ABC' - ---8. 查询出是周六、周天上网的记录,要求显示上网的卡号, ---用户名,机器号,开始时间、结束时间和消费金额 -select cardId,userName,P.id,beginTime,endTime,fee from record inner join computer P -on ComputerId=P.id inner join card C on C.id=cardId where datepart(weekday,beginTime)=1 or datepart(weekday,beginTime)=7 - ---9. 查询成一次上网时间超过12小时的的上网记录, ---要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -select cardId,userName,P.id,beginTime,endTime,fee from record inner join computer P on ComputerId=P.id inner join card C on C.id=cardId where datediff(hour,beginTime,endTime)>12 - ---10. 查询除消费金额排列前三名(最高)的上网记录, ---要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc -- Gitee From 86eb1ce3401b89d7dcff0d336cbcde6b453541ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BB=BA=E5=B3=B0?= <357616491@qq.com> Date: Wed, 31 Mar 2021 20:07:45 +0800 Subject: [PATCH 092/195] ljf --- .../\344\275\234\344\270\2321.sql" | 77 ++++++++++++ .../\344\275\234\344\270\2322.sql" | 113 ++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..a1d5a54 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2321.sql" @@ -0,0 +1,77 @@ +create table stuInfo +( +stulD int not null, +stuName varchar(20) not null, +stuAge int not null, +stuSex int not null, +time datetime not null +) +create table courseInfo +( +courselD int not null, +courseName varchar(20) not null, +courseMarks int not null +) +create table scoreInfo +( +scoreID int not null, +stuID int not null, +courseID int not null, +score int not null +) + +insert into stuInfo values +('1','Tom','19','1',''),('2','jack','20','0',''), +('3','Rose','21','1',''),('4','Lulu','19','1','') +,('5','Lili','21','0',''),('6','abc','20','1','2007-01-07 01:11:36.590') + + +insert into courseInfo values +('1','javaBase','4'),('2','HTML','2') +,('3','javaScript','2'),('4','SqIBase','2') + + +insert into scoreInfo values +('1','1','1','80'),('2','1','2','85'), +('3','1','4','50'),('4','2','1','75'), +('5','2','3','45'),('6','2','4','75'), +('7','3','1','45'),('8','4','1','95'), +('9','4','2','75'),('10','4','3','90'), +('11','4','4','45') + +select * from stuInfo +select * from courseInfo +select * from scoreInfo + + + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseID 课程, count(courseID)选修个数, sum(score)总分 from scoreInfo group by courseID +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A, stuInfo B +where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stulD!=B.stulD +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks AND A.courselD!=B.courselD +--5.查询出参加了 考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo +left join stuInfo on scoreInfo.stuID=stuInfo.stulD group by scoreInfo.stuID,stuName,courseID,score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo +left join courseInfo on scoreInfo.courseID=courseInfo.courselD +--7.查询出没有参加考试的学生的学号和姓名 +select Stuinfo.stulD 学号,stuInfo.stuName 姓名 from stuInfo +left join scoreInfo on stuInfo.stulD=scoreInfo.stuID +where score is null +--8.查询出是周六周天来报到的学生 + --超纲了!!!!!!!!!!!!!!!! +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出 选修了2门课程 以上的 并且 考试平均分 在70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo +group by stuID +having avg(score)>=70 and count(courseID)>=2 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..141af55 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/\344\275\234\344\270\2322.sql" @@ -0,0 +1,113 @@ +use master +go +create database wb +on +( + name='wb', + filename='D:\wb.mdf' +) +log on +( + name='wb_log', + filename='D:\wb_log.ldf' +) +go +use wb +go + +create table card +( + id varchar(30) primary key, + pasword varchar(30), + balance money, + userName varchar(50) +) +create table computer +( + id varchar(30) primary key, + onUse varchar(2) check(onUse=0 or onUse=1), + note ntext +) +create table record +( + id varchar(30) primary key, + cardId varchar(30) foreign key references card(id), + ComputerId varchar(30) foreign key references computer(id), + beginTime datetime, + endTime datetime, + fee money +) + + +insert into card(ID,pasword,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' + + +insert into computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' + + +insert into record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + + + +select * from card +select * from computer +select * from record + + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号, +--用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select card.id 卡号, card.userName 用户名 ,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from card inner join record on card.id=record.cardId where userName='张军' order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 from record group by cardId,ComputerId +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId,sum(record.fee) 总金额 from record group by cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id,userName from card where id not in(select distinct cardId from record) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from card where id=pasword + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId)使用次数 from record +group by ComputerId order By count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 +from record inner join card on record.cardId=card.id where record.cardId like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号, +--用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,P.id,beginTime,endTime,fee from record inner join computer P +on ComputerId=P.id inner join card C on C.id=cardId where datepart(weekday,beginTime)=1 or datepart(weekday,beginTime)=7 + +--9. 查询成一次上网时间超过12小时的的上网记录, +--要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,P.id,beginTime,endTime,fee from record inner join computer P on ComputerId=P.id inner join card C on C.id=cardId where datediff(hour,beginTime,endTime)>12 + +--10. 查询除消费金额排列前三名(最高)的上网记录, +--要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc -- Gitee From b3f68d5bdd980c453bfbcc74162b660f2e2ab5b8 Mon Sep 17 00:00:00 2001 From: EoL <1179233990@qq.com> Date: Wed, 31 Mar 2021 20:07:48 +0800 Subject: [PATCH 093/195] 1 --- .../SQLQuery2.sql" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery2.sql" new file mode 100644 index 0000000..e3def6a --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery2.sql" @@ -0,0 +1,77 @@ +use master +go + +create database InternetBar +on +( +name='InternetBar', +filename='D:\SQL\InternetBar.mdf', +size=10mb, +maxsize=100mb, +filegrowth=5mb +) +log on +( +name='InternetBar_log', +filename='D:\SQL\InternetBar_log.mdf', +size=10mb, +maxsize=100mb, +filegrowth=5mb +) +use InternetBar +go + +create table tbl_card +( + id char(8) primary key, + password nchar(10), + balance money, + userName nchar(2) +) +go + +create table tbl_computer +( + id char(3) primary key, + onUse int check(onUse in(0,1)), + note text +) +go + +create table tbl_record +( + id int primary key, + cardID char(8) references tbl_card(id), + ComputerID char(3) references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee money +) +go + +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abe',300,'朱俊'),('0036_CCD','何柳',100,'何柳'),('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张峻') +insert into tbl_computer values ('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'),('06',0,'688878'),('B01',0,'558558') +insert into tbl_record values (23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20),(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23),(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50),(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6),(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50),(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6),(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50),(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',300),(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23),(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) +select * from tbl_card +select * from tbl_computer +select * from tbl_record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select a.id,userName,b.id,beginTime,endTime,fee from tbl_card a inner join tbl_record c on a.id=c.cardID inner join tbl_computer b on c.ComputerID=b.id where userName='张军' order by fee DESC +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerID,count(beginTime) 上网次数,sum(fee) 消费总金额 from tbl_record group by ComputerID +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardid,sum(fee) 消费总金额 from tbl_record group by cardid +--4. 查询出从未消费过的上网卡的卡号和用户名 +select cardid,userName from tbl_card a left join tbl_record b on a.id=b.cardID where a.id not in(select cardID from tbl_record) +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card where passWord=userName +--6. 查询出使用次数最多的机器号和使用次数 +select b.id,count(ComputerID) 使用次数 from tbl_record a inner join tbl_computer b on a.ComputerID=b.id group by b.id +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select userName,ComputerID,fee from tbl_card a inner join tbl_record b on a.id=b.cardID where a.id like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardID,userName,ComputerID,beginTime,endTime,fee from tbl_record a inner join tbl_card b on a.cardID = b.id where DATEPART(dw,beginTime) in(1,7) +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardID,userName,ComputerID,beginTime,endTime,fee from tbl_record a inner join tbl_card b on a.cardID = b.id where DATEDIFF(hh,beginTime,endTime) > 12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardID,userName,ComputerID,beginTime,endTime,fee from tbl_record a inner join tbl_card b on a.cardID = b.id where fee not in(select top 3 fee from tbl_record order by fee DESC) \ No newline at end of file -- Gitee From f18d916f98d0b2e684b3b82417c717a653e49d29 Mon Sep 17 00:00:00 2001 From: EoL <1179233990@qq.com> Date: Wed, 31 Mar 2021 20:08:00 +0800 Subject: [PATCH 094/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/?= =?UTF-8?q?=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/1.bmp" | Bin 1110294 -> 0 bytes .../\344\275\234\344\270\232/2.bmp" | Bin 1116774 -> 0 bytes .../\344\275\234\344\270\232\344\270\200.txt" | 23 --------- .../\344\275\234\344\270\232\344\272\214.txt" | 47 ------------------ 4 files changed, 70 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/1.bmp" delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/2.bmp" delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.txt" delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.txt" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/1.bmp" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/1.bmp" deleted file mode 100644 index 65b6cf3101996a4c52218b7a5dad3fa9880001ad..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1110294 zcmeIbO|mRIu4Z>tBT!4GA!r0@KT}_G%HgS5R#pSh5Tp@E-%Z?uha!V;2A$5JyDvAs zND%zN$3+i0@`%bE?;FBy3G_@Ft@kcTtXG7q1@w6OMMgN$?uionBoSjbYzROA0uX?} zM*_+tD%>|5PLfz}df$+2dwh)pMuKHvHikd|0uX?}+X&qHzM;)JpGk`y&lBtPa7Faa zYQIPc?wm94mPgFT(h30xKmY;|=(%rLl8u?G_FP9Y&vd3_V)Vt~#+3JqjJq}#%SPo9 z&&qaf}S3AOHafKwwV-$|EY=H+*+)kyzJ@Tp!VQ z1OoyPfB*y@KtOp!h5LqY^5@@6p?C-XgKC7r8#-lfGQ6 z1p*L&00fjrC=lo&z?TIA5P$##ATUfoKi2R^NoRPT>jo}XwK&`uxAh{|M;s%=C#!9#P@G;aho&#JXPO z`iQ|0|JGWG4|_ z6$S(#009UD&DA7K%wBfP+BBRu3e;c|L@!NUm z4*>{300QqMpgf{-$NPq|XMARDUr%CH+*#qq=IIw1rAGVPxIGcSos<3$fB*y_@E!un zBPut&Z`d}SNu%{f_axT25o-;Ho_>*0YP1hS6digZ7DK2)00Izz00f+X@`%bE?;Bcz zCD1cz)H%43CsxIp8_wf?Wh5d^p?zx3s5aVPg;VDw;wAe@G@B96_*CqV}Q=sSV|0SG_<0uLadJfgyV!?*GliFLim^$~qXFdzT{2teRT1o-#pZ8vX` zSl5eOAMr_FF4h782tWV=$|DpA^bp|70s#m>00IygCZHc{_@ksVJkNCl7pqzvZj9S{ zk?SLlkzo`BAOHaf>`6esxnYlP9ed`K#i|yE8+$9(i(DUZj0~e7009UExm&M(U_bx@5P-k~2q=%J zaNqE)yhUPNFLHfE-w_N5KmY;|cmM(A5tYOH#+1K_J%;Nr)2;b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Or7KB`j{BLX5I0wN#+BJeE&|363w B#IpbZ diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.txt" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.txt" deleted file mode 100644 index 5a119a7..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.txt" +++ /dev/null @@ -1,23 +0,0 @@ -有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) - -题目: -1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 - -2.查询出每门课程的选修的学生的个数和学生考试的总分 - -3.查询出性别一样并且年龄一样的学生的信息 - -4.查询出学分一样的课程信息 - -5.查询出参加了考试的学生的学号,姓名,课程号和分数 - -6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 - -7.查询出没有参加考试的学生的学号和姓名 - -8.查询出是周六周天来报到的学生 - -9.查询出姓名中有字母a的学生的信息 - -10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 - diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.txt" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.txt" deleted file mode 100644 index 67f84f7..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.txt" +++ /dev/null @@ -1,47 +0,0 @@ -首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: - -表一为上网卡信息表(tbl_card) -id: 卡号,主键 -passWord:密码 -balance:卡上的余额 -userName:该上网卡所属的用户名 - -表2为网吧机器说明表(tbl_computer) -id:机器编号,主键 -onUse:该机器是否正在使用,0为未使用,1为正在使用 -note:该机器的说明 - - -表3为上网记录表(tbl_record): -id:记录编号,主键 -cardId:本次上网的卡号,外键 -ComputerId:本次上网记录所使用的机器号,外键 -beginTime:本次上网记录的开始时间 -endTime:本次上网记录的结束时间 -fee:本次上网的费用 - - -请完成以下题目: -1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 - -2. 查询出每台机器上的上网次数和消费的总金额 - -3. 查询出所有已经使用过的上网卡的消费总金额 - -4. 查询出从未消费过的上网卡的卡号和用户名 - -5. 将密码与用户名一样的上网卡信息查询出来 - -6. 查询出使用次数最多的机器号和使用次数 - -7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 - -8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - -9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - -10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - - - - -- Gitee From 8d2f9bf33fa5e1f6bccc5a2fd7ce06976b4c8cda Mon Sep 17 00:00:00 2001 From: lazy-scholar-cat <2220771866@qq.com> Date: Wed, 31 Mar 2021 20:12:38 +0800 Subject: [PATCH 095/195] cat --- .../SQLQuery3.29.1.sql" | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.1.sql" index 3dd191a..9fdab4c 100644 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.1.sql" +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery3.29.1.sql" @@ -1,7 +1,7 @@ create database System on ( - fileName='F:\homework\System.mdf', + fileName='D:\System.mdf', name='System', size=5MB, Maxsize=5MB, @@ -9,7 +9,7 @@ on ) log on ( - fileName='F:\homework\System_log.ldf', + fileName='D:\System_log.ldf', name='System_log', size=5MB, Maxsize=5MB, @@ -49,7 +49,7 @@ create table tbl_record insert into tbl_card values ('0023_ABC','555',98,'张军'), ('0025_bbd','abe',300,'朱俊'), -('0036_CCD','',100,'何柳'), +('0036_CCD','何柳',100,'何柳'), ('0045_YGR','0045_YGR',58,'验证'), ('0078_RJV','55885tg',600,'校庆'), ('0089_EDE','zhang',134,'张峻') @@ -93,9 +93,9 @@ select cardId --4. 查询出从未消费过的上网卡的卡号和用户名 select id,userName from tbl_card where id not in(select distinct cardId from tbl_record) - +select * from tbl_card --5. 将密码与用户名一样的上网卡信息查询出来 -select * from tbl_card where id=password +select * from tbl_card where passWord=userName --6. 查询出使用次数最多的机器号和使用次数 select top 1 C.id,count(ComputerId) from tbl_record R inner join tbl_computer C on C.id=ComputerId group by C.id order by count(ComputerId) DESC --7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 -- Gitee From db77cde880f6203f45418d9c7c8bf84b9d1635db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=84=E4=B8=BA?= <2608359793@qq.com> Date: Wed, 31 Mar 2021 20:14:57 +0800 Subject: [PATCH 096/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 107 ++++++++++++++++++ .../SQLQuery14.sql" | 92 +++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery14.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery1.sql" new file mode 100644 index 0000000..6e8e82e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery1.sql" @@ -0,0 +1,107 @@ +create database wb +on +( + name='wb', + filename='D:\wb.mdf' +) +log on +( + name='wb_log', + filename='D:\wb_log.ldf' +) + +use wb +go + +create table tbl_card +( + id varchar(30) primary key, + pasword varchar(30), + balance money, + userName varchar(50) +) + +create table tbl_computer +( + id varchar(30) primary key, + onUse varchar(2) check(onUse=0 or onUse=1), + note ntext +) + +create table tbl_record +( + id varchar(30) primary key, + cardId varchar(30) foreign key references tbl_card(id), + ComputerId varchar(30) foreign key references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee money +) + +insert into tbl_card(ID,pasword,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' + +insert into tbl_computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' + +insert into tbl_record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 + +select tbl_card.id 卡号,userName 用户名, tbl_computer.id 机器编号, beginTime 开始时间, endTime 结束时间, fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId = tbl_card.id +inner join tbl_computer on tbl_card.id = tbl_record.ComputerId where tbl_card.userName = '张军' + +--2. 查询出每台机器上的上网次数和消费的总金额 + +select ComputerId 机器,count(cardId) 次数,sum(fee) 金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 + +select cardId 网卡,sum(fee) 金额 from tbl_record group by cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 + +select tbl_card.id,userName from tbl_card +left join tbl_record on tbl_card.id=tbl_record.cardId +where fee is null group by userName,tbl_card.id + +--5. 将密码与用户名一样的上网卡信息查询出来 + +select * from tbl_card where userName = pasword + +--6. 查询出使用次数最多的机器号和使用次数 + +select top 1 max(ComputerId) 机器号,count(cardId)次数 from tbl_record group by ComputerId order by count(cardId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + +select tbl_card.id 卡号,tbl_card.userName 用户名,tbl_record.ComputerId 机器号,tbl_record.fee 消费金额 from tbl_card inner join tbl_record on tbl_card.id=tbl_record .cardId where tbl_card.id like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record order by fee desc \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery14.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery14.sql" new file mode 100644 index 0000000..e873c7c --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery14.sql" @@ -0,0 +1,92 @@ +create database Student +on +( +name='Student', +filename='D:\sql.mdl', +size=5mb, +maxsize=50mb, +filegrowth=10mb +) +log on +( +name='Student_log', +filename='D:\sql.ldf', +size=5mb, +maxsize=50mb, +filegrowth=10mb +) + +use Student +go + +create table stuInfo +( +stuID int primary key identity(1,1) not null, +stuName varchar(20) not null, +stuAge int not null, +stuSex char(2) not null, +time datetime +) + +create table courseInfo +( +courseID int primary key identity(1,1) not null, +courseName varchar(20) not null, +courseMarks int not null +) + +create table scoreInfo +( +scoreID int primary key identity(1,1) not null, +stuID int not null, +courseID int not null, +score int not null, +) + +insert into stuInfo(stuName,stuAge,stuSex) values ('Tom','19','1'),('Jack','20','0'), +('Rose','21','1'),('Lulu','19','1'),('Lili','21','0') +insert into stuInfo values('abc','20','1','2007-01-07 01:11:36.590') + +insert into courseInfo values ('JavaBase','4'),('HTML','2'),('JavaScript','2'),('SqlBase','2') + +insert into scoreInfo 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 stuID 学生,count(courseID) 数量,AVG(score) 平均分 from scoreInfo group by stuID + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + +select courseID 课程,count(stuID) 学生个数,sum(score) 总分 from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 + +select * from stuInfo where stuAge in (select stuAge from stuInfo group by stuAge,stuSex having count(stuAge)>1) + +--4.查询出学分一样的课程信息 + +select * from courseInfo where courseMarks in (select courseMarks from courseInfo group by courseMarks having count(courseMarks)>1) + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程,score 分数 from scoreInfo inner join stuInfo on scoreInfo.stuID=stuInfo.stuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +select stuID 学号,courseInfo.courseID 课程号,courseName 课程名,courseMarks 学分,score 分数 from courseInfo inner join scoreInfo on courseInfo.courseID=scoreInfo.courseID + +--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 stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select stuID 学号,count(courseID) 数量,AVG(score) 平均分 from scoreInfo group by stuID having count(courseID)>=2 and AVG(score)>70 \ No newline at end of file -- Gitee From eaff455232aa09dabb0f1e752d29e7927c675249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=96=E7=BA=B7?= <8332024+o2444091281@user.noreply.gitee.com> Date: Wed, 31 Mar 2021 20:23:02 +0800 Subject: [PATCH 097/195] =?UTF-8?q?=E9=BB=84=E9=94=9F=E5=AE=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 107 ++++++++++++++ .../SQLQuery2.sql" | 130 ++++++++++++++++++ 2 files changed, 237 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQLQuery1.sql" new file mode 100644 index 0000000..6060b29 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQLQuery1.sql" @@ -0,0 +1,107 @@ +use master +go +--学生信息表(stuInfo), +create database Mar29 +go +use Mar29 +go +create table stuInfo +( +stuID int primary key identity(1,1), +stuName nvarchar(20) not null, +stuAge int not null, +stuSex int check(stuSex=1 or stuSex=0) not null, +time datetime +) +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') +select * from stuInfo + +--课程信息表(courseInfo), +create table courseInfo +( +courseID int primary key identity(1,1), +courseName nvarchar(20) not null, +courseMarks int not null +) +insert into courseInfo(courseName,courseMarks) +values('JavaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) +select * from courseInfo +--分数信息表(scoreInfo) +create table scoreInfo +( +scoreID int primary key identity(1,1), +stuID int not null, +courseID int not null, +score int not null +) +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,15), +(4,1,95), +(4,2,75), +(4,3,90), +(4,4,45) +select * from scoreInfo +--题目: +--select * from stuInfo +--select * from courseInfo +--select * from scoreInfo +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID 学生,count(courseID)课程的数量,avg(score)平均分 +from scoreInfo group by stuID + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseID 课程, count(courseID)选修个数, sum(score)总分 +from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A, stuInfo B +where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stuID!=B.stuID + +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks AND A.courseID!=B.courseID + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select SC.stuID 学号,stuName 姓名,courseID 课程号,score +from scoreInfo SC +left join stuInfo ST on SC.stuID=ST.stuID +group by SC.stuID,stuName,courseID,score + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select SC.stuID 学号, SC.courseID 课程号,CO.courseName 课程名,courseMarks 学分,SC.score 分数 +from scoreInfo SC +left join courseInfo CO on SC.courseID=CO.courseID + +--7.查询出没有参加考试的学生的学号和姓名 +select ST.stuID 学号,ST.stuName 姓名 from stuInfo ST +left join scoreInfo SC on ST.stuID=SC.stuID +where score is null + +--8.查询出是周六周天来报到的学生 +--??? + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号 +--和考试平均分以及选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo +group by stuID +having avg(score)>=70 and count(courseID)>=2 + +--drop Database \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQLQuery2.sql" new file mode 100644 index 0000000..0cb6ff0 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQLQuery2.sql" @@ -0,0 +1,130 @@ +USE master +go +create database Mar30 +go +use Mar30 +go + +--表一为上网卡信息表(tbl_card) +create table card +( +--id: 卡号,主键 +id varchar(30) primary key , +----passWord:密码 +passWord varchar(30), +--balance:卡上的余额 +balance money, +--userName:该上网卡所属的用户名 +userName nvarchar(20) +) + +--表2为网吧机器说明表(tbl_computer) +create table computer +( +--id:机器编号,主键 +id varchar(30) primary key, +--onUse:该机器是否正在使用,0为未使用,1为正在使用 +onUse int check(onUse=0 or onUse=1), +--note:该机器的说明 +note ntext +) + +--表3为上网记录表(tbl_record): +create table record +( +--id:记录编号,主键 +id varchar(30) primary key, +--cardId:本次上网的卡号,外键 +cardId varchar(30) foreign key references card(id), +--ComputerId:本次上网记录所使用的机器号,外键 +ComputerId varchar(30) foreign key references computer(id), +--beginTime:本次上网记录的开始时间 +beginTime datetime, +--endTime:本次上网记录的结束时间 +endTime datetime, +--fee:本次上网的费用 +fee money +) + + --上网卡信息表 +insert into card(ID,password,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' +--网吧机器说明表 +insert into computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' +--上网记录表 +insert into record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from card --上网卡信息表 +select * from computer --网吧机器说明表 +select * from record --上网记录表 + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select c.id 卡号, c.userName 用户名 ,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from card c inner join record r on c.id=r.cardId +where userName='张军' +order by fee desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 +from record +group by cardId,ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId,sum(record.fee) 总金额 +from record +group by cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select c.id,userName +from card c +left join record r on c.id=r.cardId +where fee is null group by userName,c.id + +--5. 将密码与用户名一样的上网卡信息查询出来 +select A.* from card A,card B +where A.password=B.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId)使用次数 +from record +group by ComputerId order By count(ComputerId) +desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 +from record r +inner join card c on r.cardId=c.id +where r.cardId like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +--??? +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +--??? + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from record +order by fee +desc \ No newline at end of file -- Gitee From e4561aa70dc86a6bde2a76de2756d5f8dadfd633 Mon Sep 17 00:00:00 2001 From: cowlong <1220590642@qq.com> Date: Wed, 31 Mar 2021 20:28:34 +0800 Subject: [PATCH 098/195] =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery2.sql" | 88 +++++++++++++++++++ .../SQLQuery3.sql" | 76 ++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery2.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery3.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery2.sql" new file mode 100644 index 0000000..8dc85f2 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery2.sql" @@ -0,0 +1,88 @@ +create database wbjfk +on +( + name ='wbjfk', + size=10, + filename='D:\wbjfk.mdf', + maxsize=100, + filegrowth=10 +) +log on +( + name ='wbjfk_log', + size=10, + filename='D:\wbjfk_log.ldf', + maxsize=100, + filegrowth=10 +) +go +use wbjfk +go +create table tbl_card +( + id nvarchar(10) primary key, + passWord nvarchar(18), + balance int, + userName nvarchar(20) +) +create table tbl_computer +( + id nvarchar(10) primary key, + onUse int, + note nvarchar(200) +) +create table tbl_record +( + id nvarchar(10) primary key, + cardid nvarchar(10) foreign key references tbl_card(id), + Computerid nvarchar(10) foreign key references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee int +) +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885lg',600,'校庆'),('0089_EDE','zhang',134,'张峻') +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'),('06',0,'688878'),('B01',0,'558558') +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',30), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号 +--,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select cardid,userName,Computerid,beginTime,endTime from tbl_card a left join tbl_record d on a.id = d.cardid + where userName = '张军' order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select b.id,count(Computerid),sum(fee) from tbl_record a left join tbl_computer b on a.Computerid = b.id group by b.id +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardid,sum(fee) from tbl_record group by cardid +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id,userName from tbl_card where id not in (select distinct cardid from tbl_record ) +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card where id=passWord +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId,count(ComputerId) from tbl_record group by ComputerId order by count(ComputerId) desc +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 +from tbl_record inner join tbl_card on tbl_record.cardId=tbl_card.id where tbl_record.cardId like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardid,userName,Computerid,beginTime,endTime from tbl_card a left join tbl_record d on a.id = d.cardid +where datepart(weekday,beginTime)=6 or datepart(weekday,beginTime)=7 +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t +inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId +where datediff(hour,beginTime,endTime)>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t +inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId +where fee not in(select top 3 fee from tbl_record order by fee DESC) \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery3.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery3.sql" new file mode 100644 index 0000000..a5f22cd --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery3.sql" @@ -0,0 +1,76 @@ +create database st +on +( + name ='st', + size=10, + filename='D:\st.mdf', + maxsize=100, + filegrowth=10 +) +log on +( + name ='st_log', + size=10, + filename='D:\st_log.ldf', + maxsize=100, + filegrowth=10 +) +go +use st +go +create table stuInfo +( + stuID int primary key identity, + stuName nvarchar(8), + stuAge int, + stuSex nchar(2), + time datetime +) +create table courseInfo +( + courseID int primary key identity, + courseName nvarchar(12), + courseMarks int +) +create table scoreInfo +( + scoreID int primary key identity, + stuID int, + courseID int, + score int +) +insert into stuInfo(stuName,stuAge,stuSex,time) values ('Tom',19,'男',''),('Jack',20,'女',''),('Rose',21,'男',''), +('Lulu',19,'男',''),('Lili',21,'女',''),('abc',20,'男','2007-01-07 01:11:36.590') +insert into courseInfo values('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) +insert into scoreInfo 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) + +select * from stuInfo +select * from courseInfo +select * from scoreInfo + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuName,count(c.stuID) 选课数量,avg(score) 所选课考试的平均分 from stuInfo t +inner join courseInfo x on t.stuID=x.courseID left join scoreInfo c on t.stuID=c.stuID group by stuName +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName,count(StuName) 学生的个数,sum(score) 考试的总分 from scoreInfo s +inner join stuInfo x on s.StuID=x.StuID inner join courseInfo a on s.courseID=a.courseID group by courseName +--3.查询出性别一样并且年龄一样的学生的信息 +select s.* from stuInfo s,stuInfo x where s.stuSex=x.stuSex and s.stuAge=x.stuAge and s.stuID!=x.stuID +--4.查询出学分一样的课程信息 +select distinct t.* from courseInfo t,courseInfo x where t.courseMarks=x.courseMarks and t.courseID!=x.courseID +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select s.stuID,stuName,x.courseID,score from stuInfo s +left join courseInfo x on s.stuID = x.courseID +left join scoreInfo o on o.scoreID = s.stuID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select t.stuID 学号, t.courseID 课程号,x.courseName 课程名,courseMarks 学分,t.score 分数 from scoreInfo t +left join courseInfo x on t.courseID=x.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select t.stuID 学号,t.stuName 姓名 from stuInfo t left join scoreInfo x on t.stuID=x.stuID where score is null +--8.查询出是周六周天来报到的学生 +select t.stuID 学号,t.stuName 姓名 from stuInfo t left join scoreInfo x on t.stuID=x.stuID where score is null +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID having avg(score)>=70 and count(courseID)>=2 -- Gitee From b5f3681b66d89d8b6ab538203ef2089af6ed4b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E7=91=BE=E8=A8=80?= <2220660532@qq.com> Date: Wed, 31 Mar 2021 20:29:19 +0800 Subject: [PATCH 099/195] =?UTF-8?q?=E6=AE=B5=E5=97=A3=E5=87=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 94 +++++++++++++++++++ .../SQLQuery2.sql" | 81 ++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" new file mode 100644 index 0000000..ef9ca98 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" @@ -0,0 +1,94 @@ +create database Students +go + +use Students +go + +--学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +create table stuInfo +( + stuID int primary key identity, + stuName nvarchar(20), + stuAge int, + stuSex int check(stuSex=1 or stuSex=0), + time datetime +) + +create table courseInfo +( + courseID int primary key identity, + courseNAME nvarchar(20), + couresMarks int +) + +create table scoreInfo +( + scoerID int primary key identity, + stuiD int, + courseID int, + score int +) + +insert into stuInfo values + ('Tom',19,1,null), + ('Jack',20,0,null), + ('Rose',21,1,null), + ('Lulu',19,1,null), + ('Lili',21,0,null), + ('abc',20,1,'2001-01-07 01:11:36.590') +select * from stuInfo + +insert into courseInfo values + ('JavaBase',4), + ('HTML',2), + ('JavaScript',2), + ('SqlBase',2) +select * from courseInfo + +insert into scoreInfo 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) +select * from scoreInfo +select * from stuInfo +select * from courseInfo + + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 + select stuName , count(courseInfo.couresMarks) 选修的课程的数量, avg(score) 所选修的课程的考试的平均分 from stuInfo + inner join courseInfo on stuInfo.stuID=courseInfo.courseID + inner join scoreInfo on courseInfo.courseID=scoreInfo.stuID group by stuName +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + select courseInfo.courseNAME,count(stuiD)数量,sum(scoreInfo.score)总分 from courseInfo + inner join scoreInfo on courseInfo.courseid=scoreInfo.courseid group by courseInfo.courseNAME +--3.查询出性别一样并且年龄一样的学生的信息 + select distinct A.* from stuInfo A,stuInfo B where A.stuAge=B.stuAge and A.stuSex=B.stuSex and A.stuName!=B.stuName +--4.查询出学分一样的课程信息 + select distinct A. * from courseInfo A,courseInfo B where A.couresMarks=B.couresMarks and A.courseID!=B.courseID +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + select stuInfo.stuID,stuInfo.stuName,courseInfo.courseID,scoreInfo.score from scoreInfo + inner join stuInfo on scoreInfo.stuiD=stuInfo.stuID + inner join courseInfo on scoreInfo.courseID=courseInfo.courseID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + select stuInfo.stuID,courseInfo.courseID,courseInfo.courseNAME,courseInfo.couresMarks,scoreInfo.score from scoreInfo + inner join stuInfo on scoreInfo.stuiD=stuInfo.stuID + inner join courseInfo on scoreInfo.courseID=courseInfo.courseID +--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 stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + select stuid 学号,avg(score)平均分,count(*)选修课程的数量 from scoreInfo group by stuiD having avg(score)>=70 and count(*)>=2 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" new file mode 100644 index 0000000..4a7e650 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" @@ -0,0 +1,81 @@ +use master +go +create database py2 +go +use py2 +go +create table card +( + id varchar(30) primary key, + pasword varchar(30), + balance money, + userName varchar(50) +) +create table computer +( + id varchar(30) primary key, + onUse varchar(2) check(onUse=0 or onUse=1), + note ntext +) +create table record +( + id varchar(30) primary key, + cardId varchar(30) foreign key references card(id), + ComputerId varchar(30) foreign key references computer(id), + beginTime datetime, + endTime datetime, + fee money +) + --上网卡信息表 +insert into card(ID,pasword,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' +--网吧机器说明表 +insert into computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' +--上网记录表 +insert into record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from card +select * from computer +select * from record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select b.id 卡号,b.userName 用户名,c.id 机器编号, a.beginTime 开始时间,a.endTime 结束时间,a.fee 消费金额 from record a inner join card b on a.cardId=b.id +inner join computer c on c.id=a.ComputerId where b.userName='张军' order by a.fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select b.id 机器,count(*)上网次数,sum(c.fee)消费的总金额 from computer b left join record c on b.id=c.ComputerId group by b.id,c.fee order by c.fee desc +--3. 查询出所有已经使用过的上网卡的消费总金额 +select b.id, sum(b.fee)消费总金额 from card a inner join record b on a.id=b.cardId group by b.id +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id,userName from card where id in (select id from record group by id ) +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from card where userName = pasword +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 max(ComputerId) 机器号,count(*)次数 from record group by ComputerId order by count(*) desc +----7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.fee 消费金额 from card a inner join record b on a.id=b.cardId where a.id like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.beginTime 开始时间,b.endTime 结束时间 ,b.fee 消费金额 from card a inner join record b on a.id=b.cardId where b.beginTime =CONVERT(datetime,b.beginTime) group by b.beginTime,a.id,a.userName,b.ComputerId,b.beginTime,b.endTime,b.fee +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.beginTime 开始时间,b.endTime 结束时间,b.fee 消费金额 from card a inner join record b on a.id=b.cardId where b.beginTime-b.endTime>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.beginTime 开始时间,b.endTime 结束时间,b.fee 消费金额 from card a inner join record b on a.id=b.cardId order by b.fee desc \ No newline at end of file -- Gitee From 3b291824ed19acf0074f4fa824dc2a1e0ab2dd99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=BC=E7=9D=80=E5=A5=B6=E7=93=B6=E5=8E=BB=E6=89=93?= =?UTF-8?q?=E8=99=8E?= <1348328020@qq.com> Date: Wed, 31 Mar 2021 20:34:31 +0800 Subject: [PATCH 100/195] 2021-3-31 --- .../\344\275\234\344\270\2321.sql" | 107 ++++++++++++++++++ .../\344\275\234\344\270\2322.sql" | 92 +++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\344\275\234\344\270\2321.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\344\275\234\344\270\2322.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\344\275\234\344\270\2321.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..b603215 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\344\275\234\344\270\2321.sql" @@ -0,0 +1,107 @@ +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +create database Student +go +use Student +go + +create table stuInfo +( + stuID int identity(1,1) primary key, + stuName varchar(20) not null, + stuAge int, + stuSex varchar(1) default(1) check(stuSex in('1','0')), + time date +) +insert into stuInfo(stuName,stuAge,stuSex) values +('Tom',19,'1'), +('Jack',20,'0'), +('Rose',21,'1'), +('Lulu',19,'1'), +('Lili',21,'0') +insert into stuInfo values ('abc',20,1,'2001-01-07 01:11:36.590') + + +create table courseInfo +( + courseID int identity(1,1) primary key, + courseName varchar(20) not null, + courseMarks int +) +insert into courseInfo values ('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) + +create table scoreInfo +( + scoreID int identity(1,1) primary key, + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int +) +insert into scoreInfo 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) + +select * from stuInfo +select * from courseInfo +select * from scoreInfo +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 + +select StuID 学生编号,count(courseID) 所选修课程数量,avg(score) 平均分 +from scoreInfo group by StuID + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + +select courseID 课程编号,count(StuID) 课程所选修学生个数,sum(score) 总分 +from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 + +select A.stuID,A.stuName,A.stuAge,A.stuSex,A.time from StuInfo A,StuInfo B +where A.stuSex=B.stuSex and A.stuAge=B.stuAge and A.stuID != b.stuID + +--4.查询出学分一样的课程信息 + +select difference(A.courseID,A.courseName,A.courseMarks from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks and A.courseID != b.courseID + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +select A.stuID 学号,A.stuName 姓名,B.courseID 课程编号,B.score 分数 +from stuInfo A inner join scoreInfo B on A.stuID=B.stuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +select A.stuID 学号,B.courseID 课程编号,C.courseName 课程名,C.courseMarks 课程学分,B.score 分数 +from stuInfo A inner join scoreInfo B on A.stuID=B.stuID +inner join courseInfo C on C.courseID=B.courseID + +--7.查询出没有参加考试的学生的学号和姓名 + +select A.stuID 学号,A.stuName 姓名 +from stuInfo A left join scoreInfo B on A.stuID=B.stuID +where score is null + +--8.查询出是周六周天来报到的学生 + + select * from stuInfo where time= + (select time from stuInfo + group by time having datename(dw,time)='星期六' or datename(dw,time)='星期日') + +--9.查询出姓名中有字母a的学生的信息 + +select * from stuInfo where stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select A.StuID 学号,sum(score) 平均分,count(courseID) 选修数量 +from stuInfo A join scoreInfo B on A.stuID=B.stuID +group by A.StuID having count(courseID)>2 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\344\275\234\344\270\2322.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..23c8416 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/\344\275\234\344\270\2322.sql" @@ -0,0 +1,92 @@ +create database tbl +go +use tbl +go + +create table tbl_card +( + id varchar(20) primary key, + passWord varchar(12), + balance money, + userName varchar(10) +) +insert into tbl_card values +('0023_ABC','555',99,'张军'), +('0025_bbd','abc',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'验证'), +('0078_RJV','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张俊') + +create table tbl_computer +( + id varchar(3) primary key, + onUse char(1) check(onUse in('1','0')), + note text +) + +insert into tbl_computer values +('02',0,'25555'), +('03',1,'55555'), +('04',0,'66666'), +('05',1,'888888'), +('06',0,'688878'), +('B01',0,'558558') + +create table tbl_record +( + id varchar(20) primary key , + cardId varchar(20) references tbl_card(id), + ComputerId varchar(3) references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee money +) +insert into tbl_record values +('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +('47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), +('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select A.id 卡号,A.userName 用户名,B.beginTime 开始时间,B.endTime 结束时间,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId +where userName like '张军' order by fee DESC +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器编号,count(ComputerId) 上网次数,sum(fee) 消费总金额 from tbl_record group by ComputerId +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId 使用过卡号,sum(fee) 消费总金额 +from tbl_record group by cardId having count(cardId)>0 +--4. 查询出从未消费过的上网卡的卡号和用户名 +select A.id 卡号,A.userName 用户名 +from tbl_card A left join tbl_record B on B.cardId=A.id +where fee is null +--5. 将密码与用户名一样的上网卡信息查询出来 + +select * from tbl_card where userName=passWord + +select A.id,A.passWord,A.balance,A.userName from tbl_card A,tbl_card B +where A.userName=B.passWord +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId) 使用次数 from tbl_record +group by ComputerId order by count(ComputerId) DESC +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select A.userName 用户名,B.ComputerId 机器号,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId where A.id like '%ABC' +--8. 查询出是周六、周天上网的c记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select B.cardId 卡号,A.userName 用户名,B.ComputerId 机器号,B.beginTime 开始时间,B.endTime 结束时间,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId where datename(dw,B.beginTime)='星期六' or datename(dw,B.beginTime)='星期日' + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select B.cardId 卡号,A.userName 用户名,B.ComputerId 机器号,B.beginTime 开始时间,B.endTime 结束时间,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId where datediff(HOUR,B.beginTime,B.endTime)>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 B.cardId 卡号,A.userName 用户名,B.ComputerId 机器号,B.beginTime 开始时间,B.endTime 结束时间,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId order by fee DESCS \ No newline at end of file -- Gitee From 847b1cf5c50bd787d628256d894a801d40b726c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E9=82=B5=E6=98=A0?= <2934277968@qq.com> Date: Wed, 31 Mar 2021 20:39:13 +0800 Subject: [PATCH 101/195] 1 --- .../zuoye1.sql" | 88 +++++++++++++++++++ .../zuoye2.sql" | 82 +++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye1.sql" new file mode 100644 index 0000000..c301d1a --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye1.sql" @@ -0,0 +1,88 @@ +use master +go +create database aa +go +use aa +go +create table stuInfo +( +stuID int primary key identity, +stuName nvarchar(10), +stuAge int, +stuSex int check (stuSex in (1,0)), +time datetime null +) +go +create table courseInfo +( +courseID int primary key identity, +courseName nvarchar(20), +coureMarks int +) +go +create table scoreInfo +( +scoreID int primary key identity, +stuID int, +courseID int, +score int +) +select * from stuInfo +select * from courseInfo +select * from scoreInfo +insert into stuInfo (stuName,stuAge,stuSex) values ('Tom',19,1), +('Jack',20,0), +('Rose',21,1), +('Lulu',19,1), +('Lili',21,0) +insert into stuInfo (stuName,stuAge,stuSex,time) values +('abc',20,1,'2007-01-07 01:11:36.590') +insert into courseInfo (courseName,coureMarks) values ('JacaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) +insert into scoreInfo (stuID,courseID,score) values (1,1,80), +(1,1,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) +select * from stuInfo +select * from courseInfo +select * from scoreInfo + +--1.查询出 每个学生 所选修的 课程的数量 和 所选修的课程的 考试的平均分 +select s1.stuID,s1.stuName,count(coureMarks) 课程的数量,avg(score) 平均分 from stuInfo +s1 inner join courseInfo s2 on s1.stuID=s2.courseID inner join scoreInfo s3 on s1.stuID=s3.stuID group by s1.stuID,s1.stuName +--2.查询出 每门课程的选修的学生的个数和学生考试的总分 +select s2.courseName,count(s2.coureMarks) 个数,sum(score) 总分 from stuInfo +s1 inner join courseInfo s2 on s1.stuID=s2.courseID inner join scoreInfo s3 on s1.stuID=s3.stuID group by s2.courseName +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A,stuInfo B where A.stuSex=B.stuSex and A.stuAge=B.stuAge and A.stuID != B.stuID +--4.查询出学分一样的课程信息 +select distinct B.* from courseInfo A, courseInfo B where A.coureMarks= B.coureMarks and A.coureMarks != B.coureMarks +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select s1.stuID,s1.stuName,s3.courseID 课程号,s3.score 分数 from stuInfo +s1 inner join courseInfo s2 on s1.stuID=s2.courseID inner join scoreInfo s3 on s1.stuID=s3.stuID group by s1.stuID,s1.stuName,s3.courseID,s3.score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select s1.stuID,s1.stuName,s2.courseName,s3.courseID 课程号,s3.score 分数 from stuInfo +s1 inner join courseInfo s2 on s1.stuID=s2.courseID inner join scoreInfo s3 on s1.stuID=s3.stuID group by s1.stuID,s1.stuName,s3.courseID,s3.score,s2.courseName +--7.查询出没有参加考试的学生的学号和姓名 +select s1.stuID,s1.stuName from stuInfo s1 left join scoreInfo s2 on s1.stuID=s2.stuID group by s1.stuID,s1.stuName +except +select s1.stuID,s1.stuName from stuInfo s1 inner join scoreInfo s2 on s1.stuID=s2.stuID group by s1.stuID,s1.stuName +--8.查询出是周六周天来报到的学生 +select * from stuInfo +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select s1.stuID,s1.stuName,count(s3.courseID) 课程的数量,avg(score) 平均分 from stuInfo +s1 inner join courseInfo s2 on s1.stuID=s2.courseID inner join scoreInfo s3 on s1.stuID=s3.stuID group by s1.stuID,s1.stuName +having count(s3.courseID)>2 and avg(score)>70 + + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye2.sql" new file mode 100644 index 0000000..17c84c4 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/zuoye2.sql" @@ -0,0 +1,82 @@ +use master +go +create database bb +go +use bb +go +create table tbl_card +( + ID varchar(20) primary key , + passWord nvarchar(10), + banlance int, + userName nvarchar(10), +) +go +create table tbl_computer +( + Id varchar(5) primary key , + onUse int , + note text, +) +go +create table tbl_record +( + ID int primary key , + cardId varchar(20) references tbl_card(ID), + ComputerId varchar(5) references tbl_computer(Id), + beginTime datetime, + endTime datetime, + fee int, +) +go +select * from tbl_computer +select * from tbl_card +select * from tbl_record +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abe',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张峻') +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'), +('06',0,'688878'),('B01',0,'558558') +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) +select * from tbl_computer +select * from tbl_card +select * from tbl_record +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select tbl_card.ID 卡号,tbl_card.userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID where tbl_card.userName='张军' order by fee DESC +--2. 查询出每台机器上的上网次数和消费的总金额 +select tbl_computer.Id,count(*)上网的次数,sum(fee)总金额 from tbl_record +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id group by tbl_computer.Id +--3. 查询出所有已经使用过的上网卡的消费总金额 +select tbl_record.cardId,sum(fee)总金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID group by tbl_record.cardId +--4. 查询出从未消费过的上网卡的卡号和用户名 +select ID 卡号,userName 用户名 from tbl_card where ID not in(select distinct cardId from tbl_record) +--5. 将密码与用户名一样的上网卡信息查询出来 +select A.* from tbl_card A ,tbl_card B where A.userName=B.passWord +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 tbl_record.ComputerId,count(*) 使用次数 from tbl_record +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id group by tbl_record.ComputerId order by count(*) DESC +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_card.ID 卡号,tbl_card.userName 用户名,tbl_computer.Id 上网的机器号,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id where tbl_card.ID like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.ID 上网的卡号,tbl_card.userName 用户名,tbl_computer.Id 机器号,beginTime 开始时间,endTime 结束时间,DATEDIFF(hh,beginTime,endTime) 相差的时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id where DATEDIFF(hh,beginTime,endTime)>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 30 percent tbl_card.ID 上网的卡号,tbl_card.userName 用户名,tbl_computer.Id 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id order by fee DESC \ No newline at end of file -- Gitee From fa8e81053e10983f2b48ae18370b9ee5491ac5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E7=A8=8B=E7=A5=A5?= <842143662@qq.com> Date: Wed, 31 Mar 2021 20:39:24 +0800 Subject: [PATCH 102/195] =?UTF-8?q?=E4=B8=87=E7=A8=8B=E7=A5=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" | 1 + .../\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" new file mode 100644 index 0000000..111bddd --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" @@ -0,0 +1 @@ +use master go create database ClassInfo on ( name= 'ClassInfo', filename='D:\SQL代码\ClassInfo.mdf', size=5mb, maxsize=500mb, filegrowth=10% ) log on ( name= 'ClassInfo_ldf', filename='D:\SQL代码\ClassInfo_ldf.ldf', size=5mb, maxsize=500mb, filegrowth=10% ) use ClassInfo go --学生信息表(stuInfo) create table stuInfo ( stuID int primary key identity(1,1), stuName nvarchar(20) not null, stuAge int not null, stuSex int check(stuSex=1 or stuSex=0) not null, time datetime ) 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') select * from stuInfo --课程信息表(courseInfo) create table courseInfo ( courseID int primary key identity(1,1), courseName nvarchar(20) not null, courseMarks int not null ) insert into courseInfo(courseName,courseMarks) values('JavaBase',4), ('HTML',2), ('JavaScript',2), ('SqlBase',2) select * from courseInfo --分数信息表(scoreInfo) create table scoreInfo ( scoreID int primary key identity(1,1), stuID int not null, courseID int not null, score int not null ) 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,15), (4,1,95), (4,2,75), (4,3,90), (4,4,45) select * from scoreInfo --题目: --1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 select stuName , count(courseID)课程的数量,avg(score)平均分 from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID group by stuName --2.查询出每门课程的选修的学生的个数和学生考试的总分 select courseName,count(StuID)学生的个数 , sum(score)考试的总分 from scoreInfo inner join courseInfo on scoreInfo.courseID=courseInfo.courseID group by courseName --3.查询出性别一样并且年龄一样的学生的信息 select * from StuInfo where stuAge in(select stuAge from StuInfo group by stuAge,stuSex having COUNT(stuAge)>1 and COUNT(stuSex)>1) --4.查询出学分一样的课程信息 select * from courseInfo where courseMarks in(select courseMarks from courseInfo group by courseMarks having COUNT(courseMarks)>1) --5.查询出参加了考试的学生的学号,姓名,课程号和分数 select stuInfo.stuID,stuName,courseInfo.courseID,score from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID inner join courseInfo on courseInfo.courseID=scoreInfo.courseID --6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 select stuInfo.stuID,stuName,courseInfo.courseID,courseName,courseMarks,score from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID inner join courseInfo on courseInfo.courseID=scoreInfo.courseID --7.查询出没有参加考试的学生的学号和姓名 select stuInfo.stuID,stuName,courseName from stuInfo left join courseInfo on stuInfo.stuID=courseInfo.courseID where courseName is null --8.查询出是周六周天来报到的学生 --9.查询出姓名中有字母a的学生的信息 select * from stuInfo where stuName like '%a%' --10.查询出 选修了2门课程以上的 并且考试平均分在70以上 的学生的 学号和 考试平均分 以及 选修课程的数量 select * from stuInfo,scoreInfo select stuInfo.stuID,avg(score),count(courseInfo.courseID) from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID inner join courseInfo on courseInfo.courseID=scoreInfo.courseID group by stuInfo.stuID having count(courseInfo.courseID)>2 and avg(score)>70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" new file mode 100644 index 0000000..35dd7d6 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery2.sql" @@ -0,0 +1,3 @@ +use master go --首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: create database charge on ( name='charge', filename='D:\SQL代码\charge.mdf', size=5mb, maxsize=500mb, filegrowth=10% ) log on ( name='charge_ldf', filename='D:\SQL代码\charge_ldf.ldf', size=5mb, maxsize=500mb, filegrowth=10% ) use charge go --表一为上网卡信息表(tbl_card) --id: 卡号,主键 --passWord:密码 --balance:卡上的余额 --userName:该上网卡所属的用户名 create table tbl_card ( ID nvarchar(10) primary key not null, PassWord nvarchar(10) not null, Balance nvarchar(10) not null, UserName nvarchar(10) not null ) insert into tbl_card values ('0023_ABC','555','98','张军'), ('0025_bbd','abe','300','朱俊'), ('0036_CDD','何柳','100','何柳'), ('0045_YGR','0045_YGR','58','证验'), ('0078_RJV','55885fg','600','校庆'), ('0089_EDE','zhang','134','张骏') --表2为网吧机器说明表(tbl_computer) --id:机器编号,主键 --onUse:该机器是否正在使用,0为未使用,1为正在使用 --note:该机器的说明 create table tbl_computer ( ID nvarchar(10) not null primary key, OnUse int check(OnUse=1 or OnUse=0) not null, Note int not null ) insert into tbl_computer values ('02',0,25555), ('03',1,25555), ('04',0,66666), ('05',1,88888), ('06',0,688878), ('B01',0,558558) --表3为上网记录表(tbl_record): --id:记录编号,主键 --cardId:本次上网的卡号,外键 --ComputerId:本次上网记录所使用的机器号,外键 --beginTime:本次上网记录的开始时间 --endTime:本次上网记录的结束时间 --fee:本次上网的费用 create table tbl_record ( ID nvarchar(10) primary key not null, CardID nvarchar(10) not null foreign key references tbl_card(ID), ComputerID nvarchar(10) not null foreign key (ComputerID) references tbl_computer(ID), BeignTime datetime not null, EndTime datetime not null, Fee int not null ) insert into tbl_record values (23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), (34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), (45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), (46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), (47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',60), (48,'0023_ABC','03','2007-01-06 15:26:00','2006-01-06 22:55:00',6), (55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), (64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), (65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), (98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) --请完成以下题目: select * from tbl_record --上网记录表(tbl_record) select* from tbl_computer --网吧机器说明表(tbl_computer) select * from tbl_card --上网卡信息表(tbl_card) --1. 查询出用户名为'张军'的上网卡的上网记录, --要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额, --并按消费金额降序排列 select tbl_card.ID 显示卡号,UserName 用户名,tbl_computer.ID 机器编号,BeignTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.CardID=tbl_card.ID +inner join tbl_computer on tbl_computer.Id=tbl_record.ComputerId where UserName='张军' order by fee DESC --2. 查询出每台机器上的上网次数和消费的总金额 select ComputerID, count(*)上网次数 ,sum(Fee)消费的总金额 from tbl_record group by ComputerID --3. 查询出所有已经使用过的上网卡的消费总金额 select tbl_card.ID,sum(Fee) from tbl_record inner join tbl_card on tbl_record.CardID=tbl_card.ID group by tbl_card.ID --4. 查询出从未消费过的上网卡的卡号和用户名 select tbl_card.ID,UserName from tbl_record right join tbl_card on tbl_record.CardID=tbl_card.ID where Fee is null group by tbl_card.ID,CardID,UserName,Fee --5. 将密码与用户名一样的上网卡信息查询出来 --select * from tbl_card A --INNER join tbl_card B on A.PassWord = B.PassWord where A.PassWord = A .UserName select * from tbl_card where PassWord=UserName --6. 查询出使用次数最多的机器号和使用次数 select top 1 count(*) 使用次数,ComputerID 机器号 from tbl_record group by ComputerID order by count(*) DESC select ComputerID , count(*) from tbl_record group by ComputerID having count(*)=5 --7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 select CardID 卡号,UserName 用户名,ComputerID 上网的机器号,Fee 消费金额 from tbl_record inner join tbl_card on tbl_record.CardID=tbl_card.ID where CardID like '%ABC' --8. 查询出是周六、周天上网的记录, --要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 --9. 查询成一次上网时间超过12小时的的上网记录, --要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 select CardId , userName , ComputerID,BeignTime , EndTime ,Fee from tbl_record inner join tbl_card on tbl_record.CardID=tbl_card.ID where (EndTime-BeignTime)>=12 --10. 查询消费金额排列前三名(最高)的上网记录, --要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 select Fee , CardID,UserName , ComputerID,BeignTime , EndTime from tbl_record inner join tbl_card on tbl_record.CardID=tbl_card.ID where Fee not in (select top 3 fee from tbl_record order by fee DESC) \ No newline at end of file -- Gitee From 1810f850ac29259c73d97950970114a2fff746a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=9D=B0=E7=83=A8?= Date: Wed, 31 Mar 2021 20:41:17 +0800 Subject: [PATCH 103/195] =?UTF-8?q?=E9=BB=84=E6=9D=B0=E7=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oooo...one.sql" | 96 +++++++++++++++++++ .../tttt...two.sql" | 79 +++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/oooo...one.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/tttt...two.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/oooo...one.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/oooo...one.sql" new file mode 100644 index 0000000..60f041c --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/oooo...one.sql" @@ -0,0 +1,96 @@ +create database Students +go + +use Students +go + +--学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +create table stuInfo +( + stuID int primary key identity, + stuName nvarchar(20), + stuAge int, + stuSex int check(stuSex=1 or stuSex=0), + time datetime +) + +create table courseInfo +( + courseID int primary key identity, + courseNAME nvarchar(20), + couresMarks int +) + +create table scoreInfo +( + scoerID int primary key identity, + stuiD int, + courseID int, + score int +) + +insert into stuInfo values + ('Tom',19,1,null), + ('Jack',20,0,null), + ('Rose',21,1,null), + ('Lulu',19,1,null), + ('Lili',21,0,null), + ('abc',20,1,'2001-01-07 01:11:36.590') + + +insert into courseInfo values + ('JavaBase',4), + ('HTML',2), + ('JavaScript',2), + ('SqlBase',2) + + +insert into scoreInfo 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) +select * from scoreInfo +select * from stuInfo +select * from courseInfo + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 + select stuName 学生名字 , count(courseInfo.couresMarks) 选修的课程的数量, avg(score) 所选修的课程的考试的平均分 from stuInfo + inner join courseInfo on stuInfo.stuID=courseInfo.courseID + inner join scoreInfo on courseInfo.courseID=scoreInfo.stuID group by stuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + select courseName 课程名字, count(stuiD)学生个数,sum(scoreInfo.score)学生考试的总分 from courseInfo + left join scoreInfo on courseInfo.courseID=scoreInfo.courseID group by courseInfo.courseName + +--3.查询出性别一样并且年龄一样的学生的信息 + select distinct A. * from stuInfo A,stuInfo B where A.stuAge=B.stuAge AND A.stuSex=B.stuSex AND A.stuName!=B.stuName +--4.查询出学分一样的课程信息 + select distinct A.* from courseInfo A,courseInfo B where A.couresMarks=B.couresMarks and A.courseID!=B.courseID +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + select stuInfo.stuID,stuInfo.stuName,courseInfo.courseID,scoreInfo.score from scoreInfo + inner join stuInfo on scoreInfo.stuiD= stuInfo.stuID + inner join courseInfo on scoreInfo.courseID=courseInfo.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + select stuInfo.stuID,courseInfo.courseID,courseInfo.courseNAME,courseInfo.couresMarks,scoreInfo.score from scoreInfo + inner join stuInfo on scoreInfo.stuiD= stuInfo.stuID + inner join courseInfo on scoreInfo.courseID=courseInfo.courseID +--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 stuname like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + select stuid ,count(*) 数量 ,avg(score) 平均分 from scoreInfo group by stuid having count(*)>=2 and avg(score)>=70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/tttt...two.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/tttt...two.sql" new file mode 100644 index 0000000..e12f90c --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/tttt...two.sql" @@ -0,0 +1,79 @@ +use master +go +create database wangba +go +use wangba +go +create table tbl_cardcard +( + id varchar(50) primary key, + pasword varchar(50), + balance money, + userName varchar(50) +) +create table tbl_computer +( + id varchar(50) primary key, + onUse varchar(2) check(onUse=0 or onUse=1), + note ntext +) +create table tbl_record +( + id varchar(50) primary key, + cardId varchar(50) foreign key references card(id), + ComputerId varchar(50) foreign key references computer(id), + beginTime datetime, + endTime datetime, + fee money +) +insert into tbl_cardcard(ID,pasword,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' + +insert into tbl_computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' + +insert into tbl_record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from tbl_cardcard +select * from tbl_computer +select * from tbl_record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select b.id 卡号,b.userName 用户名,c.id 机器编号, a.beginTime 开始时间,a.endTime 结束时间,a.fee 消费金额 from record a inner join card b on a.cardId=b.id +inner join computer c on c.id=a.ComputerId where b.userName='张军' order by a.fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select b.id 机器,count(*)上网次数,sum(c.fee)消费的总金额 from computer b left join record c on b.id=c.ComputerId group by b.id,c.fee order by c.fee desc +--3. 查询出所有已经使用过的上网卡的消费总金额 +select b.id, sum(b.fee)消费总金额 from card a inner join record b on a.id=b.cardId group by b.id +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id,userName from card where id in (select id from record group by id ) +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from card where userName = pasword +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 max(ComputerId) 机器号,count(*)次数 from record group by ComputerId order by count(*) desc +----7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -- Gitee From c05970241aa37e104c48670847400831c178c1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E6=98=82?= <2636153719@qq.com> Date: Wed, 31 Mar 2021 20:41:24 +0800 Subject: [PATCH 104/195] 1 --- .../\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" | 1 + .../\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" new file mode 100644 index 0000000..7ef3091 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" @@ -0,0 +1 @@ +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) create database stu go use stu go create table stuInfo ( stuId int primary key identity, stuname nvarchar(20) , stuage int , stusex int check(stusex=1 or stusex=0), time datetime ) create table courseInfo ( courseid int primary key identity, couesename nvarchar(20) , cousrmarks int ) create table scoreInfo ( scoreid int primary key identity, stuid int, courseid int, score int ) insert into stuInfo 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 values ('javabase',4), ('html',2), ('javascript',2), ('sqlbase',2) insert into scoreInfo 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) select * from stuInfo --学生信息表 select * from courseInfo --科目表 select * from scoreInfo --成绩表 select * from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid --题目: --1.查询出 每个学生 所选修的 课程的数量 和所 选修的课程的考试的平均分 select stuname 学习, count(C.cousrmarks) 课程, avg(score) 平均分 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid group by stuname --2.查询出每门课程的选修的学生的个数和学生考试的总分 select C.couesename,count(S.stuId) 学生的个数,sum(O.score) 总分 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid group by C.couesename --3.查询出性别一样并且年龄一样的学生的信息 select stuage,stusex ,count(stuage),count(stusex) from stuInfo group by stuage,stusex having count(stuage)>1 and count(stusex) >1 select * from stuInfo where stuage in (select stuage from stuInfo group by stuage,stusex having count(stusex) >1) select * from stuInfo A , stuInfo B where A.stuage = B.stuage and A.stusex = B.stusex and A.stuname!=B.stuname --4.查询出学分一样的课程信息 select * from courseInfo where cousrmarks in (select cousrmarks from courseInfo group by cousrmarks having count(cousrmarks)>1) select * from courseInfo A ,courseInfo B where A.cousrmarks=B.cousrmarks and A.couesename!= B.couesename --5.查询出参加了考试的学生的学号,姓名,课程号和分数 select o.stuid 学号, stuname 姓名,o.courseid 课程号,o.score 分数 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid --6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 select o.stuid 学号, stuname 姓名,o.courseid 课程号,c.couesename 课程名,c.cousrmarks 课程学分,o.score 分数 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid --7.查询出没有参加考试的学生的学号和姓名 select * from stuInfo S left join scoreInfo O on S.stuId=O.stuid left join courseInfo C on O.courseid = C.courseid where c.couesename is null --8.查询出是周六周天来报到的学生 --9.查询出姓名中有字母a的学生的信息 select stuname from stuInfo where stuname like '%a%' --10.查询出选修了 2门课程以上 的并且 考试平均分在70 以上的 学生的学号和考试平均分以及选修课程的数量 select s.stuId, count(c.courseid) 选修课程的数量,avg(score) 考试平均分 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid group by s.stuId having count(c.courseid)>1 and avg(score)>70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" new file mode 100644 index 0000000..a24b9b9 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery2.sql" @@ -0,0 +1,3 @@ +use master go --首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: create database internet go use internet go --表一为上网卡信息表(tbl_card) --id: 卡号,主键 --passWord:密码 --balance:卡上的余额 --userName:该上网卡所属的用户名 create table tbl_card ( ID nvarchar(10) primary key not null, PassWord nvarchar(10) not null, Balance nvarchar(10) not null, UserName nvarchar(10) not null ) insert into tbl_card values ('0023_ABC','555','98','张军'), ('0025_bbd','abe','300','朱俊'), ('0036_CDD','何柳','100','何柳'), ('0045_YGR','0045_YGR','58','证验'), ('0078_RJV','55885fg','600','校庆'), ('0089_EDE','zhang','134','张骏') --表2为网吧机器说明表(tbl_computer) --id:机器编号,主键 --onUse:该机器是否正在使用,0为未使用,1为正在使用 --note:该机器的说明 create table tbl_computer ( ID nvarchar(10) not null primary key, OnUse int check(OnUse=1 or OnUse=0) not null, Note int not null ) insert into tbl_computer values ('02',0,25555), ('03',1,25555), ('04',0,66666), ('05',1,88888), ('06',0,688878), ('B01',0,558558) --表3为上网记录表(tbl_record): --id:记录编号,主键 --cardId:本次上网的卡号,外键 --ComputerId:本次上网记录所使用的机器号,外键 --beginTime:本次上网记录的开始时间 --endTime:本次上网记录的结束时间 --fee:本次上网的费用 create table tbl_record ( ID nvarchar(20) primary key not null, CardID nvarchar(10) not null foreign key references tbl_card(ID), ComputerID nvarchar(10) not null foreign key (ComputerID) references tbl_computer(ID), BeignTime datetime not null, EndTime datetime not null, Fee int not null ) insert into tbl_record values (23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), (34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), (45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), (46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), (47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',60), (48,'0023_ABC','03','2007-01-06 15:26:00','2006-01-06 22:55:00',6), (55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), (64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), (65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), (98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) --请完成以下题目: select * from tbl_record --上网记录表(tbl_record) select* from tbl_computer --网吧机器说明表(tbl_computer) select * from tbl_card --上网卡信息表(tbl_card) select * from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID --1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额, --并按消费金额降序排列 select r.CardID 卡号,a.UserName 用户名,c.ID 机器编号,r.BeignTime 开始时间,r.EndTime 结束时间,r.Fee 消费金额 from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID where a.UserName='张军' --2. 查询出每台机器上的上网次数和消费的总金额 select C.ID 机器, count(c.OnUse) 上网次数, sum(r.Fee) 总金额 from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID group by C.ID, c.OnUse --3. 查询出所有已经使用过的上网卡的消费总金额 select r.CardID 上网卡,sum(r.Fee) 消费总金额 from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID group by r.CardID --4. 查询出从未消费过的上网卡的卡号和用户名 select a.ID 卡号,a.UserName 用户名 from tbl_record R right join tbl_computer C on r.ComputerID=c.ID right join tbl_card A on r.CardID=a.ID group by a.ID,r.Fee,a.UserName having r.Fee is null --5. 将密码与用户名一样的上网卡信息查询出来 select a.* from tbl_card a,tbl_card b where a.PassWord=b.UserName --6. 查询出使用次数最多的机器号和使用次数 select top 1 count(*) 使用次数,ComputerID 机器号 from tbl_record group by ComputerID order by count(*) desc --7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 select r.CardID,a.UserName,c.ID,r.Fee from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID where a.ID like '%abc' --8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 --9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 --10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 select Fee , CardID,UserName , ComputerID,BeignTime , EndTime from tbl_record +inner join tbl_card on tbl_record.CardID=tbl_card.ID +where Fee not in (select top 3 fee from tbl_record order by fee DESC) \ No newline at end of file -- Gitee From d01f0a118f49ea4decd5120d48a42ed10ea7b6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Wed, 31 Mar 2021 20:42:15 +0800 Subject: [PATCH 105/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=99=88=E6=B5=A9?= =?UTF-8?q?=E5=AE=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\231\210\346\265\251\345\256\207/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From c3de47eeb493c1bc3d898913ef81dd6ede48fb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Wed, 31 Mar 2021 20:42:37 +0800 Subject: [PATCH 106/195] 1 --- .../SQLQuery2.sql" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery2.sql" new file mode 100644 index 0000000..796e81e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery2.sql" @@ -0,0 +1,85 @@ +use master +go +create database student +on +( + name='student', + filename='D:\student.mdf', + size=10mb, + maxsize=100mb, + filegrowth=15% +) +log on +( + name='student_log', + filename='D:\studentlog.ldf', + size=10mb, + maxsize=100mb, + filegrowth=15% +) +go +use student +go +create table stuinfo +( + stuid int primary key identity, + stuname nvarchar(10), + stuage nchar(10), + stusex char(1) check (stusex in(1,0)), + time datetime +) +create table courseinfo +( + courseid int primary key identity, + coursename nvarchar(10), + coursemarks int +) +create table scoreinfo +( + scoreid int identity primary key, + stuid int, + courseid int, + score int +) +insert into stuinfo 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 values ('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) +insert into scoreinfo 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) +select * from stuinfo +select * from scoreinfo +select * from courseinfo +--1.查询出 每个学生 所选修的课程的数量 和 所选修的课程的考试的平均分 +select stuinfo.stuid,stuname,count(courseid)课程的数量,avg(score)平均分 from scoreinfo +inner join stuinfo on stuinfo.stuid = scoreinfo.stuid group by stuinfo.stuid,stuinfo.stuname +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseinfo.coursename,count(stuid)学生的个数,sum(score)考试的总分 from scoreinfo +inner join courseinfo on courseinfo.courseid = scoreinfo.courseid group by courseinfo.coursename +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A,stuInfo B where A.stuSex=B.stuSex and A.stuAge=B.stuAge and A.stuID != B.stuID +--4.查询出学分一样的课程信息 +select distinct A.* from courseinfo A,courseinfo B where A.coursemarks = B.coursemarks and A.courseid != B.courseid +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuinfo.stuid,stuinfo.stuname,scoreinfo.courseid,scoreinfo.score from scoreinfo +inner join stuinfo on stuinfo.stuid = scoreinfo.stuid +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreinfo.stuid,courseinfo.courseid,courseinfo.coursename,courseinfo.coursemarks,scoreinfo.score from scoreinfo +inner join courseinfo on courseinfo.courseid = scoreinfo.courseid +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuID 学号,stuInfo.stuName 姓名 from stuinfo +left join scoreinfo on scoreInfo.stuID=stuInfo.stuID +except +select stuInfo.stuID 学号,stuInfo.stuName 姓名 from scoreInfo +right join stuInfo on scoreInfo.stuID=stuInfo.stuID where score is not null +--8.查询出是周六周天来报到的学生 +select * from stuInfo where DATEPART(dw,[time]) in(1,7) +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuinfo.stuid 学号,avg(score)考试平均分,count(score.courseid)选修课程的数量 from scoreinfo +inner join courseinfo on scoreInfo.courseID=courseInfo.courseID +inner join stuInfo on stuInfo.stuID=scoreInfo.stuID group by stuInfo.stuName , stuInfo.stuID having count(*)>2 and avg(score)>70 -- Gitee From 936e53bfacefd5f95b2506f9d68df4cf2e7812f6 Mon Sep 17 00:00:00 2001 From: yangwenrong <956352682@qq.com> Date: Wed, 31 Mar 2021 20:45:22 +0800 Subject: [PATCH 107/195] 2021.3.31.20 --- .../SQLQuery1.sql" | 109 +++++++++++++++++ .../SQLQuery2.sql" | 115 ++++++++++++++++++ 2 files changed, 224 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" new file mode 100644 index 0000000..d5679b9 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" @@ -0,0 +1,109 @@ +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +use master +go + +create database Student +on +( + name='Student', + filename='C:\学习\数据库\Student.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='Student_log', + filename='C:\学习\数据库\Student_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go +use Student +go + +create table stuInfo +( + stuID int primary key identity(1,1), + stuName nvarchar(10), + stuAge int, + stuSex int check(stuSex='1'or stuSex='0'), + time datetime +) +create table courseInfo +( + courseID int primary key identity(1,1), + courseName nvarchar(20), + courseMarks int, +) +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int +) + +insert into stuInfo 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 values +('javaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) + +insert into scoreInfo 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) + + +select * from stuInfo +select * from courseInfo +select * from scoreInfo +--1.查询出 每个学生 所选修的课程的数量 和 所选修的课程的考试的平均分 +select stuName 学生,count(*) 课程的数量,AVG(score) 平均分 from stuInfo +inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID +group by stuName +--2.查询出 每门课程 的 选修的学生的个数 和 学生考试的总分 +select courseName 课程,count(*) 个数,sum(score) 总分 from courseInfo +inner join scoreInfo on courseInfo.courseID=scoreInfo.courseID +group by courseName +--3.查询出性别一样并且年龄一样的学生的信息 +select * from stuInfo +select A.stuAge,A.stuSex,a.* from stuInfo A,stuInfo B where A.stuAge=B.stuAge and A.stuSex=B.stuSex and A.stuID!=B.stuID +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks and A.courseID!=B.courseID +--5.查询出 参加了考试的学生 的学号,姓名,课程号和分数 +select stuInfo.stuID,stuName,courseID,score from stuInfo right join scoreInfo on stuInfo.stuID=scoreInfo.stuID +--6.查询出 参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuInfo.stuID,stuName,scoreInfo.courseID,courseInfo.courseName,courseInfo.courseMarks,score from stuInfo +right join scoreInfo on stuInfo.stuID=scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuID,stuInfo.stuName from stuInfo full join scoreInfo on stuInfo.stuID=scoreInfo.stuID +except +select stuInfo.stuID,stuInfo.stuName from stuInfo right join scoreInfo on stuInfo.stuID=scoreInfo.stuID +--8.查询出是周六周天来报到的学生 +select * from stuInfo where DATEPART(dw,time)=7 or DATEPART(dw,time)=1 +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName='%a%' +--10.查询出 选修了2门课程以上的 并且 考试平均分在70以上的 学生 的学号和考试平均分以及选修课程的数量 +select stuID 学号,avg(score) 平均分,count(*) 课程数量 from scoreInfo +group by stuID +having avg(score)>70 and count(*)>2 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery2.sql" new file mode 100644 index 0000000..1c7948c --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery2.sql" @@ -0,0 +1,115 @@ + use master + go + + create database Itb + on + ( + name='Internet bar', + filename='D:\Itb.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% + ) + log on + ( + name='Internet bar_log.ldf', + filename='D:\Itb_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% + ) + go + use Itb + go + + create table tbl_card + ( + id nvarchar(10) primary key, + passWord nchar(20), + balance decimal(5,2), + userName nvarchar(20) + ) + + create table tbl_computer + ( + id nvarchar(10) primary key, + onUse char(1) check(onUse=0 or onUse=1), + note text + ) + + create table tbl_record + ( + id nvarchar(10) primary key, + cardId nvarchar(10) references tbl_card(id), + ComputerId nvarchar(10) references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee int + ) + +insert into tbl_card values +('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'), +('0078_RJV','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张峻') + +insert into tbl_computer values +('02',0,'25555'), +('03',1,'55555'), +('04',0,'66666'), +('05',1,'88888'), +('06',0,'688878'), +('B01',0,'558558') + +insert into tbl_record values +(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',300), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) + +--请完成以下题目: +select * from tbl_card +select * from tbl_computer +select * from tbl_record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select A.id 卡号,userName 用户名,B.ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_card A +inner join tbl_record B on A.id=B.cardId +where userName='张军' +order by fee DESC +--2. 查询出 每台机器 上的 上网次数 和 消费的总金额 +select ComputerId,count(*) 上网次数,sum(fee) 消费总金额 from tbl_record +group by ComputerId +--3. 查询出所有已经使用过的上网卡的 消费总金额 +select cardId 卡号,sum(fee)消费总金额 from tbl_record group by cardId +--4. 查询出从未消费过的上网卡的卡号和用户名 +select A.id,userName 用户名 from tbl_card A left join tbl_record C on C.cardId=A.id +where A.id NOT IN (select cardId from tbl_record) +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card where userName=passWord +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId,COUNT(*) 使用次数 from tbl_record group by ComputerId order by count(*) DESC +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_record.cardId 卡号,userName 用户名,ComputerId 机器号,fee 消费金额 from tbl_card +full join tbl_record on tbl_card.id=tbl_record.cardId +where tbl_card.id like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,ComputerId,beginTime,endTime,fee from tbl_record +full join tbl_card on tbl_record.cardId=tbl_card.id +where DATEPART(dw,beginTime)=7 or DATEPART(dw,beginTime)=1 +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,ComputerId,beginTime,endTime,fee from tbl_record +full join tbl_card on tbl_record.cardId=tbl_card.id +where datediff(HH,beginTime,endTime)>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select * from tbl_record +full join tbl_card on tbl_record.cardId=tbl_card.id +where tbl_record.id not in (select top 3 id from tbl_record order by fee DESC) + -- Gitee From 41a0fd4a4559eb629ac2c308eb1ef776839dd336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BA=8C=E6=9F=B1?= <2964399941@qq.com> Date: Wed, 31 Mar 2021 21:21:38 +0800 Subject: [PATCH 108/195] =?UTF-8?q?=E6=9D=8E=E5=98=89=E5=9F=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 86 ++++++++++++++ .../SQLQuery2.sql" | 112 ++++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery1.sql" new file mode 100644 index 0000000..cb07ee7 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery1.sql" @@ -0,0 +1,86 @@ +use master +go +create database abc +go +use abc +go +create table stuInfo +--学生信息表 +( + stuId int identity(1,1), + stuName nvarchar(10) not null, + stuAge int not null, + stuSex int not null, + time datetime, +) +insert into stuInfo +select 'Tom',19,1,null union +select 'Jack',20,0,null union +select 'Rose',21,1,null union +select 'Lulu',19,1,null union +select 'Lili',21,0,null union +select 'abc',20,1,'2007-01-07 01:11:36.590' + +create table courseInfo +--课程信息表 +( + courseId int identity(1,1), + courceName nvarchar(20) not null, + courseMarks int not null +) +insert into courseInfo +select 'JavaBase',4 union +select 'HTML',2 union +select 'JavaScript',2 union +select 'SqlBase',2 + +create table scoreInfo +--分数信息表 +( + scoreId int identity(1,1), + stuId int not null, + courseId int not null, + score int not null +) +insert into scoreInfo +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + +select * from stuInfo --学生信息表 +select * from courseInfo --课程信息表 +select * from scoreInfo --分数信息表 + +--题目: +--1.查询出每个学生所选修的课程的数量 和所选修的课程的考试的平均分 +select stuId 学生,COUNT(*) 课程数量,AVG(score) 考试平均分 from scoreInfo group by stuId +--2.查询出每门课程的选修的学生的个数 和 学生考试的总分 +select C.courseId 课程,count(*)数量,sum(S.score)总分 from courseInfo C +inner join scoreInfo S on C.courseId=S.courseId group by C.courseId +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A, stuInfo B where A.stuage= B.stuage and A.stusex=B.stusex and A.stuId !=B.stuId +--4.查询出学分一样的课程信息 +select * from courseInfo where courseMarks in +(select courseMarks from courseInfo group by courseMarks having count(courseMarks)>1) +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select b.stuId 学号,a.stuname 学生姓名,b.courseId 课程号,b.score 分数 +from stuInfo a inner join scoreInfo b on a.stuId=b.stuId +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuId 学号,b.courseId 课程号,courceName 程名,courseMarks 课程名,score 分数 +from courseInfo a inner join scoreInfo b on a.courseId=b.courseId +--7.查询出没有参加考试的学生的学号和姓名 +select stuId 学号,stuname 学生姓名 from stuInfo where stuId not in (select stuId from scoreInfo group by stuId) +--8.查询出是周六周天来报到的学生 +select stuId from stuInfo where datepart(dw,time)=1 or datepart(dw,time)=7 +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuid 学号 ,count(*) 数量 ,avg(score) 平均分 from scoreInfo group by stuid having count(*)>=2 and avg(score)>=70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery2.sql" new file mode 100644 index 0000000..add2b6f --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery2.sql" @@ -0,0 +1,112 @@ +use master +go +create database abcd +go +use abcd +go +create table card +( + id varchar(30) primary key, + pasword varchar(30), + balance money, + userName varchar(50) +) +create table computer +( + id varchar(30) primary key, + onUse varchar(2) check(onUse=0 or onUse=1), + note ntext +) +create table record +( + id varchar(30) primary key, + cardId varchar(30) foreign key references card(id), + ComputerId varchar(30) foreign key references computer(id), + beginTime datetime, + endTime datetime, + fee money +) +--上网卡信息表 +insert into card(ID,pasword,balance,userName) +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' +--网吧机器说明表 +insert into computer(id,onUse,note) +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' +--上网记录表 +insert into record(ID,cardId,ComputerId,beginTime,endTime,fee) +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from card +select * from computer +select * from record + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名, +--机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select cardId,userName,ComputerId,beginTime,endTime,fee from record a +inner join card b on a.cardId=b.id where b.userName='张军' order by fee desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId,COUNT(ComputerId),SUM(fee) from record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select SUM(balance) from card + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select a.id,a.userName,b.fee from card a left join record b on a.id=b.cardId +where fee is null group by a.id,a.userName,b.fee + +--5. 将密码与用户名一样的上网卡信息查询出来 +select a.* from card a ,card b where a.pasword=b.userName + +select * from card +select * from computer +select * from record + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(*)次数 from record group by ComputerId order by count(*) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select a.id 卡号,a.userName 用户名,b.ComputerId 机器号,b.fee 消费金额 +from card a inner join record b on a.id=b.cardId where a.id like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select cardId,userName a,P.id,beginTime,endTime,fee +from record inner join computer P +on ComputerId=P.id inner join card C on C.id=cardId +where datepart(weekday,beginTime)=1 or datepart(weekday,beginTime)=7 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select cardId,userName,a.id,beginTime,endTime,fee +from record inner join computer a +on computerId=a.id inner join card C on C.id=cardId +where datediff(hour,beginTime,endTime)>12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select cardId,userName,a.id,beginTime,endTime,fee +from record inner join computer a +on ComputerId=a.id inner join card C on C.id=cardId +where fee not in(select top 3 fee from record order by fee DESC) + + -- Gitee From ab47565122d89102392b06dd383d70a408ae0494 Mon Sep 17 00:00:00 2001 From: yu-sijie <1609873552@qq.com> Date: Wed, 31 Mar 2021 21:31:15 +0800 Subject: [PATCH 109/195] =?UTF-8?q?SQL=E4=BD=9C=E4=B8=9A11=E2=80=94?= =?UTF-8?q?=E2=80=943/31?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery--HomeWork.sql" | 119 +++++++++++++++++ .../SQLQuery--WB.sql" | 121 ++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--HomeWork.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--WB.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--HomeWork.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--HomeWork.sql" new file mode 100644 index 0000000..ab8b45a --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--HomeWork.sql" @@ -0,0 +1,119 @@ +use master +go + +create database HomeWork +on +( + name='HomeWork', + filename='D:\SQL作业\SQL作业11\HomeWork.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='HomeWork_log', + filename='D:\SQL作业\SQL作业11\HomeWork_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use HomeWork +go +create table stuInfo +( + stuID int primary key identity(1,1), + stuName char(20) not null, + stuAge char(5) not null, + stuSex char(2) not null, + time time +) +go + +insert into stuInfo 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') + +select * from stuInfo + +use HomeWork +create table courseInfo +( + courseID int primary key identity(1,1), + courseName nvarchar(15) not null, + courseMarks char(5) not null +) +go + +select * from courseInfo + +insert into courseInfo values('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) + +select * from courseInfo + + +use HomeWork +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int constraint FK_scoreInfo_stuID references stuInfo(stuID), + courseID int not null, + score int not null +) +go + +insert into scoreInfo 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) + + +select * from stuInfo +select * from courseInfo +select * from scoreInfo + + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuName 学生,count(*)课程数量,avg(score)平均分 from scoreInfo +inner join stuInfo on stuInfo.stuID = scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID = courseInfo.courseID group by stuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName 课程,count(*)学生个数,sum(score)考试总分 from scoreInfo +inner join courseInfo on scoreInfo.courseID = courseInfo.courseID group by courseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A,stuInfo B where A.stuAge=B.stuAge and A.stuSex=B.stuSex and A.stuID!=B.stuID + +select s.* from StuInfo s where (select count(*) from StuInfo where stuAge=s.stuAge and stuSex=s.stuSex)>1 + +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks and A.courseID!=B.courseID + +select c.* from courseInfo c where (select count(*) from courseInfo where courseMarks=c.courseMarks)>1 + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select StuInfo.stuID 学号,stuName 姓名, courseInfo.courseID 课程号,score 分数 from scoreInfo +inner join StuInfo on scoreInfo.stuID = StuInfo.stuID +inner join courseInfo on scoreInfo.courseID = courseInfo.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select StuInfo.stuID 学号,courseInfo.courseID 课程号, courseName 课程名,courseMarks 课程学分,score 分数 from scoreInfo +inner join StuInfo on scoreInfo.stuID = StuInfo.stuID +inner join courseInfo on scoreInfo.courseID = courseInfo.courseID + +--7.查询出没有参加考试的学生的学号和姓名 +select StuInfo.stuID 学号,stuName 姓名 from StuInfo left join scoreInfo on scoreInfo.stuID = StuInfo.stuID +where score is null + +--8.查询出是周六周天来报到的学生 +--I can't do it + +--9.查询出姓名中有字母a的学生的信息 +select * from StuInfo where stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuInfo.stuID 学号,avg(score)平均分,count(*)选修课程数量 from stuInfo +inner join scoreInfo on stuInfo.stuID = scoreInfo.stuID group by stuInfo.stuID +having count(*)>2 and avg(score)>70 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--WB.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--WB.sql" new file mode 100644 index 0000000..dd03993 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--WB.sql" @@ -0,0 +1,121 @@ +use master +go +create database WB +on +( + name='WB', + filename='D:\SQL作业\SQL作业11\WB.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='WB_log', + filename='D:\SQL作业\SQL作业11\WB_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use WB +go +create table tbl_card +( + id varchar(25) primary key, + [passWord] varchar(30) not null, + balance money not null, + userName varchar(20) not null +) +go + + +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abe',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'),('0045_YGR','0045_YGR',58,'验证'), +('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张峻') + +select * from tbl_card + +use WB +create table tbl_computer +( + id varchar(20) primary key, + onUse char(2) check(onUse=0 or onUse=1), + note text +) +go + +insert into tbl_computer values('02','0','25555'),('03','1','55555'),('04','0','66666'), +('05','1','88888'),('06','0','688878'),('B01','0','558558') + +select * from tbl_computer + +use WB +create table tbl_record +( + id varchar(30) primary key, + cardId varchar(25) constraint FK_tbl_record_cardId references tbl_card(id), + ComputerId varchar(20) constraint FK_tbl_record_ComputerId references tbl_computer(id), + beginTime time, + endTime time, + fee money +) +go + +insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +('47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3'), +('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId +where userName='张军' order by fee desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(*)次数,sum(fee)总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId 卡号,sum(fee)总金额 from tbl_record group by cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select cardId 卡号,userName 用户名 from tbl_record +right join tbl_card on tbl_card.id = tbl_record.cardId where tbl_card.id not in(select cardId from tbl_record) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card A,tbl_card B where A.passWord = B.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 使用最多的机器号,count(*)次数 from tbl_record group by ComputerId order by count(*) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,fee 金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId where tbl_card.id like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +--I can't do it + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_record +inner join tbl_card on tbl_card.id = tbl_record.cardId where fee not in(select top 3 fee from tbl_record order by fee desc) + +select top 3 fee from tbl_record order by fee desc + + -- Gitee From b376a9778645b76da0eebe5ede7d731c991e08f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=80?= <8332095+Xone-by-one@user.noreply.gitee.com> Date: Wed, 31 Mar 2021 21:33:21 +0800 Subject: [PATCH 110/195] 123 --- .../SQLQuery1.sql" | 90 ++++++++++++++++++ .../SQLQuery2.sql" | 91 +++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" new file mode 100644 index 0000000..4589fb2 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" @@ -0,0 +1,90 @@ +create database Students +on +( +name='Students_data', +filename='C:\app\Students_data.mdf', +size=1mb, +Maxsize=50mb, +filegrowth=10% +) +log on +( +name='Students_log', +filename='C:\app\Students_log.ldf', +size=1mb, +filegoeth=1mb +) +USE Students +go +create table StuInfo +( +StuID int primary key , +Stuname varchar(10), +StuAge int, +StuSex nvarchar(1), +time datetime +) + +INSERT into StuInfo(StuID,Stuname,StuAge,StuSex,time) +SELECT 1,'Tom',19,1,'' UNION +SELECT 1,'Jack',20,0,'' UNION +SELECT 1,'Rose',21,1,'' UNION +SELECT 1,'Lulu',19,1,'' UNION +SELECT 1,'Lili',21,0,'' UNION +SELECT 1,'abc',20,1,'2007-01-0701:11:36.590' + + +create table courseInfo +( +courseID int primary Key, +courseName varchar(25), +courseMarks varchar(5) +) +INSERT into courseInfo(courseID,courseName,courseMarks) +SELECT 1,'JavaBase',4 UNION +SELECT 2,'HTML',2 UNION +SELECT 3,'JavaScript',2 UNION +SELECT 4,'SplBase',2 + +create table scoreInfo +( +scoreID int primary key identity(1,1), +stuID int, +courseID int foreign key references courseInfo(courseID), +score int +) +INSERT into scoreInfo(scoreID,stuID,courseID,score) +SELECT 1,1,1,80 UNION +SELECT 2,1,2,85 UNION +SELECT 3,1,4,50 UNION +SELECT 4,2,1,75 UNION +SELECT 5,2,3,45 UNION +SELECT 6,2,4,75 UNION +SELECT 7,3,1,45 UNION +SELECT 8,4,1,95 UNION +SELECT 9,4,2,75 UNION +SELECT 10,4,3,90 UNION +SELECT 11,4,4,45 + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +SELECT StuID,count(courseID),Avg(score) FROM scoreInfo group by stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseID,COUNT(courseID),SUM(score) from scoreInfo group by courseID +--3.查询出性别一样并且年龄一样的学生的信息 +select A.StuAge,B.StuSex from StuInfo A inner join StuInfo B on A.StuAge=B.StuSex +--4.查询出学分一样的课程信息 +select A.courseMarks,B.courseMarks from courseInfo A inner join courseInfo B on A.courseMarks=B.courseMarks +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo +left join stuInfo on scoreInfo.stuID=stuInfo.stuID group by scoreInfo.stuID,stuName,courseID,score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo +left join courseInfo on scoreInfo.courseID=courseInfo.courseID +--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 stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID having avg(score)>=70 and count(courseID)>=2 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery2.sql" new file mode 100644 index 0000000..603e929 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery2.sql" @@ -0,0 +1,91 @@ +create database Student +on +( +name='Student_data', +filename='C:\app\Student_data.mdf', +size=1mb, +Maxsize=50mb, +filegrowth=10% +) +log on +( +name='Student_log', +filename='C:\app\Student_log.ldf', +size=1mb, +filegoeth=1mb +) +USE Student +go +create table tbl_card +( +id int NOT null, +passWord varchar(10) not null, +balance int NOT null, +userName int NOT null +) +INSERT into tbl_card(id,passWord,balance,userName) +SELECT 0023_abc,'555',98,'张军' UNION +SELECT 0025_bbd,'abe',300,'朱俊' UNION +SELECT 0036_CDD,'何柳',100,'何柳' UNION +SELECT 0045_YGR,'0045_YGR',58,'证验' UNION +SELECT 0078_RJV,'55885fg',600,'校庆' UNION +SELECT 0089_EDE,'zhang',134,'张峻' +create table tbl_computer +( +id varchar(30) primary key, +onUse bit NOT null DEFAULT(0), +note int +) +INSERT into tbl_computer(id,onUse,note) +SELECT '02',0,25555 UNION +SELECT '03',1,55555 UNION +SELECT '04',0,66666 UNION +SELECT '05',1,88888 UNION +SELECT '06',0,688878 UNION +SELECT 'B01',0,558558 +create table tbl_record +( +id int NOT null, +cardld char(10) NOT null, +Computerld int, +beginTime datetime, +endTime datetime, +fee int not null +) +INSERT into tbl_record(id,cardld,Computerld,beginTime,endTime,fee) +SELECT '23','0078_RJV','B01,2007-07-15 19:00:00','2007-07-15 21:00:00','20' UNION +SELECT '34','0025_bbd','02,2006-12-25 18:00:00','2006-12-25 21:00:00','23'UNION +SELECT '45','0023_ABC','03,2006-12-23 15:26:00','2006-12-23 22:55:00','50' UNION +SELECT '46','0023_ABC','03,2006-12-22 15:26:00','2006-12-22 22:55:00','6' UNION +SELECT '47','0023_ABC','03,2006-12-23 15:26:00','2006-12-23 22:55:00','50' UNION +SELECT '48','0023_ABC','03,2007-01-06 15:26:00','2007-01-06 22:55:00','6' UNION +SELECT '55','0023_ABC','03,2006-07-21 15:26:00','2006-07-21 22:55:00','50' UNION +SELECT '64','0045_Y...','04,2006-12-24 18:00:00','2006-12-24 22:00:00','3...'UNION +SELECT '65','0025_bbd','02,2006-12-28 18:00:00','2006-12-28 22:00:00','23' UNION +SELECT '98','0025_bbd','02,2006-12-26 18:00:00','2006-12-26 22:00:00','23' +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select card.id , card.userName ,beginTime ,endTime,fee +from card inner join record on card.id=record.cardId where userName='张军' order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId ,count(cardId),sum(fee) from record group by cardId,ComputerId +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId,sum(record.fee) 总金额 from record group by cardId +--4. 查询出从未消费过的上网卡的卡号和用户名 +select card.id,userName from card +left join record on card.id=record.cardId +where fee is null group by userName,card.id +--5. 将密码与用户名一样的上网卡信息查询出来 +select A.* from card A,card B where A.pasword=B.userName +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId)使用次数 from record +group by ComputerId order By count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 +from record inner join card on record.cardId=card.id where record.cardId like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on t.ComputerId=x.id inner join tbl_card a on a.id=t.cardId where datepart(weekday,beginTime)=6 or datepart(weekday,beginTime)=7 +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId,userName,x.id,beginTime,endTime,fee from tbl_record t inner join tbl_computer x on ComputerId=x.id inner join tbl_card a on a.id=t.cardId where datediff(hour,beginTime,endTime)>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc \ No newline at end of file -- Gitee From 6ad6d1f45c3997c514ac423ee848362e1b85ce0d Mon Sep 17 00:00:00 2001 From: meng-lingkun <1725116698@qq.com> Date: Wed, 31 Mar 2021 21:50:40 +0800 Subject: [PATCH 111/195] aaa --- .../\344\277\241\346\201\257\350\241\250.sql" | 76 ++++++++++++++++++ ...1\345\220\247\350\256\241\350\264\271.sql" | 80 +++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\344\277\241\346\201\257\350\241\250.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\347\275\221\345\220\247\350\256\241\350\264\271.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\344\277\241\346\201\257\350\241\250.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\344\277\241\346\201\257\350\241\250.sql" new file mode 100644 index 0000000..2b4322d --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\344\277\241\346\201\257\350\241\250.sql" @@ -0,0 +1,76 @@ +use master +go + +create database TEXT + +go + +use TEXT +go +create table stuInfo +( + stuID int primary key identity(1,1), + stuName nvarchar(10), + stuAge int, + stuSex varchar(2) check(stuSex = '1' or stuSex = '0') default('1'), + time datetime, +) +go + +use TEXT +go +create table courseInfo +( + courseID int primary key identity(1,1), + courseName nvarchar(10), + courseMarks varchar(2) +) +go + +use TEXT +go +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int +) + +insert into stuInfo values('Tom','19','1',''),('Jack','20','0',''),('Rose','21','1',''),('Lulu','19','1',''),('Lili','21','0',''),('abc','20','1','2007-01-07 01:11:36.590') +insert into courseInfo values('JavaBase','4'),('HTML','2'),('JavaScript','2'),('SqlBase','2') +insert into scoreInfo 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 courseID 课程,COUNT(*) 数量,AVG(score)平均分 from stuInfo inner join scoreInfo on stuInfo.stuID = scoreInfo.stuID group by courseID + +--2.查询出 每门课程 的 选修的学生 的个数 和 学生考试的总分 +select courseID 课程,count(SC.stuID)选修学生的个数,SUM(score) 总分 from stuInfo SI inner join scoreInfo SC on SI.stuID = SC.stuID group by courseID + +--3.查询出 性别一样 并且 年龄一样 的学生的信息 +select A.* from stuInfo A ,stuInfo B +where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stuID!=B.stuID + +--4.查询出学分一样的课程信息 +select DISTINCT A.* from courseInfo A inner join courseInfo B on A.courseMarks = B.courseMarks AND a.courseID != B.courseID + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select SC.stuID 学号,stuName 姓名,courseID 课程号,score 分数 from stuInfo ST inner join scoreInfo SC on ST.stuID = SC.stuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select C.courseID 课程号,stuID 学号,courseName 课程名,courseMarks 课程学分,score 分数 +from courseInfo C inner join scoreInfo S on C.courseID = S.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select ST.stuID 学号,stuName 姓名 from stuInfo ST inner join scoreInfo SC on ST.stuID != SC.stuID +select * from scoreInfo +select * from stuInfo +select * from courseInfo +--8.查询出是周六周天来报到的学生 +select * from stuInfo where DATEPART(dw,[time]) in(0,1) +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName LIKE '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的s 学号 和 考试平均分 以及选修 课程的数量 +select AVG(score) 考试平均分,courseID,COUNT(*) 课程的数量 +from stuInfo ST inner join scoreInfo SC on ST.stuID = SC.stuID group by courseID having AVG(score) > 70 and COUNT(*) > 2 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\347\275\221\345\220\247\350\256\241\350\264\271.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\347\275\221\345\220\247\350\256\241\350\264\271.sql" new file mode 100644 index 0000000..f659b22 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\347\275\221\345\220\247\350\256\241\350\264\271.sql" @@ -0,0 +1,80 @@ + +use TEXT +go + +create table tbl_card +( + ID varchar(20) primary key, + passWord nvarchar(15), + Balance varchar(50), + UseName nvarchar(5), +) + + +go +use TEXT +go +create table tbl_computer +( + ID varchar(10) primary key, + onUse int check(onUse = 0 or onUse = 1) default(1), + note varchar(10) +) + +go +use TEXT +go +create table tbl_record +( + ID nvarchar(10) primary key, + cardId varchar(20) references tbl_card(ID), + ComputerId varchar(10) references tbl_computer(ID), + beginTime datetime, + endTime datetime, + fee int +) +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885lg',600,'校庆'),('0089_EDE','zhang',134,'张峻') + +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'),('06',0,'688878'),('B01',0,'558558') +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23),(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6),(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6),(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',30),(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) +select * from tbl_card +select * from tbl_record +select * from tbl_computer +--1. 查询出用户名为'张军'的上网卡的上网记录,要求 显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select TC.ID 卡号,UseName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from tbl_card TC inner join tbl_record TE on TC.ID = TE.cardId where UseName = '张军' order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select SUM(fee)消费的总金额,COUNT(onUse)上网次数 from tbl_computer TP inner join tbl_record TR on TP.ID = TR.ComputerId where onUse = '1' + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId,SUM(fee)消费总金额 from tbl_record TR inner join tbl_card TC on TR.cardId = TC.ID group by cardId +--4. 查询出从未消费过的上网卡的 卡号 和 用户名 +select TC.ID 卡号,UseName 用户名 from tbl_card TC inner join tbl_record TR on TC.ID = TR.cardId +inner join tbl_computer TP on TP.ID = TR.ComputerId where onUse = 0 +--5. 将密码与用户名一样的上网卡信息查询出来 +select A.* from tbl_card A inner join tbl_card B on A.passWord = B.UseName + +--6. 查询出使用次数最多的机器号和使用次数 +select TC.ID,COUNT(onUse)使用次数 +from tbl_computer TC inner join tbl_record TR on TC.ID = TR.ComputerId GROUP BY TC.ID +--7. 查询出卡号是以'ABC'结尾的 卡号,用户名 ,上网的 机器号 和 消费金额 +select TP.ID 机器号,UseName 用户名,fee 消费金额 from tbl_computer TP inner join tbl_record TR on TP.ID = TR.ComputerId +inner join tbl_card TC on TC.ID = TR.cardId where cardId like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select TC.ID 卡号,UseName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from tbl_card TC inner join tbl_record TE on TC.ID = TE.cardId where DATEPART(dw,[beginTime]) in(0,1) +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select TC.ID 卡号,UseName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from tbl_card TC inner join tbl_record TE on TC.ID = TE.cardId where DATEDIFF(hh,beginTime,endTime) > 12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select TC.ID 卡号,UseName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from tbl_card TC inner join tbl_record TE on TC.ID = TE.cardId where fee < (select max(fee) from tbl_record) order by fee desc + + + -- Gitee From 161ff54909731f743910849ec76d71073405e023 Mon Sep 17 00:00:00 2001 From: BMxhd796815 <2396054158@qq.com> Date: Wed, 31 Mar 2021 22:27:16 +0800 Subject: [PATCH 112/195] first commit --- .../SQLQuery1.sql" | 122 ++++++++++++++++++ .../SQLQuery2.sql" | 115 +++++++++++++++++ 2 files changed, 237 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery1.sql" new file mode 100644 index 0000000..73624e2 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery1.sql" @@ -0,0 +1,122 @@ +use master +go +create database BIAO +on +( +name='BIAO', +filename='C:\SQL\BIAO.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='BIAO_log', +filename='C:\SQL\BIAO_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use BIAO +go +create table StuInfo +( +StuID int primary key not null, +StuName varchar(10) not null, +StuAge int not null, +StuSex varchar(2) check(StuSex='男' or StuSex='女') not null, +Time datetime +) +go +use BIAO +go +create table CourseInfo +( +CourseID int primary key not null, +CourseName varchar(10) not null, +CourseMarks int +) +go +use BIAO +go +create table ScoreInfo +( +ScoreID int primary key not null, +StuID int references StuInfo(StuID), +CourseID int references CourseInfo(CourseID), +Score int +) +go + +insert into StuInfo (StuID,StuName,StuAge,StuSex) values(1,'Tom','19','男') +insert into StuInfo (StuID,StuName,StuAge,StuSex) values(2,'Jack','20','女') +insert into StuInfo (StuID,StuName,StuAge,StuSex) values(3,'Rose','21','男') +insert into StuInfo (StuID,StuName,StuAge,StuSex) values(4,'Lulu','19','男') +insert into StuInfo (StuID,StuName,StuAge,StuSex) values(5,'Lili','21','女') +insert into StuInfo (StuID,StuName,StuAge,StuSex,Time) values(6,'Abc','20','男','2007-01-07 01:11:36.590') +select * from StuInfo + +insert into CourseInfo (CourseID,CourseName,CourseMarks) values(1,'JavaBase','4') +insert into CourseInfo (CourseID,CourseName,CourseMarks) values(2,'HTML','2') +insert into CourseInfo (CourseID,CourseName,CourseMarks) values(3,'JavaScript','2') +insert into CourseInfo (CourseID,CourseName,CourseMarks) values(4,'SqlBase','2') +select * from CourseInfo + +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(1,1,1,'80') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(2,1,2,'85') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(3,1,4,'50') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(4,2,1,'75') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(5,2,3,'45') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(6,2,4,'75') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(7,3,1,'45') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(8,4,1,'95') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(9,4,2,'75') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(10,4,3,'90') +insert into ScoreInfo (ScoreID,StuID,CourseID,Score) values(11,4,4,'45') +select * from ScoreInfo + + +--学生信息表(stuInfo) +select * from StuInfo +--课程信息表(courseInfo) +select * from CourseInfo +--分数信息表(scoreInfo) +select * from ScoreInfo +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select StuInfo.StuID 学生编号,StuInfo.StuName 姓名,count(CourseMarks) 课程数量,AVG(Score) 平均分 +from ScoreInfo,StuInfo,CourseInfo +where ScoreInfo.StuId=StuInfo.StuId and ScoreInfo.CourseId=CourseInfo.CourseId +group by StuInfo.StuID,StuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select CourseInfo.CourseID 课程编号,CourseInfo.CourseName 课程名称,count(ScoreInfo.StuID) 学生个数,SUM(Score) 总分 +from ScoreInfo,StuInfo,CourseInfo +where ScoreInfo.StuId=StuInfo.StuId and ScoreInfo.CourseId=CourseInfo.CourseId +group by CourseInfo.CourseID,CourseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo as A,stuInfo as B +where B.StuAge=A.StuAge and B.StuSex=A.StuSex and A.StuID!=B.StuID + +--4.查询出学分一样的课程信息 +select distinct A. * from courseInfo A,courseInfo B where A.CourseMarks=B.CourseMarks AND A.courseID!=B.courseID + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select StuInfo.StuID 学号,StuName 姓名,CourseInfo.CourseID 课程编号,Score 课程分数 +from ScoreInfo inner join CourseInfo on CourseInfo.CourseID=ScoreInfo.CourseID +inner join StuInfo on StuInfo.StuID=ScoreInfo.StuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select StuInfo.StuID 学号,CourseInfo.CourseID 课程编号,CourseName 课程名称,CourseMarks 课程学分,Score 分数 from ScoreInfo +inner join CourseInfo on CourseInfo.CourseID=ScoreInfo.CourseID +inner join StuInfo on StuInfo.StuID=ScoreInfo.StuID + +--7.查询出没有参加考试的学生的学号和姓名 +select StuInfo.StuID 学号,StuName 姓名 from StuInfo +left join ScoreInfo on StuInfo.StuID=ScoreInfo.StuID where Score is null + +--8.查询出姓名中有字母a的学生的信息 +select * from StuInfo where StuName like 'a%' + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery2.sql" new file mode 100644 index 0000000..e828608 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery2.sql" @@ -0,0 +1,115 @@ +use master +go +create database TBL +on +( +name='TBL', +filename='C:\SQL\TBL.mdf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +log on +( +name='TBL_log', +filename='C:\SQL\TBL_log.ldf', +size=10MB, +maxsize=100MB, +filegrowth=10MB +) +go +use TBL +go +create table CardInfo +( +ID varchar(50) primary key not null, --卡号 +PassWord varchar(30) not null, --密码 +Balance int not null, --卡上余额 +UserName varchar(10) not null --该上网卡所属的用户名 +) +go +use TBL +go +create table ComPuter +( +ID varchar(10) primary key not null, --机器编号 +OnUse varchar(2) check(OnUse='是' or OnUse='否') not null, --机器是否使用 +Note text --该机器说明 +) +go +use TBL +go +create table Record +( +ID int primary key not null, --记录编号 +CardID varchar(50) references CardInfo(ID), --本次上网的卡号 +ComPuterID varchar(10) references ComPuter(ID), --本次上网记录所使用的机器号 +BeginTime datetime, --本次上网记录的开始时间 +EndTime datetime, --本次上网记录的结束时间 +Fee int --本次上网的费用 +) + +insert into CardInfo(ID,PassWord,Balance,UserName) values('0023_ABC','555','98','张军') +insert into CardInfo(ID,PassWord,Balance,UserName) values('0025_bbd','abc','300','朱俊') +insert into CardInfo(ID,PassWord,Balance,UserName) values('0036_CCD','何柳','100','何柳') +insert into CardInfo(ID,PassWord,Balance,UserName) values('0045_YGR','0045_YGR','58','证验') +insert into CardInfo(ID,PassWord,Balance,UserName) values('0078_RJV','55885fg','600','校庆') +insert into CardInfo(ID,PassWord,Balance,UserName) values('0089_EDE','zhang','134','张峻') +select * from CardInfo + +insert into ComPuter(ID,OnUse,Note) values('02','否','25555') +insert into ComPuter(ID,OnUse,Note) values('03','是','55555') +insert into ComPuter(ID,OnUse,Note) values('04','否','66666') +insert into ComPuter(ID,OnUse,Note) values('05','是','88888') +insert into ComPuter(ID,OnUse,Note) values('06','否','688878') +insert into ComPuter(ID,OnUse,Note) values('B01','否','558558') +select * from ComPuter + +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23') +insert into Record(ID,CardID,ComPuterID,BeginTime,EndTime,Fee) values(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + + +--请完成以下题目: +--上网卡信息表 +select * from CardInfo +--网吧机器说明表 +select * from ComPuter +--上网记录表 +select * from Record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +--2. 查询出每台机器上的上网次数和消费的总金额 +select count(ComPuterID)上网次数,sum(fee)消费总金额 from Record group by ComPuterID + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select C.ID 卡号,SUM(R.Fee) 消费总金额 +from CardInfo C inner join Record R on C.ID=R.CardID +group by C.ID + +--4. 查询出从未消费过的上网卡的卡号和用户名 +--5. 将密码与用户名一样的上网卡信息查询出来 +select distinct A.* from CardInfo A , CardInfo B +where A.PassWord=B.UserName + +--6. 查询出使用次数最多的机器号和使用次数 +select * from Record +select top 1 ComPuterID 机器号 ,count(ComPuterID)使用次数 +from Record group by ComPuterID order by count(ComPuterID) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select C.ID 卡号,UserName 用户名, ComPuterID 机器号,Fee 消费金额 from CardInfo C +inner join Record R on C.ID=R.CardID where C.ID like '_____ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select CardID 卡号,UserName 用户名,ComPuterID 机器号,BeginTime 开始时间,EndTime 结束时间, Fee 消费金额 +from Record inner join CardInfo on CardInfo.ID=Record.CardID + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -- Gitee From 60f57d0f909cbcf8d38ab12673360af80ed72115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Wed, 31 Mar 2021 22:59:45 +0800 Subject: [PATCH 113/195] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20=E7=AC=AC?= =?UTF-8?q?=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/=E9=99=88?= =?UTF-8?q?=E6=B5=A9=E5=AE=87/SQLQuery2.sql=20=E4=B8=BA=20=E7=AC=AC?= =?UTF-8?q?=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/=E9=99=88?= =?UTF-8?q?=E6=B5=A9=E5=AE=87/SQLQuery11.1sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\231\210\346\265\251\345\256\207/SQLQuery11.1sql" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery2.sql" => "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery11.1sql" (100%) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery11.1sql" similarity index 100% rename from "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery2.sql" rename to "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery11.1sql" -- Gitee From 5326e0fde8f4bd6bb4121bf472fc8a067e083aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Wed, 31 Mar 2021 23:00:18 +0800 Subject: [PATCH 114/195] 1 --- .../SQLQuery11.2.sql" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery11.2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery11.2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery11.2.sql" new file mode 100644 index 0000000..2f75b5e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery11.2.sql" @@ -0,0 +1,88 @@ +create database tbl +go +use tbl +go + +create table tbl_card +( + id varchar(20) primary key, + passWord varchar(12), + balance money, + userName varchar(10) +) +insert into tbl_card values +('0023_ABC','555',99,'张军'), +('0025_bbd','abc',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'验证'), +('0078_RJV','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张俊') + +create table tbl_computer +( + id varchar(3) primary key, + onUse char(1) check(onUse in('1','0')), + note text +) + +insert into tbl_computer values +('02',0,'25555'), +('03',1,'55555'), +('04',0,'66666'), +('05',1,'888888'), +('06',0,'688878'), +('B01',0,'558558') + +create table tbl_record +( + id varchar(20) primary key , + cardId varchar(20) references tbl_card(id), + ComputerId varchar(3) references tbl_computer(id), + beginTime datetime, + endTime datetime, + fee money +) +insert into tbl_record values +('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +('47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), +('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select A.id 卡号,A.userName 用户名,B.beginTime 开始时间,B.endTime 结束时间,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId +where userName like '张军' order by fee DESC +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器编号,count(ComputerId) 上网次数,sum(fee) 消费总金额 from tbl_record group by ComputerId +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId 使用过卡号,sum(fee) 消费总金额 +from tbl_record group by cardId having count(cardId)>0 +--4. 查询出从未消费过的上网卡的卡号和用户名 +select A.id 卡号,A.userName 用户名 +from tbl_card A left join tbl_record B on B.cardId=A.id +where fee is null +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card where userName=passWord +select A.id,A.passWord,A.balance,A.userName from tbl_card A,tbl_card B +where A.userName=B.passWord +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId) 使用次数 from tbl_record +group by ComputerId order by count(ComputerId) DESC +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select A.userName 用户名,B.ComputerId 机器号,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId where A.id like '%ABC' +--8. 查询出是周六、周天上网的c记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select B.cardId 卡号,A.userName 用户名,B.ComputerId 机器号,B.beginTime 开始时间,B.endTime 结束时间,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId where datename(dw,B.beginTime)='星期六' or datename(dw,B.beginTime)='星期日' +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select B.cardId 卡号,A.userName 用户名,B.ComputerId 机器号,B.beginTime 开始时间,B.endTime 结束时间,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId where datediff(HOUR,B.beginTime,B.endTime)>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 B.cardId 卡号,A.userName 用户名,B.ComputerId 机器号,B.beginTime 开始时间,B.endTime 结束时间,B.fee 消费金额 +from tbl_card A join tbl_record B on A.id=B.cardId order by fee DESC \ No newline at end of file -- Gitee From 54be214568978601bc54d5adcf887851b9c28bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E6=A2=A6=E6=9E=97?= <2777141796@qq.com> Date: Wed, 31 Mar 2021 23:43:22 +0800 Subject: [PATCH 115/195] =?UTF-8?q?=E5=85=AB=E5=98=8E=E5=8E=8B=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5.sql" | 157 ++++++++++++++++++ .../SQLQuery6.sql" | 139 ++++++++++++++++ 2 files changed, 296 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" new file mode 100644 index 0000000..8b1db2b --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" @@ -0,0 +1,157 @@ +create database bbs + + + +on + +( + + name='bbs', + + filename='E:\bbs.mdf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +log on + +( + + name='bbs_log', + + filename='E:\bbs_log.ldf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +go + +use bbs + +go + + +--学生信息表 +create table stuInfo +( +stuID int primary key identity not null, +stuName varchar(20) not null, +stuAge int not null, +stuSex varchar(2) not null, +stutime varchar(20) +) +drop table stuInfo +insert into stuInfo +select '梦林',19,'男','NULL'union +select 'a海彪',20,'女','NULL'union +select '吴煌',21,'女','NULL'union +select '巧晶',19,'女','NULL'union +select '心怡',21,'女','NULL'union +select 'a坦克',20,'女','2017_01_07:11:36.590' + +select * from stuInfo + + +--课程表 +create table courseInfo +( +courseID int primary key identity not null, +courseName varchar(20) not null, +courseMarks int not null +) +drop table courseInfo +insert into courseInfo +select '语文',4 union +select '数学',2 union +select '英语',2 union +select 'SQL',2 + +select * from courseInfo + +--分数信息表 +create table scoreInfo +( +scoreID int primary key identity not null, +stuid int not null, +courseID int not null, +score int not null, +) + +insert into scoreInfo +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + +select * from scoreInfo +select * from stuInfo +select * from courseInfo + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select Y.stuName 姓名,M.courseName 科目,AVG(L.score) 平均分,count(M.courseMarks) 课程数量 from stuInfo Y inner join courseInfo M on Y.stuID=M.courseID inner join scoreInfo L on Y.stuID=L.stuid group by M.courseName,Y.stuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName 科目, count(M.stuID ) 学生人数, sum(score ) 总分 from courseInfo Y inner join stuInfo M ON Y.courseID=M.stuID inner join scoreInfo L on Y.courseID=L.courseID group by Y.courseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select * from stuInfo A,stuInfo B where A.stuAge =B.stuAge and A.stuSex=B.stuSex AND A.stuid!=B.stuid + + +--4.查询出学分一样的课程信息 +select * from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks AND A.courseid!=B.courseid + + + +select * from scoreInfo +--课程表 +select * from stuInfo +--学生表 +select * from courseInfo +--分数表 + + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select Y.stuid 学号,Y.stuName 姓名,L.courseID 课程号,M.score 分数 from stuInfo Y inner join scoreInfo M on Y.stuid = M.stuid inner join courseInfo L on Y.stuid =L.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select Y.stuid 学号,M.courseid 课程号,M.courseName 课程名, M.courseMarks 课程学分,L.score 分数 from stuInfo Y inner join courseInfo M on Y.stuid =M.courseid inner join scoreInfo L on Y.stuid = L.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuid,stuname from stuInfo left join scoreInfo on stuInfo.stuId=scoreInfo.stuid +where score is null +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like 'a%' + +--10.查询出选修了2门 课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select stuid 学号,avg(score)平均分,count(courseID)课程的数量 from scoreInfo group by stuid +having avg(score)>70 and count(courseID)>2 + + +select * from scoreInfo +--课程表 +select * from stuInfo +--学生表 +select * from courseInfo +--分数表 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" new file mode 100644 index 0000000..7e0b416 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" @@ -0,0 +1,139 @@ +create database dds + + + +on + +( + + name='dds', + + filename='E:\dds.mdf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +log on + +( + + name='dds_log', + + filename='E:\dds_log.ldf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +go + +use dds + +go +create table card --网卡信息表 +( + id varchar(30) primary key,--卡号,主键 + pasword varchar(30),--密码 + balance money,--卡上的余额 + userName varchar(50)--该上网卡所属的用户名 +) +create table computer --网吧机器说明表 +( + id varchar(30) primary key,--机器编号,主键 + onUse varchar(2) check(onUse=0 or onUse=1),--该机器是否正在使用,0为未使用,1为正在使用 + note ntext --该机器的说明 +) +create table record --上网记录表 +( + id varchar(30) primary key,--记录编号,主键 + cardId varchar(30) foreign key references card(id),--本次上网的卡号,外键 + ComputerId varchar(30) foreign key references computer(id),--本次上网记录所使用的机器号,外键 + beginTime datetime,--本次上网记录的开始时间 + endTime datetime,--本次上网记录的结束时间 + fee money --本次上网的费用 +) + +insert into card +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' + +select * from card + +insert into computer +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' + +select * from computer + +insert into record +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from record -- --上网记录表 +select * from computer --网吧机器说明表 +select * from card --网卡信息表 + + + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select card.id 卡号, card.userName 用户名 ,beginTime 开始时间,endTime 结束时间,fee 消费金额 from card inner join record on card.id=record.cardId where userName='张军' order by fee desc + + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 from record group by cardId,ComputerId + + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId 卡号,sum(record.fee) 消费总金额 from record group by cardId + + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select card.id 卡号 ,userName 用户名 from card left join record on card.id=record.cardId where fee is null group by userName,card.id + + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from card A,card B where A.pasword=B.userName + + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId)使用次数 from record group by ComputerId order By count(ComputerId) + + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 from record inner join card on record.cardId=card.id where record.cardId like '%ABC' + + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc + + -- Gitee From 3b542e38bd439d20e12c995a9001299585009bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E6=B5=B7=E5=BD=AA?= <3305448617@qq.com> Date: Wed, 31 Mar 2021 23:44:12 +0800 Subject: [PATCH 116/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 95 ++++++++++++++++ .../SQLQuery2.sql" | 107 ++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery1.sql" new file mode 100644 index 0000000..4752318 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery1.sql" @@ -0,0 +1,95 @@ +create database BAGA +on +( +name='BAGA', +filename='D:\BAGA.mdf', +size=500mb, +filegrowth=15%, +maxsize=15mb +) +log on +( +name='BAGA_log', +filename='D:\BAGA_log.ldf', +size=500mb, +filegrowth=15%, +maxsize=15mb +) +go +use BAGA +go + +create table tbl_card +( +id varchar(10) primary key not null, +passWord varchar(20) not null, +balance varchar(20) not null, +userName varchar(10) +) +create table tbl_computer +( +id varchar(10) primary key not null, +onUse int not null, +note text not null +) +create table tbl_record +( +id int primary key not null, +cardld varchar(10) foreign key references tbl_card(id), +ComputerId varchar(10) foreign key references tbl_computer(id), +beginTime datetime not null, +endTime datetime not null, +fee money not null +) +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_abe','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳'),('0045_YGR','0045_YGR',58,'验证'),('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张峻') + +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'),('06',0,'688878'),('B01',0,'558558') + + +insert into tbl_record values('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), + ('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), + ('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), + ('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), + ('47','0023_ABC','03','2006-12-23 15:26:00','2007-12-23 22:55:00','50'), + ('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), + ('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), + ('64','0045_Y...','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3...'), + ('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), + ('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') +select * from tbl_card 上网卡信息表 +select * from tbl_computer 网吧机器说明表 +select * from tbl_record 上网记录表 +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select cardld 卡号, userName 用户名, beginTime 开始时间, endTime 结束时间, fee 消费金额 from tbl_record inner join tbl_computer on tbl_computer.id=tbl_record.ComputerId + inner join tbl_card on cardld=tbl_card.id where userName='张军' order by fee + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId,COUNT(ComputerId) 上网次数,SUM(fee) 消费总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardld 网卡,SUM(fee) 消费总金额 from tbl_record group by cardld + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id 卡号,userName 用户名 from tbl_card where id not in (select cardld from tbl_record ) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card where passWord=userName +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号, count(ComputerId) 使用次数 from tbl_record group by ComputerId order by count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,fee 消费金额 from tbl_record inner join tbl_card on tbl_card.id=cardld where cardld like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record inner join tbl_card on tbl_card.id=cardld + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record inner join tbl_card on tbl_card.id=cardld + where datediff(HOUR,beginTime,endTime)>=12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record inner join tbl_card on tbl_card.id=cardld + order by fee desc + + + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery2.sql" new file mode 100644 index 0000000..38d2080 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery2.sql" @@ -0,0 +1,107 @@ +create database ATM +on +( +name='ATM', +filename='D:\ATM.mdf', +size=500mb, +filegrowth=15%, +maxsize=15mb +) +log on +( +name='ATM_log', +filename='D:\ATM_log.ldf', +size=500mb, +filegrowth=15%, +maxsize=15mb +) +go +use ATM +go + +create table stuInfo +( +stuId int primary key identity(1,1) not null, +stuName varchar(10) not null, +stuAge int not null, +stuSex varchar(2) not null, +time varchar(50) not null +) +insert into stuInfo +select '唐僧',19,'男','NULL' union +select '孙悟空',20,'女','NULL' union +select '猪八戒',21,'男','NULL' union +select '沙悟净',19,'男','NULL' union +select '白龙马',21,'女','NULL' union +select '如来佛',20,'男','2007-01-07 01:11:36.590' + +select * from stuInfo + +create table courseInfo +( +courseID int primary key not null, +courseName varchar(15) not null, +courseMarks int not null, +) +insert into courseInfo +select 1,'JavaB',4 union +select 2,'Html',2 union +select 3,'JavaS',2 union +select 4,'Sql',2 + +select * from courseInfo +create table scoreInfo +( +score int primary key not null, +stuID int not null, +courseID int not null, +score1 int not null +) +insert into scoreInfo +select 1,1,1,80 union +select 2,1,2,85 union +select 3,1,4,50 union +select 4,2,1,75 union +select 5,2,3,45 union +select 6,2,4,75 union +select 7,3,1,45 union +select 8,4,1,95 union +select 9,4,2,75 union +select 10,4,3,90 union +select 11,4,4,45 + +select * from scoreInfo +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuName,COUNT(courseID) 数量,AVG(score1) 平均分 from scoreInfo inner join stuInfo on scoreInfo.stuID = stuInfo.stuID +group by stuInfo.stuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName,COUNT(stuID) 学生个数,SUM(score1) 总分 from scoreInfo inner join courseInfo on courseInfo.courseID=scoreInfo.courseID +group by courseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select a.* from stuInfo A,stuInfo B where A.stuAge=B.stuAge and A.stuSex=B.stuSex and a.stuName != b.stuName + +--4.查询出学分一样的课程信息 +select a.courseName,a.courseMarks from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks and a.courseName != b.courseName +group by a.courseName,a.courseMarks + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuInfo.stuId,stuName,courseID 课程号,score1 分数 from stuInfo inner join scoreInfo on stuInfo.stuId=scoreInfo.courseID + + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuInfo.stuId,scoreInfo.courseID,courseInfo.courseName,courseInfo.courseMarks,score1 from stuInfo inner join scoreInfo on stuInfo.stuId=scoreInfo.courseID +inner join courseInfo on courseInfo.courseID=scoreInfo.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuId,stuName from stuInfo left join scoreInfo on stuInfo.stuId=scoreInfo.courseID +where score1 is null + +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuID,AVG(score1) 平均分,COUNT(courseID) 数量 from scoreInfo group by stuID having COUNT(courseID)>=2 AND AVG(score1)>70 -- Gitee From e37a40dd2e29033a0c1524fd3628832491637d1b Mon Sep 17 00:00:00 2001 From: huangziyi <3120130015@qq.com> Date: Thu, 1 Apr 2021 00:39:21 +0800 Subject: [PATCH 117/195] first commit --- .../\344\275\234\344\270\232\344\270\200.sql" | 113 +++++++++++++++++ .../\344\275\234\344\270\232\344\272\214.sql" | 114 ++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\344\275\234\344\270\232\344\270\200.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\344\275\234\344\270\232\344\272\214.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\344\275\234\344\270\232\344\270\200.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\344\275\234\344\270\232\344\270\200.sql" new file mode 100644 index 0000000..c3c416d --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\344\275\234\344\270\232\344\270\200.sql" @@ -0,0 +1,113 @@ +use master +go +create database xuesheng +on +( + name='xuesheng', + filename='C:\test\xuesheng.mdf', + size=10, + maxsize=200, + filegrowth=10% + ) + log on +( + name='xuesheng_log', + filename='C:\test\xuesheng_log.ldf', + size=10, + maxsize=200, + filegrowth=10% + ) + +create table students +( + stuID int primary key identity ( 1,1 ), + stuName nvarchar ( 20 ), + stuAge int, + stuSex nvarchar ( 2 ) check ( stuSex='1' or stuSex='0' ), + time datetime2 + ) + + insert into students(stuName,stuAge,stuSex) values ('Tom','19',1) + insert into students(stuName,stuAge,stuSex) values ('Jack','20',0) + insert into students(stuName,stuAge,stuSex) values ('Rose','21',1) + insert into students(stuName,stuAge,stuSex) values ('Lulu','19',1) + insert into students(stuName,stuAge,stuSex) values ('Lili','21',0) + insert into students(stuName,stuAge,stuSex,time) values ('abc','20',1,'2007-01-07 01:11:36.590') + + select * from students + +create table course +( + courseID int primary key identity ( 1,1 ), + courseName nvarchar(20), + courseMarks nvarchar(10) + ) + + insert into course(courseName,courseMarks) values ('JavaBase',4) + insert into course(courseName,courseMarks) values ('HTML',2) + insert into course(courseName,courseMarks) values ('JavaScript',2) + insert into course(courseName,courseMarks) values ('SqlBase',2) + + select * from course + +create table score +( + scoreID int primary key identity ( 1,1 ), + stuID int references students( stuID ), + courseID nvarchar(20), + score int + +) + + insert into score(stuID,courseID,score) values ('1','1','80') + insert into score(stuID,courseID,score) values ('1','2','85') + insert into score(stuID,courseID,score) values ('1','4','50') + insert into score(stuID,courseID,score) values ('2','1','75') + insert into score(stuID,courseID,score) values ('2','3','45') + insert into score(stuID,courseID,score) values ('2','4','75') + insert into score(stuID,courseID,score) values ('3','1','45') + insert into score(stuID,courseID,score) values ('4','1','95') + insert into score(stuID,courseID,score) values ('4','2','75') + insert into score(stuID,courseID,score) values ('4','3','90') + insert into score(stuID,courseID,score) values ('4','4','45') + + select * from score + +-- 有如图所示的三张表结构,学生信息表(students),课程信息表(course),分数信息表(score) + select * from students + select * from course + select * from score + +--题目: +--1.查询出 每个学生 所选修的课程的 数量 和 所选修的课程的 考试的 平均分 + select students.stuName,count(*) as 课程数量,avg(score.score) as 平均分 from students + inner join score on students.stuID=score.stuID group by students.stuName,score.score +--2.查询出 每门课程 的选修的 学生的个数 和 学生考试的总分 + select course.courseName, count(*), sum(score.score) from course + inner join score on course.courseID=score.courseID group by score.courseID,course.courseName +--3.查询出性别一样并且年龄一样的学生的信息 + select A. * from students A,students B + where A.stuSex=B.stuSex and A.stuAge=B.stuAge and A.stuID <> B.stuID +--4.查询出 学分一样 的课程信息 + select C. * from course C,course D + where C.courseMarks=D.courseMarks and C.courseName <> D.courseName +--5.查询出 参加了考试的 学生的学号,姓名,课程号和分数 + select students.stuID,students.stuName,score.courseID,score.score from students + right join score on students.stuID=score.stuID group by students.stuID,students.stuName,score.courseID,score.score +--6.查询出 参加了考试的 学生的学号,课程号,课程名,课程学分和分数 + select score.stuID,score.courseID,course.courseName,course.courseMarks,score.score from course + right join score on score.courseID=course.courseID group by score.stuID,score.courseID,course.courseName,course.courseMarks,score.score + +--7.查询出 没有参加考试的 学生的学号 和 姓名 + select students.stuID,students.stuName,score.score from students + left join score on students.stuID=score.stuID group by students.stuID,students.stuName,score.score + having score.score is null +--8.查询出是周六周天来报到的学生 + select stuName,time from students +--9.查询出姓名中有字母a的学生的信息 + select * from students + where stuName like '%a%' +--10.查询出 选修了 2门课程以上的 并且 考试平均分在70以上的 学生的 学号 和 考试平均分 以及 选修课程的 数量 + select score.stuID,avg(score.score) as 考试平均分,count(course.courseID) as 选修课程的数量 from course + inner join score on course.courseID=score.courseID group by score.stuID,score.score,course.courseID + having count(course.courseID)>2 and avg(score.score)>70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\344\275\234\344\270\232\344\272\214.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\344\275\234\344\270\232\344\272\214.sql" new file mode 100644 index 0000000..e628a71 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\344\275\234\344\270\232\344\272\214.sql" @@ -0,0 +1,114 @@ +use master +go + +create database internet +on +( + name='internet', + filename='C:\test\internet.mdf', + size=20, + maxsize=200, + filegrowth=10% + ) +log on +( + name='internet_log', + filename='C:\test\internet_log.ldf', + size=20, + maxsize=200, + filegrowth=10% + ) +go +use internet +go +create table tbl_card +( + id varchar(30) primary key , + passWord nvarchar(20) not null, + balance money, + userName varchar(30) +) +insert into tbl_card(ID,PassWord,Balance,UserName) values('0023_ABC','555','98','张军') +insert into tbl_card(ID,PassWord,Balance,UserName) values('0025_bbd','abc','300','朱俊') +insert into tbl_card(ID,PassWord,Balance,UserName) values('0036_CCD','何柳','100','何柳') +insert into tbl_card(ID,PassWord,Balance,UserName) values('0045_YGR','0045_YGR','58','证验') +insert into tbl_card(ID,PassWord,Balance,UserName) values('0078_RJV','55885fg','600','校庆') +insert into tbl_card(ID,PassWord,Balance,UserName) values('0089_EDE','zhang','134','张峻') + +select * from tbl_card + +create table tbl_computer +( + id varchar(30) primary key, + onUse int check (onUse='1' or onUse='0'), + note ntext +) +insert into tbl_computer values ('02','0','25555') +insert into tbl_computer values ('03','1','55555') +insert into tbl_computer values ('04','0','66666') +insert into tbl_computer values ('05','1','88888') +insert into tbl_computer values ('06','0','6888878') +insert into tbl_computer values ('B01','0','558558') + +create table tbl_record +( + id varchar(30) primary key , + cardId varchar(30) references tbl_card (id), + ComputerId varchar(30) references tbl_computer(id), + beginTime datetime2, + endTime datetime2, + fee money +) + +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20') +insert into tbl_record values(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23') +insert into tbl_record values(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50') +insert into tbl_record values(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6') +insert into tbl_record values(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50') +insert into tbl_record values(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6') +insert into tbl_record values(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50') +insert into tbl_record values(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30') +insert into tbl_record values(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23') +insert into tbl_record values(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') +--请完成以下题目: +select * from tbl_card +select * from tbl_computer +select * from tbl_record +--1. 查询出 用户名为'张军' 的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 + select tbl_record.ComputerId,tbl_record.cardId,tbl_card.userName,tbl_computer.id,tbl_record.beginTime,tbl_record.endTime,tbl_record.fee from tbl_record + inner join tbl_card on tbl_record.cardId=tbl_card.id + inner join tbl_computer on tbl_record.ComputerId=tbl_computer.id + where tbl_card.userName ='张军' +--2. 查询出 每台机器上 的 上网次数 和 消费的总金额 + select count(tbl_record.ComputerId) as 上网次数,sum(tbl_record.fee) as 消费的总金额 from tbl_computer + inner join tbl_record on tbl_record.ComputerId=tbl_computer.id + group by ComPuterID + +--3. 查询出 所有已经使用过的上网卡 的 消费总金额 + select tbl_card.ID 卡号,sum(tbl_record.fee) 消费总金额 from tbl_card + inner join tbl_record on tbl_card.ID=tbl_record.CardID + group by tbl_card.ID + +--4. 查询出 从未消费过的上网卡 的 卡号 和 用户名 + select * from tbl_record + right join tbl_card on tbl_record.ComputerId=tbl_card.id +--5. 将密码与用户名一样的上网卡信息查询出来 + select distinct A.* from tbl_card A , tbl_card B + where A.PassWord=B.UserName +--6. 查询出使用次数最多的机器号和使用次数 + select top 1 ComputerId 机器号 ,count(ComputerId)使用次数 from tbl_record + group by ComPuterID order by count(ComPuterID) desc +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + select tbl_card.ID 卡号,UserName 用户名, ComPuterID 机器号,Fee 消费金额 from tbl_card + inner join tbl_record on tbl_card.ID=tbl_record.CardID + where tbl_card.ID like '_____ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + select CardID 卡号,userName 用户名,ComPuterID 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 from tbl_record + inner join tbl_card on tbl_card.ID=tbl_record.CardID +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + + + + -- Gitee From 907f8e7b09e497ca3246f31e68d35f66a221757e Mon Sep 17 00:00:00 2001 From: heiiii <1390105108@qq.com> Date: Thu, 1 Apr 2021 10:10:53 +0800 Subject: [PATCH 118/195] 55 --- .../\351\231\210\346\227\255/SQLQuery1.sql" | 55 ++++++++++++ .../\351\231\210\346\227\255/SQLQuery2.sql" | 86 +++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery1.sql" new file mode 100644 index 0000000..00c8997 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery1.sql" @@ -0,0 +1,55 @@ +create database hh +go +use hh +go +create table stuInfo +( + stuID int primary key identity, + stuName nvarchar(8), + stuAge int, + stuSex nchar(2), + time datetime +) +create table courseInfo +( + courseID int primary key identity, + courseName nvarchar(12), + courseMarks int +) +create table scoreInfo +( + scoreID int primary key identity, + stuID int, + courseID int, + score int +) +insert into stuInfo(stuName,stuAge,stuSex,time) values ('Tom',19,'男',''),('Jack',20,'女',''),('Rose',21,'男',''), +('Lulu',19,'男',''),('Lili',21,'女',''),('abc',20,'男','2007-01-07 01:11:36.590') +insert into courseInfo values('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) +insert into scoreInfo 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) +select * from stuInfo +select * from courseInfo +select * from scoreInfo + +--1.查询出每个学生所选修的课程的数量 和 所选修的课程的考试的平均分 +select stuid,count(*)数量,avg(score) from scoreInfo group by stuid +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select c.courseid,count(*)数量,sum(s.score)总分 from courseInfo c inner join scoreInfo s on c.courseid=s.courseid group by c.courseid +--3.查询出性别一样并且年龄一样的学生的信息 +select a.* from stuInfo a, stuInfo b where a.stuage= b.stuage and a.stusex=b.stusex and a.stuid !=b.stuid +--4.查询出学分一样的课程信息 +select distinct a.* from courseInfo a, courseInfo b where a.courseMarks=b.courseMarks and a.coursename!=b.coursename +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select b.stuid,a.stuname,b.courseid,b.score from stuInfo a inner join scoreInfo b on a.stuid=b.stuid +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select s.stuid,c.courseid,c.coursename,c.courseMarks,s.score from courseInfo c inner join scoreInfo s on c.courseid=s.courseid +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuid,stuInfo.stuname from stuInfo left join scoreInfo on stuInfo.stuid= scoreInfo .stuid where score is null +select stuid,stuname from stuInfo where stuid not in (select stuid from scoreInfo group by stuid,courseid ) +--8.查询出是周六周天来报到的学生 +select stuname,time from stuInfo where time =CONVERT(datetime,time) group by time,stuname +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuname like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuid 学号 ,count(*) 数量 ,avg(score) 平均分 from scoreInfo group by stuid having count(*)>=2 and avg(score)>=70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" new file mode 100644 index 0000000..e3dd2ce --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" @@ -0,0 +1,86 @@ + +create database yyy +go +use yyy +go +create table tbl_card +( + ID varchar(20) primary key , + passWord nvarchar(10), + banlance int, + userName nvarchar(10), +) +create table tbl_computer +( + Id varchar(5) primary key , + onUse int , + note text, +) +create table tbl_record +( + ID int primary key , + cardId varchar(20) references tbl_card(ID), + ComputerId varchar(5) references tbl_computer(Id), + beginTime datetime, + endTime datetime, + fee int, +) + + +insert into tbl_card values('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'), +('0078_RJV','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张峻') +insert into tbl_computer values('02',0,'25555'), +('03',1,'55555'), +('04',0,'66666'), +('05',1,'88888'), +('06',0,'688878'), +('B01',0,'558558') +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) + + +select * from tbl_computer +select * from tbl_card +select * from tbl_record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select tbl_card.ID 卡号,tbl_card.userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID where tbl_card.userName='张军' order by fee DESC +--2. 查询出每台机器上的上网次数和消费的总金额 +select tbl_computer.Id,count(*)上网的次数,sum(fee)总金额 from tbl_record +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id group by tbl_computer.Id +--3. 查询出所有已经使用过的上网卡的消费总金额 +select tbl_record.cardId,sum(fee)总金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID group by tbl_record.cardId +--4. 查询出从未消费过的上网卡的卡号和用户名 +select ID 卡号,userName 用户名 from tbl_card where ID not in(select distinct cardId from tbl_record) +--5. 将密码与用户名一样的上网卡信息查询出来 +select A.* from tbl_card A ,tbl_card B where A.userName=B.passWord +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 tbl_record.ComputerId,count(*) 使用次数 from tbl_record +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id group by tbl_record.ComputerId order by count(*) DESC +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_card.ID 卡号,tbl_card.userName 用户名,tbl_computer.Id 上网的机器号,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id where tbl_card.ID like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.ID 上网的卡号,tbl_card.userName 用户名,tbl_computer.Id 机器号,beginTime 开始时间,endTime 结束时间,DATEDIFF(hh,beginTime,endTime) 相差的时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id where DATEDIFF(hh,beginTime,endTime)>12 +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 30 percent tbl_card.ID 上网的卡号,tbl_card.userName 用户名,tbl_computer.Id 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id order by fee DESC \ No newline at end of file -- Gitee From d3e790a41f5a1686e6c7c679a0d7d7758cbad37c Mon Sep 17 00:00:00 2001 From: yiQ <1325307033@qq.com> Date: Thu, 1 Apr 2021 10:13:44 +0800 Subject: [PATCH 119/195] 11 --- .../\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" | 1 + .../\351\203\255\350\211\272\346\263\211/SQLQuery2.sql" | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" new file mode 100644 index 0000000..7ef3091 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" @@ -0,0 +1 @@ +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) create database stu go use stu go create table stuInfo ( stuId int primary key identity, stuname nvarchar(20) , stuage int , stusex int check(stusex=1 or stusex=0), time datetime ) create table courseInfo ( courseid int primary key identity, couesename nvarchar(20) , cousrmarks int ) create table scoreInfo ( scoreid int primary key identity, stuid int, courseid int, score int ) insert into stuInfo 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 values ('javabase',4), ('html',2), ('javascript',2), ('sqlbase',2) insert into scoreInfo 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) select * from stuInfo --学生信息表 select * from courseInfo --科目表 select * from scoreInfo --成绩表 select * from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid --题目: --1.查询出 每个学生 所选修的 课程的数量 和所 选修的课程的考试的平均分 select stuname 学习, count(C.cousrmarks) 课程, avg(score) 平均分 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid group by stuname --2.查询出每门课程的选修的学生的个数和学生考试的总分 select C.couesename,count(S.stuId) 学生的个数,sum(O.score) 总分 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid group by C.couesename --3.查询出性别一样并且年龄一样的学生的信息 select stuage,stusex ,count(stuage),count(stusex) from stuInfo group by stuage,stusex having count(stuage)>1 and count(stusex) >1 select * from stuInfo where stuage in (select stuage from stuInfo group by stuage,stusex having count(stusex) >1) select * from stuInfo A , stuInfo B where A.stuage = B.stuage and A.stusex = B.stusex and A.stuname!=B.stuname --4.查询出学分一样的课程信息 select * from courseInfo where cousrmarks in (select cousrmarks from courseInfo group by cousrmarks having count(cousrmarks)>1) select * from courseInfo A ,courseInfo B where A.cousrmarks=B.cousrmarks and A.couesename!= B.couesename --5.查询出参加了考试的学生的学号,姓名,课程号和分数 select o.stuid 学号, stuname 姓名,o.courseid 课程号,o.score 分数 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid --6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 select o.stuid 学号, stuname 姓名,o.courseid 课程号,c.couesename 课程名,c.cousrmarks 课程学分,o.score 分数 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid --7.查询出没有参加考试的学生的学号和姓名 select * from stuInfo S left join scoreInfo O on S.stuId=O.stuid left join courseInfo C on O.courseid = C.courseid where c.couesename is null --8.查询出是周六周天来报到的学生 --9.查询出姓名中有字母a的学生的信息 select stuname from stuInfo where stuname like '%a%' --10.查询出选修了 2门课程以上 的并且 考试平均分在70 以上的 学生的学号和考试平均分以及选修课程的数量 select s.stuId, count(c.courseid) 选修课程的数量,avg(score) 考试平均分 from stuInfo S inner join scoreInfo O on S.stuId=O.stuid inner join courseInfo C on O.courseid = C.courseid group by s.stuId having count(c.courseid)>1 and avg(score)>70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery2.sql" new file mode 100644 index 0000000..a24b9b9 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery2.sql" @@ -0,0 +1,3 @@ +use master go --首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: create database internet go use internet go --表一为上网卡信息表(tbl_card) --id: 卡号,主键 --passWord:密码 --balance:卡上的余额 --userName:该上网卡所属的用户名 create table tbl_card ( ID nvarchar(10) primary key not null, PassWord nvarchar(10) not null, Balance nvarchar(10) not null, UserName nvarchar(10) not null ) insert into tbl_card values ('0023_ABC','555','98','张军'), ('0025_bbd','abe','300','朱俊'), ('0036_CDD','何柳','100','何柳'), ('0045_YGR','0045_YGR','58','证验'), ('0078_RJV','55885fg','600','校庆'), ('0089_EDE','zhang','134','张骏') --表2为网吧机器说明表(tbl_computer) --id:机器编号,主键 --onUse:该机器是否正在使用,0为未使用,1为正在使用 --note:该机器的说明 create table tbl_computer ( ID nvarchar(10) not null primary key, OnUse int check(OnUse=1 or OnUse=0) not null, Note int not null ) insert into tbl_computer values ('02',0,25555), ('03',1,25555), ('04',0,66666), ('05',1,88888), ('06',0,688878), ('B01',0,558558) --表3为上网记录表(tbl_record): --id:记录编号,主键 --cardId:本次上网的卡号,外键 --ComputerId:本次上网记录所使用的机器号,外键 --beginTime:本次上网记录的开始时间 --endTime:本次上网记录的结束时间 --fee:本次上网的费用 create table tbl_record ( ID nvarchar(20) primary key not null, CardID nvarchar(10) not null foreign key references tbl_card(ID), ComputerID nvarchar(10) not null foreign key (ComputerID) references tbl_computer(ID), BeignTime datetime not null, EndTime datetime not null, Fee int not null ) insert into tbl_record values (23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), (34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), (45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), (46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), (47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',60), (48,'0023_ABC','03','2007-01-06 15:26:00','2006-01-06 22:55:00',6), (55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), (64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), (65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), (98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) --请完成以下题目: select * from tbl_record --上网记录表(tbl_record) select* from tbl_computer --网吧机器说明表(tbl_computer) select * from tbl_card --上网卡信息表(tbl_card) select * from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID --1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额, --并按消费金额降序排列 select r.CardID 卡号,a.UserName 用户名,c.ID 机器编号,r.BeignTime 开始时间,r.EndTime 结束时间,r.Fee 消费金额 from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID where a.UserName='张军' --2. 查询出每台机器上的上网次数和消费的总金额 select C.ID 机器, count(c.OnUse) 上网次数, sum(r.Fee) 总金额 from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID group by C.ID, c.OnUse --3. 查询出所有已经使用过的上网卡的消费总金额 select r.CardID 上网卡,sum(r.Fee) 消费总金额 from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID group by r.CardID --4. 查询出从未消费过的上网卡的卡号和用户名 select a.ID 卡号,a.UserName 用户名 from tbl_record R right join tbl_computer C on r.ComputerID=c.ID right join tbl_card A on r.CardID=a.ID group by a.ID,r.Fee,a.UserName having r.Fee is null --5. 将密码与用户名一样的上网卡信息查询出来 select a.* from tbl_card a,tbl_card b where a.PassWord=b.UserName --6. 查询出使用次数最多的机器号和使用次数 select top 1 count(*) 使用次数,ComputerID 机器号 from tbl_record group by ComputerID order by count(*) desc --7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 select r.CardID,a.UserName,c.ID,r.Fee from tbl_record R inner join tbl_computer C on r.ComputerID=c.ID inner join tbl_card A on r.CardID=a.ID where a.ID like '%abc' --8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 --9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 --10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 select Fee , CardID,UserName , ComputerID,BeignTime , EndTime from tbl_record +inner join tbl_card on tbl_record.CardID=tbl_card.ID +where Fee not in (select top 3 fee from tbl_record order by fee DESC) \ No newline at end of file -- Gitee From 9681cf175ddb38c8789d8e0a26518a6dad638dbf Mon Sep 17 00:00:00 2001 From: hzt1993 <248875989@qq.com> Date: Thu, 1 Apr 2021 10:35:24 +0800 Subject: [PATCH 120/195] frist commit --- .../SQLQuery1.sql" | 83 ++++++++++++++++++ .../SQLQuery2.sql" | 84 +++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" new file mode 100644 index 0000000..08ec52f --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" @@ -0,0 +1,83 @@ +create database bbs +go +use bbs +go + +--学生信息表 +create table stuInfo +( + stuID int primary key identity, + stuName varchar(20), + stuAge int, + stuSex int, + time datetime, +) +--插入数据 +insert into stuInfo(stuName,stuAge,stuSex) values ('Tom',19,1),('Jack',20,0),('Rose',21,1), +('Lulu',19,1),('Lili',21,0) +insert into stuInfo(stuName,stuAge,stuSex,time) values ('abc',20,1,'2007-01-07 01:11:36.590') + +--课程信息表 +create table courseInfo +( + courseID int primary key identity, + courseName varchar(20), + courseMarks int, +) +insert into courseInfo values ('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) + +--分数信息表 +create table scoreInfo +( + scoreID int primary key identity, + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int , +) +insert into scoreInfo 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) + +select * from stuInfo +select * from courseInfo +select * from scoreInfo + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuInfo.stuID, count(*)课程数量,avg(score) 考试平均分 from stuInfo inner join scoreInfo +on stuInfo.stuID = scoreInfo.stuID group by stuInfo.stuID + +--2.查询出 每门课程的选修的学生的个数和学生考试的总分 +select scoreInfo.courseID,count(*)学生个数, sum(score)考试总分 from courseInfo inner join scoreInfo +on courseInfo.courseID = scoreInfo.courseID group by scoreInfo.courseID + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A,stuInfo B where A.stuSex=B.stuSex and A.stuAge=B.stuAge and A.stuID != B.stuID + +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks AND A.courseID !=B.courseID + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuInfo.stuID 学号,stuInfo.stuName 姓名,courseInfo.courseID 课程号,scoreInfo.score 分数 +from scoreInfo inner join stuInfo on stuInfo.stuID = scoreInfo.stuID +inner join courseInfo on courseInfo.courseID = scoreInfo.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuInfo.stuID 学号,stuInfo.stuName 姓名,courseInfo.courseID 课程号,courseInfo.courseName 课程名,courseInfo.courseMarks 课程学分, scoreInfo.score 分数 +from scoreInfo inner join stuInfo on stuInfo.stuID = scoreInfo.stuID +inner join courseInfo on courseInfo.courseID = scoreInfo.courseID + +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuID 学号,stuInfo.stuName 姓名 from scoreInfo right join stuInfo on scoreInfo.stuID=stuInfo.stuID +except +select stuInfo.stuID 学号,stuInfo.stuName 姓名 from scoreInfo +right join stuInfo on scoreInfo.stuID=stuInfo.stuID where score is not null + +--8.查询出是周六周天来报到的学生 + + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuInfo.stuID,stuInfo.stuName 姓名,count(*) 所选修的课程,avg(score)考试平均分 from scoreInfo +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID +inner join stuInfo on stuInfo.stuID=scoreInfo.stuID group by stuInfo.stuName , stuInfo.stuID having count(*)>2 and avg(score)>70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery2.sql" new file mode 100644 index 0000000..d30e32e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery2.sql" @@ -0,0 +1,84 @@ +create database HZT +go +use HZT +go +create table tbl_card +( + ID varchar(20) primary key , + passWord nvarchar(10), + banlance int, + userName nvarchar(10), +) +create table tbl_computer +( + Id varchar(5) primary key , + onUse int , + note text, +) +create table tbl_record +( + ID int primary key , + cardId varchar(20) references tbl_card(ID), + ComputerId varchar(5) references tbl_computer(Id), + beginTime datetime, + endTime datetime, + fee int, +) + +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abe',300,'朱俊'),('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'),('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张峻') +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'88888'), +('06',0,'688878'),('B01',0,'558558') +insert into tbl_record values(23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23) + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + + +--1.查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名, +--机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select tbl_card.ID 卡号,userName 用户名,computerId 机器编号,tbl_record.beginTime 开始时间, tbl_record.endTime 结束时间,tbl_record.fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId =tbl_card.ID where userName='张军' order by fee desc + +--2. 查询出 每台机器 上的上网次数和消费的总金额 +select tbl_computer.Id,count(*)上网的次数,sum(fee)总金额 from tbl_record +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id group by tbl_computer.Id + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select tbl_record.cardId,sum(fee)总金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID group by tbl_record.cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select ID 卡号,userName 用户名 from tbl_card + +-- 5. 将密码与用户名一样的上网卡信息查询出来 +select A.* from tbl_card A,tbl_card B where A.userName=B.passWord + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 tbl_record.ComputerId,count(*) 使用次数 from tbl_record +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id +group by tbl_record.ComputerId order by count(*) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_card.ID 卡号,tbl_card.userName 用户名,tbl_computer.Id 上网的机器号,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id where tbl_card.ID like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 30 percent tbl_card.ID 上网的卡号,tbl_card.userName 用户名,tbl_computer.Id 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record +inner join tbl_card on tbl_record.cardId=tbl_card.ID +inner join tbl_computer on tbl_record.ComputerId=tbl_computer.Id order by fee DESC \ No newline at end of file -- Gitee From 22c89a63657254fa3118db6e0130c5bbb9a0e14f Mon Sep 17 00:00:00 2001 From: adios <1347358158@qq.com> Date: Thu, 1 Apr 2021 11:08:31 +0800 Subject: [PATCH 121/195] =?UTF-8?q?=E6=A2=81=E4=B8=96=E8=B4=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery2.sql" | 118 +++++++++++++++ .../SQLQuery3.sql" | 141 ++++++++++++++++++ 2 files changed, 259 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery3.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" new file mode 100644 index 0000000..aba6bdd --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" @@ -0,0 +1,118 @@ +use master +go + +create database student +on primary +( +name='student', +filename='D:\.mdf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +log on +( +name='student_log', +filename='D:\_log.ldf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +go + +use student +--创建学生信息表 +create table stuInfo +( +stuId int primary key identity, +stuName varchar(10) not null, +stuAge varchar(6) not null, +stuSex nvarchar(1) not null check(stuSex=1 or stuSex=0), +time datetime +) +go + +--创建课程信息表 +create table courseInfo +( +courseId int primary key identity, +courseName varchar(10) not null, +couorseMarks int +) +go + +--创建分数信息表 +create table scoreInfo +( +scorsId int primary key identity, +stuId int not null, +courseId int not null, +score int +) +go + +select * from stuInfo + +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') + + +select * from courseInfo + +insert into courseInfo(courseName,couorseMarks) values ('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) + +select * from scoreInfo + +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) + +--题目: +select * from stuInfo +select * from courseInfo +select * from scoreInfo +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 + +select s3.stuId,couorseMarks 课程数量,avg(score) 平均分 from courseInfo s1 inner join scoreInfo s2 on s1.courseId=s2.courseId +inner join stuInfo s3 on s3.stuId=s2.stuId +group by s3.stuId,couorseMarks order by s3.stuId +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + +select s1.courseId,sum(stuId) 人数,sum(score) 总分 from courseInfo s1 inner join scoreInfo s2 on s1.courseId=s2.courseId group by s1.courseId + +--3.查询出性别一样并且年龄一样的学生的信息 + +select s1.* from stuInfo s1,stuInfo s2 where s1.stuAge=s2.stuAge and s1.stuSex=s2.stuSex and s1.stuId!=s2.stuId + +--4.查询出学分一样的课程信息 + +select s1.* from scoreInfo s1,scoreInfo s2 where s1.score=s2.score and s1.stuId!=s2.stuId + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +select s1.stuId 学号,s1.stuName 姓名,s2.scorsId,s2.score from stuInfo s1 left join scoreInfo s2 on s1.stuId=s2.stuId + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +select s1.stuId,s2.courseId,s2.courseName,s2.couorseMarks,s1.score from scoreInfo s1,courseInfo s2 +--7.查询出没有参加考试的学生的学号和姓名 + +select * from stuInfo s1 where s1.stuId not in (select s2.stuId from scoreInfo s2) + +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 + +select * from stuInfo s1 where s1.stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select s1.stuId,avg(s1.score),count(s1.courseId) from scoreInfo s1 group by s1.stuId having avg(s1.score)>70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery3.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery3.sql" new file mode 100644 index 0000000..bb8fffe --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery3.sql" @@ -0,0 +1,141 @@ +use master +go + +create database wb +on primary +( +name='wb', +filename='D:\.mdf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +log on +( +name='wb_log', +filename='D:\_log.ldf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +go + +use wb + +--表一为上网卡信息表(tbl_card) +--id: 卡号,主键 +--passWord:密码 +--balance:卡上的余额 +--userName:该上网卡所属的用户名 + +create table tbl_card +( +id varchar(10) primary key, +passWord varchar(18) not null, +balance varchar(20) not null, +userName varchar(16) +) +go + +--表2为网吧机器说明表(tbl_computer) +--id:机器编号,主键 +--onUse:该机器是否正在使用,0为未使用,1为正在使用 +--note:该机器的说明 + +create table tbl_computer +( +id varchar(6) primary key, +onUse varchar(1) check(onUse=0 or onUse=1), +note varchar(100) +) +go + +--表3为上网记录表(tbl_record): +--id:记录编号,主键 +--cardId:本次上网的卡号,外键 +--ComputerId:本次上网记录所使用的机器号,外键 +--beginTime:本次上网记录的开始时间 +--endTime:本次上网记录的结束时间 +--fee:本次上网的费用 + +create table tbl_record +( +id varchar(2) primary key , +cardId varchar(10) foreign key(cardId) references tbl_card(id), +ComputerId varchar(6) foreign key(ComputerId) references tbl_computer(id), +beginTime datetime, +endTime datetime, +fee int +) +go + +insert into tbl_card(id,passWord,balance,userName) values +('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'), +('0036_DDD0','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'), +('0078_RJV','zhang',134,'张俊') + +insert into tbl_computer values +('02',0,25555), +('03',1,55555), +('04',0,66666), +('05',1,88888), +('06',0,688878), +('B01',0,558558) + +insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values +(23,'0078_RJV','B01','2007-07-15 19:00:00.000','2007-07-15 21:00:00.000',20), +(34,'0025_bbd','02','2006-12-25 18:00:00.000','2006-12-25 22:00:00.000',23), +(45,'0023_ABC','03','2006-12-23 15:26:00.000','2006-12-23 22:55:00.000',50), +(46,'0023_ABC','03','2006-12-22 15:26:00.000','2006-12-22 22:55:00.000',6), +(47,'0023_ABC','03','2006-12-23 15:26:00.000','2006-12-23 22:55:00.000',50), +(48,'0023_ABC','03','2007-01-06 15:26:00.000','2007-01-06 22:55:00.000',6), +(55,'0023_ABC','03','2006-07-21 15:26:00.000','2007-07-21 22:55:00.000',50), +(64,'0045_YGR','04','2006-12-24 18:00:00.000','2006-12-24 22:00:00.000',30), +(65,'0025_bbd','02','2006-12-28 18:00:00.000','2006-12-28 22:00:00.000',23), +(98,'0025_bbd','02','2006-12-26 18:00:00.000','2006-12-26 22:00:00.000',23) + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 + +select s2.cardId,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s1.userName='张军' and s2.cardId='0023_ABC' + +--2. 查询出每台机器上的上网次数和消费的总金额 + +select s1.ComputerId,count(s1.ComputerId) 上网次数,sum(s1.fee) 总金额 from tbl_record s1 group by s1.ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 + +select s1.cardId,sum(s1.fee) 总消费 from tbl_record s1 group by s1.cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 + +select s1.id,s1.userName from tbl_card s1 where s1.id not in (select s2.cardId from tbl_record s2) + +--5. 将密码与用户名一样的上网卡信息查询出来 + +select * from tbl_card s1 where s1.passWord=s1.userName + +--6. 查询出使用次数最多的机器号和使用次数 + +select top 1 s1.ComputerId,count(s1.ComputerId) 使用次数 from tbl_record s1 group by s1.ComputerId order by count(s1.ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + +select s1.userName,s2.ComputerId,s2.fee from tbl_card s1,tbl_record s2 where s1.id like'%ABC' and s1.id=s2.cardId + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + + + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select s1.id,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s2.endTime-s2.beginTime>12 and s1.id=s2.cardId + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select top 3 s1.id,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s1.id=s2.cardId order by s2.fee desc -- Gitee From 1bb4d042f85104fc97452a7fa8ac71f070701774 Mon Sep 17 00:00:00 2001 From: adios <1347358158@qq.com> Date: Thu, 1 Apr 2021 11:08:37 +0800 Subject: [PATCH 122/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/SQLQuery?= =?UTF-8?q?2.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery2.sql" | 118 ------------------ 1 file changed, 118 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" deleted file mode 100644 index aba6bdd..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery2.sql" +++ /dev/null @@ -1,118 +0,0 @@ -use master -go - -create database student -on primary -( -name='student', -filename='D:\.mdf', -size=5MB, -filegrowth=1MB, -maxsize=5MB -) -log on -( -name='student_log', -filename='D:\_log.ldf', -size=5MB, -filegrowth=1MB, -maxsize=5MB -) -go - -use student ---创建学生信息表 -create table stuInfo -( -stuId int primary key identity, -stuName varchar(10) not null, -stuAge varchar(6) not null, -stuSex nvarchar(1) not null check(stuSex=1 or stuSex=0), -time datetime -) -go - ---创建课程信息表 -create table courseInfo -( -courseId int primary key identity, -courseName varchar(10) not null, -couorseMarks int -) -go - ---创建分数信息表 -create table scoreInfo -( -scorsId int primary key identity, -stuId int not null, -courseId int not null, -score int -) -go - -select * from stuInfo - -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') - - -select * from courseInfo - -insert into courseInfo(courseName,couorseMarks) values ('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) - -select * from scoreInfo - -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) - ---题目: -select * from stuInfo -select * from courseInfo -select * from scoreInfo ---1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 - -select s3.stuId,couorseMarks 课程数量,avg(score) 平均分 from courseInfo s1 inner join scoreInfo s2 on s1.courseId=s2.courseId -inner join stuInfo s3 on s3.stuId=s2.stuId -group by s3.stuId,couorseMarks order by s3.stuId ---2.查询出每门课程的选修的学生的个数和学生考试的总分 - -select s1.courseId,sum(stuId) 人数,sum(score) 总分 from courseInfo s1 inner join scoreInfo s2 on s1.courseId=s2.courseId group by s1.courseId - ---3.查询出性别一样并且年龄一样的学生的信息 - -select s1.* from stuInfo s1,stuInfo s2 where s1.stuAge=s2.stuAge and s1.stuSex=s2.stuSex and s1.stuId!=s2.stuId - ---4.查询出学分一样的课程信息 - -select s1.* from scoreInfo s1,scoreInfo s2 where s1.score=s2.score and s1.stuId!=s2.stuId - ---5.查询出参加了考试的学生的学号,姓名,课程号和分数 - -select s1.stuId 学号,s1.stuName 姓名,s2.scorsId,s2.score from stuInfo s1 left join scoreInfo s2 on s1.stuId=s2.stuId - ---6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 - -select s1.stuId,s2.courseId,s2.courseName,s2.couorseMarks,s1.score from scoreInfo s1,courseInfo s2 ---7.查询出没有参加考试的学生的学号和姓名 - -select * from stuInfo s1 where s1.stuId not in (select s2.stuId from scoreInfo s2) - ---8.查询出是周六周天来报到的学生 - ---9.查询出姓名中有字母a的学生的信息 - -select * from stuInfo s1 where s1.stuName like '%a%' - ---10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 - -select s1.stuId,avg(s1.score),count(s1.courseId) from scoreInfo s1 group by s1.stuId having avg(s1.score)>70 \ No newline at end of file -- Gitee From f749318396a18b6009f2cacfcab33f5e6f5ee42a Mon Sep 17 00:00:00 2001 From: adios <1347358158@qq.com> Date: Thu, 1 Apr 2021 11:08:43 +0800 Subject: [PATCH 123/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/SQLQuery?= =?UTF-8?q?3.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery3.sql" | 141 ------------------ 1 file changed, 141 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery3.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery3.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery3.sql" deleted file mode 100644 index bb8fffe..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery3.sql" +++ /dev/null @@ -1,141 +0,0 @@ -use master -go - -create database wb -on primary -( -name='wb', -filename='D:\.mdf', -size=5MB, -filegrowth=1MB, -maxsize=5MB -) -log on -( -name='wb_log', -filename='D:\_log.ldf', -size=5MB, -filegrowth=1MB, -maxsize=5MB -) -go - -use wb - ---表一为上网卡信息表(tbl_card) ---id: 卡号,主键 ---passWord:密码 ---balance:卡上的余额 ---userName:该上网卡所属的用户名 - -create table tbl_card -( -id varchar(10) primary key, -passWord varchar(18) not null, -balance varchar(20) not null, -userName varchar(16) -) -go - ---表2为网吧机器说明表(tbl_computer) ---id:机器编号,主键 ---onUse:该机器是否正在使用,0为未使用,1为正在使用 ---note:该机器的说明 - -create table tbl_computer -( -id varchar(6) primary key, -onUse varchar(1) check(onUse=0 or onUse=1), -note varchar(100) -) -go - ---表3为上网记录表(tbl_record): ---id:记录编号,主键 ---cardId:本次上网的卡号,外键 ---ComputerId:本次上网记录所使用的机器号,外键 ---beginTime:本次上网记录的开始时间 ---endTime:本次上网记录的结束时间 ---fee:本次上网的费用 - -create table tbl_record -( -id varchar(2) primary key , -cardId varchar(10) foreign key(cardId) references tbl_card(id), -ComputerId varchar(6) foreign key(ComputerId) references tbl_computer(id), -beginTime datetime, -endTime datetime, -fee int -) -go - -insert into tbl_card(id,passWord,balance,userName) values -('0023_ABC','555',98,'张军'), -('0025_bbd','abe',300,'朱俊'), -('0036_DDD0','何柳',100,'何柳'), -('0045_YGR','0045_YGR',58,'证验'), -('0078_RJV','zhang',134,'张俊') - -insert into tbl_computer values -('02',0,25555), -('03',1,55555), -('04',0,66666), -('05',1,88888), -('06',0,688878), -('B01',0,558558) - -insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values -(23,'0078_RJV','B01','2007-07-15 19:00:00.000','2007-07-15 21:00:00.000',20), -(34,'0025_bbd','02','2006-12-25 18:00:00.000','2006-12-25 22:00:00.000',23), -(45,'0023_ABC','03','2006-12-23 15:26:00.000','2006-12-23 22:55:00.000',50), -(46,'0023_ABC','03','2006-12-22 15:26:00.000','2006-12-22 22:55:00.000',6), -(47,'0023_ABC','03','2006-12-23 15:26:00.000','2006-12-23 22:55:00.000',50), -(48,'0023_ABC','03','2007-01-06 15:26:00.000','2007-01-06 22:55:00.000',6), -(55,'0023_ABC','03','2006-07-21 15:26:00.000','2007-07-21 22:55:00.000',50), -(64,'0045_YGR','04','2006-12-24 18:00:00.000','2006-12-24 22:00:00.000',30), -(65,'0025_bbd','02','2006-12-28 18:00:00.000','2006-12-28 22:00:00.000',23), -(98,'0025_bbd','02','2006-12-26 18:00:00.000','2006-12-26 22:00:00.000',23) - -select * from tbl_card -select * from tbl_computer -select * from tbl_record - ---1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 - -select s2.cardId,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s1.userName='张军' and s2.cardId='0023_ABC' - ---2. 查询出每台机器上的上网次数和消费的总金额 - -select s1.ComputerId,count(s1.ComputerId) 上网次数,sum(s1.fee) 总金额 from tbl_record s1 group by s1.ComputerId - ---3. 查询出所有已经使用过的上网卡的消费总金额 - -select s1.cardId,sum(s1.fee) 总消费 from tbl_record s1 group by s1.cardId - ---4. 查询出从未消费过的上网卡的卡号和用户名 - -select s1.id,s1.userName from tbl_card s1 where s1.id not in (select s2.cardId from tbl_record s2) - ---5. 将密码与用户名一样的上网卡信息查询出来 - -select * from tbl_card s1 where s1.passWord=s1.userName - ---6. 查询出使用次数最多的机器号和使用次数 - -select top 1 s1.ComputerId,count(s1.ComputerId) 使用次数 from tbl_record s1 group by s1.ComputerId order by count(s1.ComputerId) desc - ---7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 - -select s1.userName,s2.ComputerId,s2.fee from tbl_card s1,tbl_record s2 where s1.id like'%ABC' and s1.id=s2.cardId - ---8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - - - ---9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - -select s1.id,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s2.endTime-s2.beginTime>12 and s1.id=s2.cardId - ---10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - -select top 3 s1.id,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s1.id=s2.cardId order by s2.fee desc -- Gitee From 53cd7820222c33dbf8a9eae5ff4edd82cade60a2 Mon Sep 17 00:00:00 2001 From: adios <1347358158@qq.com> Date: Thu, 1 Apr 2021 11:08:51 +0800 Subject: [PATCH 124/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E6=A2=81=E4=B8=96?= =?UTF-8?q?=E8=B4=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\346\242\201\344\270\226\350\264\244/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/.keep" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/.keep" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 2206302ce1584bf6b4f2c96615ebd11c637dcc87 Mon Sep 17 00:00:00 2001 From: adios <1347358158@qq.com> Date: Thu, 1 Apr 2021 11:09:22 +0800 Subject: [PATCH 125/195] =?UTF-8?q?=E6=A2=81=E4=B8=96=E8=B4=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery2.sql" | 118 +++++++++++++++ .../SQLQuery3.sql" | 141 ++++++++++++++++++ 2 files changed, 259 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery2.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery3.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery2.sql" new file mode 100644 index 0000000..aba6bdd --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery2.sql" @@ -0,0 +1,118 @@ +use master +go + +create database student +on primary +( +name='student', +filename='D:\.mdf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +log on +( +name='student_log', +filename='D:\_log.ldf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +go + +use student +--创建学生信息表 +create table stuInfo +( +stuId int primary key identity, +stuName varchar(10) not null, +stuAge varchar(6) not null, +stuSex nvarchar(1) not null check(stuSex=1 or stuSex=0), +time datetime +) +go + +--创建课程信息表 +create table courseInfo +( +courseId int primary key identity, +courseName varchar(10) not null, +couorseMarks int +) +go + +--创建分数信息表 +create table scoreInfo +( +scorsId int primary key identity, +stuId int not null, +courseId int not null, +score int +) +go + +select * from stuInfo + +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') + + +select * from courseInfo + +insert into courseInfo(courseName,couorseMarks) values ('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) + +select * from scoreInfo + +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) + +--题目: +select * from stuInfo +select * from courseInfo +select * from scoreInfo +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 + +select s3.stuId,couorseMarks 课程数量,avg(score) 平均分 from courseInfo s1 inner join scoreInfo s2 on s1.courseId=s2.courseId +inner join stuInfo s3 on s3.stuId=s2.stuId +group by s3.stuId,couorseMarks order by s3.stuId +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + +select s1.courseId,sum(stuId) 人数,sum(score) 总分 from courseInfo s1 inner join scoreInfo s2 on s1.courseId=s2.courseId group by s1.courseId + +--3.查询出性别一样并且年龄一样的学生的信息 + +select s1.* from stuInfo s1,stuInfo s2 where s1.stuAge=s2.stuAge and s1.stuSex=s2.stuSex and s1.stuId!=s2.stuId + +--4.查询出学分一样的课程信息 + +select s1.* from scoreInfo s1,scoreInfo s2 where s1.score=s2.score and s1.stuId!=s2.stuId + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +select s1.stuId 学号,s1.stuName 姓名,s2.scorsId,s2.score from stuInfo s1 left join scoreInfo s2 on s1.stuId=s2.stuId + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +select s1.stuId,s2.courseId,s2.courseName,s2.couorseMarks,s1.score from scoreInfo s1,courseInfo s2 +--7.查询出没有参加考试的学生的学号和姓名 + +select * from stuInfo s1 where s1.stuId not in (select s2.stuId from scoreInfo s2) + +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 + +select * from stuInfo s1 where s1.stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select s1.stuId,avg(s1.score),count(s1.courseId) from scoreInfo s1 group by s1.stuId having avg(s1.score)>70 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery3.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery3.sql" new file mode 100644 index 0000000..bb8fffe --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery3.sql" @@ -0,0 +1,141 @@ +use master +go + +create database wb +on primary +( +name='wb', +filename='D:\.mdf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +log on +( +name='wb_log', +filename='D:\_log.ldf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +go + +use wb + +--表一为上网卡信息表(tbl_card) +--id: 卡号,主键 +--passWord:密码 +--balance:卡上的余额 +--userName:该上网卡所属的用户名 + +create table tbl_card +( +id varchar(10) primary key, +passWord varchar(18) not null, +balance varchar(20) not null, +userName varchar(16) +) +go + +--表2为网吧机器说明表(tbl_computer) +--id:机器编号,主键 +--onUse:该机器是否正在使用,0为未使用,1为正在使用 +--note:该机器的说明 + +create table tbl_computer +( +id varchar(6) primary key, +onUse varchar(1) check(onUse=0 or onUse=1), +note varchar(100) +) +go + +--表3为上网记录表(tbl_record): +--id:记录编号,主键 +--cardId:本次上网的卡号,外键 +--ComputerId:本次上网记录所使用的机器号,外键 +--beginTime:本次上网记录的开始时间 +--endTime:本次上网记录的结束时间 +--fee:本次上网的费用 + +create table tbl_record +( +id varchar(2) primary key , +cardId varchar(10) foreign key(cardId) references tbl_card(id), +ComputerId varchar(6) foreign key(ComputerId) references tbl_computer(id), +beginTime datetime, +endTime datetime, +fee int +) +go + +insert into tbl_card(id,passWord,balance,userName) values +('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'), +('0036_DDD0','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'证验'), +('0078_RJV','zhang',134,'张俊') + +insert into tbl_computer values +('02',0,25555), +('03',1,55555), +('04',0,66666), +('05',1,88888), +('06',0,688878), +('B01',0,558558) + +insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values +(23,'0078_RJV','B01','2007-07-15 19:00:00.000','2007-07-15 21:00:00.000',20), +(34,'0025_bbd','02','2006-12-25 18:00:00.000','2006-12-25 22:00:00.000',23), +(45,'0023_ABC','03','2006-12-23 15:26:00.000','2006-12-23 22:55:00.000',50), +(46,'0023_ABC','03','2006-12-22 15:26:00.000','2006-12-22 22:55:00.000',6), +(47,'0023_ABC','03','2006-12-23 15:26:00.000','2006-12-23 22:55:00.000',50), +(48,'0023_ABC','03','2007-01-06 15:26:00.000','2007-01-06 22:55:00.000',6), +(55,'0023_ABC','03','2006-07-21 15:26:00.000','2007-07-21 22:55:00.000',50), +(64,'0045_YGR','04','2006-12-24 18:00:00.000','2006-12-24 22:00:00.000',30), +(65,'0025_bbd','02','2006-12-28 18:00:00.000','2006-12-28 22:00:00.000',23), +(98,'0025_bbd','02','2006-12-26 18:00:00.000','2006-12-26 22:00:00.000',23) + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 + +select s2.cardId,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s1.userName='张军' and s2.cardId='0023_ABC' + +--2. 查询出每台机器上的上网次数和消费的总金额 + +select s1.ComputerId,count(s1.ComputerId) 上网次数,sum(s1.fee) 总金额 from tbl_record s1 group by s1.ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 + +select s1.cardId,sum(s1.fee) 总消费 from tbl_record s1 group by s1.cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 + +select s1.id,s1.userName from tbl_card s1 where s1.id not in (select s2.cardId from tbl_record s2) + +--5. 将密码与用户名一样的上网卡信息查询出来 + +select * from tbl_card s1 where s1.passWord=s1.userName + +--6. 查询出使用次数最多的机器号和使用次数 + +select top 1 s1.ComputerId,count(s1.ComputerId) 使用次数 from tbl_record s1 group by s1.ComputerId order by count(s1.ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + +select s1.userName,s2.ComputerId,s2.fee from tbl_card s1,tbl_record s2 where s1.id like'%ABC' and s1.id=s2.cardId + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + + + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select s1.id,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s2.endTime-s2.beginTime>12 and s1.id=s2.cardId + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select top 3 s1.id,s1.userName,s2.ComputerId,s2.beginTime,s2.endTime,s2.fee from tbl_card s1,tbl_record s2 where s1.id=s2.cardId order by s2.fee desc -- Gitee From 204cae8a3210159d943da5e3c4ce883a541c6381 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 1 Apr 2021 11:21:37 +0800 Subject: [PATCH 126/195] 11 --- .../\350\203\241\350\266\212/1.sql" | 105 ++++++++++++++++ .../\350\203\241\350\266\212/2.sql" | 119 ++++++++++++++++++ 2 files changed, 224 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/1.sql" new file mode 100644 index 0000000..a1ebcd3 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/1.sql" @@ -0,0 +1,105 @@ +create database scs +on +( + name='scs', + filename='D:\scs.mdf' +) + +log on +( + name='scs_log', + filename='D:\scs_log.ldf' +) + +use scs +go + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +create table stuInfo( + stuID int primary key identity(1,1), + stuName varchar(20) not null, + stuAge int not null, + stuSex int check(stuSex=1 or stuSex=0 ) not null, + time datetime +) + +insert into stuInfo 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') + +select * from stuInfo + +create table courseInfo( + courseID int primary key identity(1,1), + courseName varchar(20) not null, + courseMarks int not null +) + +insert into courseInfo values +('JavaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) + +select * from courseInfo + +create table scoreInfo( + scoreID int primary key identity(1,1), + stuID int references stuInfo(stuID) not null, + courseID int references courseInfo(courseID) not null, + score int not null +) + +insert into scoreInfo 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) + +select * from stuInfo +select * from courseInfo +select * from scoreInfo + + +--1.查询出 每个学生 和所选修的课程的考试的平均分所选修的课程的数量 +select stuName,count(distinct courseID),AVG(score) from scoreInfo,stuInfo +where scoreInfo.stuID=stuInfo.stuID group by stuName + +select stuName,count(distinct courseID),AVG(score) from scoreInfo +right join stuInfo on scoreInfo.stuID=stuInfo.stuID +group by stuName + +select stuID 姓名,count(courseID) 课程数量,AVG(score) 平均分 from scoreInfo group by stuID +--2.查询出 每门课程 的 选修的学生的个数和学生考试的总分 +select courseName,count(distinct stuID),sum(score) from scoreInfo +right join courseInfo on scoreInfo.courseID=courseInfo.courseID +group by courseName + +select courseID 课程,count(stuID) 学生个数,sum(score) 总分 from scoreInfo group by courseID +--3.查询出性别一样并且年龄一样的学生的信息 +select A.stuSex,A.stuAge, B.stuName,B.time from stuInfo A inner join stuInfo B on A.stuID=B.stuID WHERE A.stuSex=B.stuSex AND A.stuAge=B.stuAge +--4.查询出学分一样的课程信息 +select DISTINCT A.* from courseInfo A inner join courseInfo B on A.courseMarks=B.courseMarks WHERE A.courseName!=B.courseName +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select S.stuID,T.stuName,S.courseID,S.score from scoreInfo S inner join stuInfo T on S.stuID=T.stuID +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select S.stuID,C.courseID,C.courseName,C.courseMarks,S.score from scoreInfo S inner join courseInfo C on S.courseID=C.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select * from stuInfo A left join scoreInfo S on A.stuID=S.stuID where s.courseID is null +--8.查询出是周六周天来报到的学生 +select * from stuInfo where DATEPART(weekday,time)=1 or DATEPART(weekday,time)=7 +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like '%a%' +--10.查询出 选修了2门课程以上 的并且 考试平均分在70以上 的学生的学号 和考试平均分 以及 选修课程的数量 +select A.stuID,AVG(A.score)平均分,COUNT(stuID)选修数量 from scoreInfo A inner join courseInfo B on A.courseID=B.courseID GROUP BY stuID having COUNT(stuID)>2 AND AVG(score)>70 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/2.sql" new file mode 100644 index 0000000..a8f17dd --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/2.sql" @@ -0,0 +1,119 @@ + +create database sos +on +( + name='sos', + filename='D:\sos.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='sos_log', + filename='D:\sos_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use sos +go +create table tbl_card +( + id varchar(25) primary key, + [passWord] varchar(30) not null, + balance money not null, + userName varchar(20) not null +) +go + + +insert into tbl_card values('0023_ABC','555',98,'张军'),('0025_bbd','abe',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'),('0045_YGR','0045_YGR',58,'验证'), +('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张峻') + +select * from tbl_card + + +create table tbl_computer +( + id varchar(20) primary key, + onUse char(2) check(onUse=0 or onUse=1), + note text +) +go + +insert into tbl_computer values('02','0','25555'),('03','1','55555'),('04','0','66666'), +('05','1','88888'),('06','0','688878'),('B01','0','558558') + +select * from tbl_computer + + +create table tbl_record +( + id varchar(30) primary key, + cardId varchar(25) constraint FK_tbl_record_cardId references tbl_card(id), + ComputerId varchar(20) constraint FK_tbl_record_ComputerId references tbl_computer(id), + beginTime time, + endTime time, + fee money +) +go + +insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +('47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3'), +('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId +where userName='张军' order by fee desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(*)次数,sum(fee)总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId 卡号,sum(fee)总金额 from tbl_record group by cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select cardId 卡号,userName 用户名 from tbl_record +right join tbl_card on tbl_card.id = tbl_record.cardId where tbl_card.id not in(select cardId from tbl_record) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card A,tbl_card B where A.passWord = B.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 使用最多的机器号,count(*)次数 from tbl_record group by ComputerId order by count(*) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,fee 金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId where tbl_card.id like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +--I can't do it + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_record +inner join tbl_card on tbl_card.id = tbl_record.cardId where fee not in(select top 3 fee from tbl_record order by fee desc) + +select top 3 fee from tbl_record order by fee desc + -- Gitee From d9c137b29ce25b82e9578aae44a35d466c5b9ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= <3148578490@qq.com> Date: Thu, 1 Apr 2021 11:40:33 +0800 Subject: [PATCH 127/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=BB=84=E6=96=87?= =?UTF-8?q?=E8=81=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\273\204\346\226\207\350\201\252/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 2954c74843958f6a1ddb8c853558c1beb8935a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= <3148578490@qq.com> Date: Thu, 1 Apr 2021 11:41:02 +0800 Subject: [PATCH 128/195] =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQueryWB.sql" | 133 ++++++++++++++++++ .../SQLQuery\345\255\246\347\224\237.sql" | 115 +++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQueryWB.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\345\255\246\347\224\237.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQueryWB.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQueryWB.sql" new file mode 100644 index 0000000..a87726d --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQueryWB.sql" @@ -0,0 +1,133 @@ +use master +go +create database internet +on +( + name='internet', + filename='E:\数据库文件\数据库跟目录文件\交叉连接,两个表的笛卡尔乘积--多表查询 --集合运算 union intersect except(练习)\internet.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10mb +) +log on +( + name='internet_log', + filename='E:\数据库文件\数据库跟目录文件\交叉连接,两个表的笛卡尔乘积--多表查询 --集合运算 union intersect except(练习)\internet_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10mb +) +go +use internet +--首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: + +--表一为上网卡信息表(tbl_card) +--id: 卡号,主键 +--passWord:密码 +--balance:卡上的余额 +--userName:该上网卡所属的用户名 +create table tbl_card +( + Card_id char(10) primary key not null, + passWord char(20) not null, + balance float default(0) not null, + userName char(20) not null +) + + + + + + +--表2为网吧机器说明表(tbl_computer) +--id:机器编号,主键 +--onUse:该机器是否正在使用,0为未使用,1为正在使用 +--note:该机器的说明 +create table tbl_computer +( + ComputerId char(10) primary key not null, + onUse char not null, + note char(50) +) + + + + +--表3为上网记录表(tbl_record): +--id:记录编号,主键 +--cardId:本次上网的卡号,外键 +--ComputerId:本次上网记录所使用的机器号,外键 +--beginTime:本次上网记录的开始时间 +--endTime:本次上网记录的结束时间 +--fee:本次上网的费用 + +create table tbl_record +( + recordid int primary key not null, + Card_id char(10) foreign key references tbl_card(Card_id) not null, + ComputerId char(10) foreign key references tbl_computer(ComputerId) not null, + beginTime datetime null, + endTime datetime null, + fee float null +) + +--插入数据 +insert into tbl_computer(ComputerId,onUse,note)values +('02','0','25555'), +('03','1','55555'), +('04','0','66666'), +('05','1','88888'), +('06','0','688878'), +('B01','0','558558') +insert into tbl_record(recordid,Card_id,ComputerId,beginTime,endTime,fee)values +('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('46','0023_ABC','03','2007-12-22 15:26:00','2006-12-22 22:55:00','60'), +('47','0023_ABC','03','2006-12-23 15:26:00','2007-12-23 22:55:00','50'), +('48','0023_ABC','03','2006-01-06 15:26:00','2007-01-06 22:55:00','6'), +('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +('64','0045_YGR','04','2007-12-24 18:00:00','2006-12-24 22:00:00','30'), +('65','0025_bbd','02','2007-12-28 18:00:00','2006-12-28 22:00:00','23') +insert into tbl_card(Card_id,passWord,balance,userName)values +('0023_ABC','555','98','张军'), +('0025_bbd','abc','300','朱俊'), +('0036_CCD','河柳','100','何柳'), +('0045_YGR','0045_YGR','58','证验'), +('0078_RJV','55885fg','600','校庆'), +('0089_EDE','zhang','134','张峻') + + + +--查询三个表的数据 +select*from tbl_card +select*from tbl_computer +select*from tbl_record +--请完成以下题目: +--1. 查询出 用户名为'张军' 的上网卡 的上网记录 ,要求显示卡号 ,用户名 ,机器编号 、开始时间 、结束时间 ,和消费金额 ,并按消费金额降序排列 +select tbl_record.Card_id 卡号,userName 用户名,ComputerId 机器编号, beginTime 开始时间, endTime 结束时间,fee 消费金额 from tbl_card inner join tbl_record on tbl_card.Card_id=tbl_record.Card_id where userName='张军' order by fee desc +--2. 查询出 ‘每台机器’上的 ‘上网次数’ 和消费的 ‘总金额’ +select tbl_record.ComputerId 机器编号,count(tbl_record.ComputerId)上网次数,fee*count(tbl_record.ComputerId) 总金额 from tbl_computer inner join tbl_record on tbl_computer.ComputerId=tbl_record.ComputerId group by tbl_record.ComputerId,fee +--3. 查询出所有已经使用过的上网卡的消费总金额 +select Card_id 卡号,sum(fee)总金额 from tbl_record group by Card_id +--4. 查询出从未消费过的上网卡的卡号和用户名 +select tbl_card.Card_id 卡号,userName 用户名 from tbl_record +right join tbl_card on tbl_card.Card_id = tbl_record.Card_id where tbl_card.Card_id not in(select Card_id from tbl_record) +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card A,tbl_card B where A.passWord = B.userName +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 使用最多的机器号,count(*)次数 from tbl_record group by ComputerId order by count(*) desc +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_card.Card_id 卡号,userName 用户名,ComputerId 机器号,fee 金额 from tbl_card +inner join tbl_record on tbl_card.Card_id = tbl_record.Card_id where tbl_card.Card_id like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.Card_id 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_card +inner join tbl_record on tbl_card.Card_id = tbl_record.Card_id +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_record.Card_id 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_record +inner join tbl_card on tbl_card.Card_id = tbl_record.Card_id where fee not in(select top 3 fee from tbl_record order by fee desc) + +select top 3 fee from tbl_record order by fee desc \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\345\255\246\347\224\237.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\345\255\246\347\224\237.sql" new file mode 100644 index 0000000..6705f9e --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery\345\255\246\347\224\237.sql" @@ -0,0 +1,115 @@ +use master +go + +create database HomeWork +on +( + name='HomeWork', + filename='E:\数据库文件\数据库跟目录文件\交叉连接,两个表的笛卡尔乘积--多表查询 + --集合运算 union intersect except(练习)\HomeWork.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='HomeWork_log', + filename='E:\数据库文件\数据库跟目录文件\交叉连接,两个表的笛卡尔乘积--多表查询 + --集合运算 union intersect except(练习)\HomeWork_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +use HomeWork +go +create table stuInfo +( + stuID int primary key identity(1,1), + stuName char(20) not null, + stuAge char(5) not null, + stuSex char(2) not null, + time time +) +go + +insert into stuInfo 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') + +select * from stuInfo + +use HomeWork +create table courseInfo +( + courseID int primary key identity(1,1), + courseName nvarchar(15) not null, + courseMarks char(5) not null +) +go + +select * from courseInfo + +insert into courseInfo values('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) + +select * from courseInfo + + +use HomeWork +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int constraint FK_scoreInfo_stuID references stuInfo(stuID), + courseID int not null, + score int not null +) +go + +insert into scoreInfo 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) + + +select * from stuInfo +select * from courseInfo +select * from scoreInfo + + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuName 学生,count(*)课程数量,avg(score)平均分 from scoreInfo +inner join stuInfo on stuInfo.stuID = scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID = courseInfo.courseID group by stuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName 课程,count(*)学生个数,sum(score)考试总分 from scoreInfo +inner join courseInfo on scoreInfo.courseID = courseInfo.courseID group by courseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select s.* from StuInfo s where (select count(*) from StuInfo where stuAge=s.stuAge and stuSex=s.stuSex)>1 + +--4.查询出学分一样的课程信息 +select c.* from courseInfo c where (select count(*) from courseInfo where courseMarks=c.courseMarks)>1 + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select StuInfo.stuID 学号,stuName 姓名, courseInfo.courseID 课程号,score 分数 from scoreInfo +inner join StuInfo on scoreInfo.stuID = StuInfo.stuID +inner join courseInfo on scoreInfo.courseID = courseInfo.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select StuInfo.stuID 学号,courseInfo.courseID 课程号, courseName 课程名,courseMarks 课程学分,score 分数 from scoreInfo +inner join StuInfo on scoreInfo.stuID = StuInfo.stuID +inner join courseInfo on scoreInfo.courseID = courseInfo.courseID + +--7.查询出没有参加考试的学生的学号和姓名 +select StuInfo.stuID 学号,stuName 姓名 from scoreInfo inner join StuInfo on scoreInfo.stuID = StuInfo.stuID +where score not in(select score from scoreInfo) +--select * from 分数信息表 where 分数 not in(select 分数 from 分数信息表) + +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from StuInfo where stuName like + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + -- Gitee From 230dc649a68f631a17bf60aeca79be8d48036ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E6=A2=A6=E6=9E=97?= <2777141796@qq.com> Date: Thu, 1 Apr 2021 11:46:30 +0800 Subject: [PATCH 129/195] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20=E7=AC=AC?= =?UTF-8?q?=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/=E6=9D=A8?= =?UTF-8?q?=E6=A2=A6=E6=9E=971=20=E4=B8=BA=20=E7=AC=AC=E5=8D=81=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A/=E6=9D=A8=E6=A2=A6=E6=9E=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\346\235\250\346\242\246\346\236\227/SQLQuery5.sql" | 0 .../\346\235\250\346\242\246\346\236\227/SQLQuery6.sql" | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" => "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery5.sql" (100%) rename "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" => "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery6.sql" (100%) diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery5.sql" similarity index 100% rename from "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" rename to "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery5.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery6.sql" similarity index 100% rename from "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" rename to "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery6.sql" -- Gitee From 1c6ca1b885e030e9bbed421c5664633bab1390f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E6=A2=A6=E6=9E=97?= <2777141796@qq.com> Date: Thu, 1 Apr 2021 11:46:44 +0800 Subject: [PATCH 130/195] =?UTF-8?q?=E5=93=9F=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5.sql" | 157 ++++++++++++++++++ .../SQLQuery6.sql" | 138 +++++++++++++++ 2 files changed, 295 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" new file mode 100644 index 0000000..8b1db2b --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" @@ -0,0 +1,157 @@ +create database bbs + + + +on + +( + + name='bbs', + + filename='E:\bbs.mdf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +log on + +( + + name='bbs_log', + + filename='E:\bbs_log.ldf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +go + +use bbs + +go + + +--学生信息表 +create table stuInfo +( +stuID int primary key identity not null, +stuName varchar(20) not null, +stuAge int not null, +stuSex varchar(2) not null, +stutime varchar(20) +) +drop table stuInfo +insert into stuInfo +select '梦林',19,'男','NULL'union +select 'a海彪',20,'女','NULL'union +select '吴煌',21,'女','NULL'union +select '巧晶',19,'女','NULL'union +select '心怡',21,'女','NULL'union +select 'a坦克',20,'女','2017_01_07:11:36.590' + +select * from stuInfo + + +--课程表 +create table courseInfo +( +courseID int primary key identity not null, +courseName varchar(20) not null, +courseMarks int not null +) +drop table courseInfo +insert into courseInfo +select '语文',4 union +select '数学',2 union +select '英语',2 union +select 'SQL',2 + +select * from courseInfo + +--分数信息表 +create table scoreInfo +( +scoreID int primary key identity not null, +stuid int not null, +courseID int not null, +score int not null, +) + +insert into scoreInfo +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + +select * from scoreInfo +select * from stuInfo +select * from courseInfo + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select Y.stuName 姓名,M.courseName 科目,AVG(L.score) 平均分,count(M.courseMarks) 课程数量 from stuInfo Y inner join courseInfo M on Y.stuID=M.courseID inner join scoreInfo L on Y.stuID=L.stuid group by M.courseName,Y.stuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName 科目, count(M.stuID ) 学生人数, sum(score ) 总分 from courseInfo Y inner join stuInfo M ON Y.courseID=M.stuID inner join scoreInfo L on Y.courseID=L.courseID group by Y.courseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select * from stuInfo A,stuInfo B where A.stuAge =B.stuAge and A.stuSex=B.stuSex AND A.stuid!=B.stuid + + +--4.查询出学分一样的课程信息 +select * from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks AND A.courseid!=B.courseid + + + +select * from scoreInfo +--课程表 +select * from stuInfo +--学生表 +select * from courseInfo +--分数表 + + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select Y.stuid 学号,Y.stuName 姓名,L.courseID 课程号,M.score 分数 from stuInfo Y inner join scoreInfo M on Y.stuid = M.stuid inner join courseInfo L on Y.stuid =L.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select Y.stuid 学号,M.courseid 课程号,M.courseName 课程名, M.courseMarks 课程学分,L.score 分数 from stuInfo Y inner join courseInfo M on Y.stuid =M.courseid inner join scoreInfo L on Y.stuid = L.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuid,stuname from stuInfo left join scoreInfo on stuInfo.stuId=scoreInfo.stuid +where score is null +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like 'a%' + +--10.查询出选修了2门 课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select stuid 学号,avg(score)平均分,count(courseID)课程的数量 from scoreInfo group by stuid +having avg(score)>70 and count(courseID)>2 + + +select * from scoreInfo +--课程表 +select * from stuInfo +--学生表 +select * from courseInfo +--分数表 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" new file mode 100644 index 0000000..74eb597 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" @@ -0,0 +1,138 @@ +create database dds + + + +on + +( + + name='dds', + + filename='E:\dds.mdf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +log on + +( + + name='dds_log', + + filename='E:\dds_log.ldf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +go + +use dds + +go +create table card --网卡信息表 +( + id varchar(30) primary key,--卡号,主键 + pasword varchar(30),--密码 + balance money,--卡上的余额 + userName varchar(50)--该上网卡所属的用户名 +) +create table computer --网吧机器说明表 +( + id varchar(30) primary key,--机器编号,主键 + onUse varchar(2) check(onUse=0 or onUse=1),--该机器是否正在使用,0为未使用,1为正在使用 + note ntext --该机器的说明 +) +create table record --上网记录表 +( + id varchar(30) primary key,--记录编号,主键 + cardId varchar(30) foreign key references card(id),--本次上网的卡号,外键 + ComputerId varchar(30) foreign key references computer(id),--本次上网记录所使用的机器号,外键 + beginTime datetime,--本次上网记录的开始时间 + endTime datetime,--本次上网记录的结束时间 + fee money --本次上网的费用 +) + +insert into card +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' + +select * from card + +insert into computer +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' + +select * from computer + +insert into record +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from record -- --上网记录表 +select * from computer --网吧机器说明表 +select * from card --网卡信息表 + + + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 + select Y.cardId 卡号,L.userName 用户名,Y.ComputerId 机器编号,Y.beginTime 开始时间,Y.endTime 结束时间,Y.fee 消费金额 from record Y inner join card L on Y.cardId=L.id where L.userName ='张军' order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select count(*) 上网次数, ComputerId 机器编号,sum(fee) 总金额 from record group by ComputerId +select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 from record group by cardId,ComputerId + + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardid 网卡, sum(fee) 消费总金额 from record group by cardid + + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select M.id 卡号, M.userName 用户名 from card M left join record Y on Y.cardId=M.id where fee is null GROUP BY M.id,M.userName + + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from card A,card B where A.pasword=B.userName + + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(*)使用次数 from record group by ComputerId + + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 from record inner join card on record.cardId=card.id where record.cardId like '%ABC' + + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc + + -- Gitee From 1e8210f97bedbbfb65306ec10582b278b71774e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E6=A2=A6=E6=9E=97?= <2777141796@qq.com> Date: Thu, 1 Apr 2021 11:46:53 +0800 Subject: [PATCH 131/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/?= =?UTF-8?q?=E6=9D=A8=E6=A2=A6=E6=9E=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5.sql" | 157 ------------------ .../SQLQuery6.sql" | 139 ---------------- 2 files changed, 296 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery5.sql" delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery6.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery5.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery5.sql" deleted file mode 100644 index 8b1db2b..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery5.sql" +++ /dev/null @@ -1,157 +0,0 @@ -create database bbs - - - -on - -( - - name='bbs', - - filename='E:\bbs.mdf', - - size=5mb, - - maxsize=50mb, - - filegrowth=10% - -) - -log on - -( - - name='bbs_log', - - filename='E:\bbs_log.ldf', - - size=5mb, - - maxsize=50mb, - - filegrowth=10% - -) - -go - -use bbs - -go - - ---学生信息表 -create table stuInfo -( -stuID int primary key identity not null, -stuName varchar(20) not null, -stuAge int not null, -stuSex varchar(2) not null, -stutime varchar(20) -) -drop table stuInfo -insert into stuInfo -select '梦林',19,'男','NULL'union -select 'a海彪',20,'女','NULL'union -select '吴煌',21,'女','NULL'union -select '巧晶',19,'女','NULL'union -select '心怡',21,'女','NULL'union -select 'a坦克',20,'女','2017_01_07:11:36.590' - -select * from stuInfo - - ---课程表 -create table courseInfo -( -courseID int primary key identity not null, -courseName varchar(20) not null, -courseMarks int not null -) -drop table courseInfo -insert into courseInfo -select '语文',4 union -select '数学',2 union -select '英语',2 union -select 'SQL',2 - -select * from courseInfo - ---分数信息表 -create table scoreInfo -( -scoreID int primary key identity not null, -stuid int not null, -courseID int not null, -score int not null, -) - -insert into scoreInfo -select 1,1,80 union -select 1,2,85 union -select 1,4,50 union -select 2,1,75 union -select 2,3,45 union -select 2,4,75 union -select 3,1,45 union -select 4,1,95 union -select 4,2,75 union -select 4,3,90 union -select 4,4,45 - -select * from scoreInfo -select * from stuInfo -select * from courseInfo - ---有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) - ---题目: ---1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 -select Y.stuName 姓名,M.courseName 科目,AVG(L.score) 平均分,count(M.courseMarks) 课程数量 from stuInfo Y inner join courseInfo M on Y.stuID=M.courseID inner join scoreInfo L on Y.stuID=L.stuid group by M.courseName,Y.stuName - ---2.查询出每门课程的选修的学生的个数和学生考试的总分 -select courseName 科目, count(M.stuID ) 学生人数, sum(score ) 总分 from courseInfo Y inner join stuInfo M ON Y.courseID=M.stuID inner join scoreInfo L on Y.courseID=L.courseID group by Y.courseName - ---3.查询出性别一样并且年龄一样的学生的信息 -select * from stuInfo A,stuInfo B where A.stuAge =B.stuAge and A.stuSex=B.stuSex AND A.stuid!=B.stuid - - ---4.查询出学分一样的课程信息 -select * from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks AND A.courseid!=B.courseid - - - -select * from scoreInfo ---课程表 -select * from stuInfo ---学生表 -select * from courseInfo ---分数表 - - ---5.查询出参加了考试的学生的学号,姓名,课程号和分数 -select Y.stuid 学号,Y.stuName 姓名,L.courseID 课程号,M.score 分数 from stuInfo Y inner join scoreInfo M on Y.stuid = M.stuid inner join courseInfo L on Y.stuid =L.courseID - ---6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 -select Y.stuid 学号,M.courseid 课程号,M.courseName 课程名, M.courseMarks 课程学分,L.score 分数 from stuInfo Y inner join courseInfo M on Y.stuid =M.courseid inner join scoreInfo L on Y.stuid = L.courseID ---7.查询出没有参加考试的学生的学号和姓名 -select stuInfo.stuid,stuname from stuInfo left join scoreInfo on stuInfo.stuId=scoreInfo.stuid -where score is null ---8.查询出是周六周天来报到的学生 - ---9.查询出姓名中有字母a的学生的信息 -select * from stuInfo where stuName like 'a%' - ---10.查询出选修了2门 课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 - -select stuid 学号,avg(score)平均分,count(courseID)课程的数量 from scoreInfo group by stuid -having avg(score)>70 and count(courseID)>2 - - -select * from scoreInfo ---课程表 -select * from stuInfo ---学生表 -select * from courseInfo ---分数表 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery6.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery6.sql" deleted file mode 100644 index 7e0b416..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery6.sql" +++ /dev/null @@ -1,139 +0,0 @@ -create database dds - - - -on - -( - - name='dds', - - filename='E:\dds.mdf', - - size=5mb, - - maxsize=50mb, - - filegrowth=10% - -) - -log on - -( - - name='dds_log', - - filename='E:\dds_log.ldf', - - size=5mb, - - maxsize=50mb, - - filegrowth=10% - -) - -go - -use dds - -go -create table card --网卡信息表 -( - id varchar(30) primary key,--卡号,主键 - pasword varchar(30),--密码 - balance money,--卡上的余额 - userName varchar(50)--该上网卡所属的用户名 -) -create table computer --网吧机器说明表 -( - id varchar(30) primary key,--机器编号,主键 - onUse varchar(2) check(onUse=0 or onUse=1),--该机器是否正在使用,0为未使用,1为正在使用 - note ntext --该机器的说明 -) -create table record --上网记录表 -( - id varchar(30) primary key,--记录编号,主键 - cardId varchar(30) foreign key references card(id),--本次上网的卡号,外键 - ComputerId varchar(30) foreign key references computer(id),--本次上网记录所使用的机器号,外键 - beginTime datetime,--本次上网记录的开始时间 - endTime datetime,--本次上网记录的结束时间 - fee money --本次上网的费用 -) - -insert into card -select '0023_ABC','555','98','张军'union -select '0025_bbd','abe','300','朱俊'union -select '0036_CCD','何柳','100','何柳'union -select '0045_YGR','0045_YGR','58','证验'union -select '0078_RJV','55885fg','600','校庆'union -select '0089_EDE','张','134','张峻' - -select * from card - -insert into computer -select '02','0','25555' union -select '03','1','55555' union -select '04','0','66666' union -select '05','1','88888' union -select '06','0','688878' union -select 'B01','0','558558' - -select * from computer - -insert into record -select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union -select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union -select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union -select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union -select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union -select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union -select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union -select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union -select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union -select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' - -select * from record -- --上网记录表 -select * from computer --网吧机器说明表 -select * from card --网卡信息表 - - - ---请完成以下题目: ---1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 -select card.id 卡号, card.userName 用户名 ,beginTime 开始时间,endTime 结束时间,fee 消费金额 from card inner join record on card.id=record.cardId where userName='张军' order by fee desc - - ---2. 查询出每台机器上的上网次数和消费的总金额 -select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 from record group by cardId,ComputerId - - ---3. 查询出所有已经使用过的上网卡的消费总金额 -select cardId 卡号,sum(record.fee) 消费总金额 from record group by cardId - - ---4. 查询出从未消费过的上网卡的卡号和用户名 -select card.id 卡号 ,userName 用户名 from card left join record on card.id=record.cardId where fee is null group by userName,card.id - - ---5. 将密码与用户名一样的上网卡信息查询出来 -select * from card A,card B where A.pasword=B.userName - - ---6. 查询出使用次数最多的机器号和使用次数 -select top 1 ComputerId 机器号,count(ComputerId)使用次数 from record group by ComputerId order By count(ComputerId) - - ---7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 -select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 from record inner join card on record.cardId=card.id where record.cardId like '%ABC' - - ---8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - ---9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - ---10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc - - -- Gitee From 0b97940cfaf51558103ac5b08151c2ab43e6f75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E6=A2=A6=E6=9E=97?= <2777141796@qq.com> Date: Thu, 1 Apr 2021 11:52:53 +0800 Subject: [PATCH 132/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/?= =?UTF-8?q?=E6=9D=A8=E6=A2=A6=E6=9E=971?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5.sql" | 157 ------------------ .../SQLQuery6.sql" | 138 --------------- 2 files changed, 295 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" deleted file mode 100644 index 8b1db2b..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" +++ /dev/null @@ -1,157 +0,0 @@ -create database bbs - - - -on - -( - - name='bbs', - - filename='E:\bbs.mdf', - - size=5mb, - - maxsize=50mb, - - filegrowth=10% - -) - -log on - -( - - name='bbs_log', - - filename='E:\bbs_log.ldf', - - size=5mb, - - maxsize=50mb, - - filegrowth=10% - -) - -go - -use bbs - -go - - ---学生信息表 -create table stuInfo -( -stuID int primary key identity not null, -stuName varchar(20) not null, -stuAge int not null, -stuSex varchar(2) not null, -stutime varchar(20) -) -drop table stuInfo -insert into stuInfo -select '梦林',19,'男','NULL'union -select 'a海彪',20,'女','NULL'union -select '吴煌',21,'女','NULL'union -select '巧晶',19,'女','NULL'union -select '心怡',21,'女','NULL'union -select 'a坦克',20,'女','2017_01_07:11:36.590' - -select * from stuInfo - - ---课程表 -create table courseInfo -( -courseID int primary key identity not null, -courseName varchar(20) not null, -courseMarks int not null -) -drop table courseInfo -insert into courseInfo -select '语文',4 union -select '数学',2 union -select '英语',2 union -select 'SQL',2 - -select * from courseInfo - ---分数信息表 -create table scoreInfo -( -scoreID int primary key identity not null, -stuid int not null, -courseID int not null, -score int not null, -) - -insert into scoreInfo -select 1,1,80 union -select 1,2,85 union -select 1,4,50 union -select 2,1,75 union -select 2,3,45 union -select 2,4,75 union -select 3,1,45 union -select 4,1,95 union -select 4,2,75 union -select 4,3,90 union -select 4,4,45 - -select * from scoreInfo -select * from stuInfo -select * from courseInfo - ---有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) - ---题目: ---1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 -select Y.stuName 姓名,M.courseName 科目,AVG(L.score) 平均分,count(M.courseMarks) 课程数量 from stuInfo Y inner join courseInfo M on Y.stuID=M.courseID inner join scoreInfo L on Y.stuID=L.stuid group by M.courseName,Y.stuName - ---2.查询出每门课程的选修的学生的个数和学生考试的总分 -select courseName 科目, count(M.stuID ) 学生人数, sum(score ) 总分 from courseInfo Y inner join stuInfo M ON Y.courseID=M.stuID inner join scoreInfo L on Y.courseID=L.courseID group by Y.courseName - ---3.查询出性别一样并且年龄一样的学生的信息 -select * from stuInfo A,stuInfo B where A.stuAge =B.stuAge and A.stuSex=B.stuSex AND A.stuid!=B.stuid - - ---4.查询出学分一样的课程信息 -select * from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks AND A.courseid!=B.courseid - - - -select * from scoreInfo ---课程表 -select * from stuInfo ---学生表 -select * from courseInfo ---分数表 - - ---5.查询出参加了考试的学生的学号,姓名,课程号和分数 -select Y.stuid 学号,Y.stuName 姓名,L.courseID 课程号,M.score 分数 from stuInfo Y inner join scoreInfo M on Y.stuid = M.stuid inner join courseInfo L on Y.stuid =L.courseID - ---6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 -select Y.stuid 学号,M.courseid 课程号,M.courseName 课程名, M.courseMarks 课程学分,L.score 分数 from stuInfo Y inner join courseInfo M on Y.stuid =M.courseid inner join scoreInfo L on Y.stuid = L.courseID ---7.查询出没有参加考试的学生的学号和姓名 -select stuInfo.stuid,stuname from stuInfo left join scoreInfo on stuInfo.stuId=scoreInfo.stuid -where score is null ---8.查询出是周六周天来报到的学生 - ---9.查询出姓名中有字母a的学生的信息 -select * from stuInfo where stuName like 'a%' - ---10.查询出选修了2门 课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 - -select stuid 学号,avg(score)平均分,count(courseID)课程的数量 from scoreInfo group by stuid -having avg(score)>70 and count(courseID)>2 - - -select * from scoreInfo ---课程表 -select * from stuInfo ---学生表 -select * from courseInfo ---分数表 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" deleted file mode 100644 index 74eb597..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" +++ /dev/null @@ -1,138 +0,0 @@ -create database dds - - - -on - -( - - name='dds', - - filename='E:\dds.mdf', - - size=5mb, - - maxsize=50mb, - - filegrowth=10% - -) - -log on - -( - - name='dds_log', - - filename='E:\dds_log.ldf', - - size=5mb, - - maxsize=50mb, - - filegrowth=10% - -) - -go - -use dds - -go -create table card --网卡信息表 -( - id varchar(30) primary key,--卡号,主键 - pasword varchar(30),--密码 - balance money,--卡上的余额 - userName varchar(50)--该上网卡所属的用户名 -) -create table computer --网吧机器说明表 -( - id varchar(30) primary key,--机器编号,主键 - onUse varchar(2) check(onUse=0 or onUse=1),--该机器是否正在使用,0为未使用,1为正在使用 - note ntext --该机器的说明 -) -create table record --上网记录表 -( - id varchar(30) primary key,--记录编号,主键 - cardId varchar(30) foreign key references card(id),--本次上网的卡号,外键 - ComputerId varchar(30) foreign key references computer(id),--本次上网记录所使用的机器号,外键 - beginTime datetime,--本次上网记录的开始时间 - endTime datetime,--本次上网记录的结束时间 - fee money --本次上网的费用 -) - -insert into card -select '0023_ABC','555','98','张军'union -select '0025_bbd','abe','300','朱俊'union -select '0036_CCD','何柳','100','何柳'union -select '0045_YGR','0045_YGR','58','证验'union -select '0078_RJV','55885fg','600','校庆'union -select '0089_EDE','张','134','张峻' - -select * from card - -insert into computer -select '02','0','25555' union -select '03','1','55555' union -select '04','0','66666' union -select '05','1','88888' union -select '06','0','688878' union -select 'B01','0','558558' - -select * from computer - -insert into record -select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union -select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union -select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union -select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union -select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union -select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union -select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union -select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union -select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union -select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' - -select * from record -- --上网记录表 -select * from computer --网吧机器说明表 -select * from card --网卡信息表 - - - ---请完成以下题目: ---1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 - select Y.cardId 卡号,L.userName 用户名,Y.ComputerId 机器编号,Y.beginTime 开始时间,Y.endTime 结束时间,Y.fee 消费金额 from record Y inner join card L on Y.cardId=L.id where L.userName ='张军' order by fee desc ---2. 查询出每台机器上的上网次数和消费的总金额 -select count(*) 上网次数, ComputerId 机器编号,sum(fee) 总金额 from record group by ComputerId -select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 from record group by cardId,ComputerId - - ---3. 查询出所有已经使用过的上网卡的消费总金额 -select cardid 网卡, sum(fee) 消费总金额 from record group by cardid - - ---4. 查询出从未消费过的上网卡的卡号和用户名 -select M.id 卡号, M.userName 用户名 from card M left join record Y on Y.cardId=M.id where fee is null GROUP BY M.id,M.userName - - ---5. 将密码与用户名一样的上网卡信息查询出来 -select * from card A,card B where A.pasword=B.userName - - ---6. 查询出使用次数最多的机器号和使用次数 -select top 1 ComputerId 机器号,count(*)使用次数 from record group by ComputerId - - ---7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 -select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 from record inner join card on record.cardId=card.id where record.cardId like '%ABC' - - ---8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - ---9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 - ---10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc - - -- Gitee From 84bea74416d0e86f40dc61e44bfe144b18d3c6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E6=A2=A6=E6=9E=97?= <2777141796@qq.com> Date: Thu, 1 Apr 2021 11:53:11 +0800 Subject: [PATCH 133/195] =?UTF-8?q?=E8=8A=B1=E5=A7=91=E5=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5.sql" | 157 ++++++++++++++++++ .../SQLQuery6.sql" | 138 +++++++++++++++ 2 files changed, 295 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" new file mode 100644 index 0000000..8b1db2b --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery5.sql" @@ -0,0 +1,157 @@ +create database bbs + + + +on + +( + + name='bbs', + + filename='E:\bbs.mdf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +log on + +( + + name='bbs_log', + + filename='E:\bbs_log.ldf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +go + +use bbs + +go + + +--学生信息表 +create table stuInfo +( +stuID int primary key identity not null, +stuName varchar(20) not null, +stuAge int not null, +stuSex varchar(2) not null, +stutime varchar(20) +) +drop table stuInfo +insert into stuInfo +select '梦林',19,'男','NULL'union +select 'a海彪',20,'女','NULL'union +select '吴煌',21,'女','NULL'union +select '巧晶',19,'女','NULL'union +select '心怡',21,'女','NULL'union +select 'a坦克',20,'女','2017_01_07:11:36.590' + +select * from stuInfo + + +--课程表 +create table courseInfo +( +courseID int primary key identity not null, +courseName varchar(20) not null, +courseMarks int not null +) +drop table courseInfo +insert into courseInfo +select '语文',4 union +select '数学',2 union +select '英语',2 union +select 'SQL',2 + +select * from courseInfo + +--分数信息表 +create table scoreInfo +( +scoreID int primary key identity not null, +stuid int not null, +courseID int not null, +score int not null, +) + +insert into scoreInfo +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + +select * from scoreInfo +select * from stuInfo +select * from courseInfo + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select Y.stuName 姓名,M.courseName 科目,AVG(L.score) 平均分,count(M.courseMarks) 课程数量 from stuInfo Y inner join courseInfo M on Y.stuID=M.courseID inner join scoreInfo L on Y.stuID=L.stuid group by M.courseName,Y.stuName + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName 科目, count(M.stuID ) 学生人数, sum(score ) 总分 from courseInfo Y inner join stuInfo M ON Y.courseID=M.stuID inner join scoreInfo L on Y.courseID=L.courseID group by Y.courseName + +--3.查询出性别一样并且年龄一样的学生的信息 +select * from stuInfo A,stuInfo B where A.stuAge =B.stuAge and A.stuSex=B.stuSex AND A.stuid!=B.stuid + + +--4.查询出学分一样的课程信息 +select * from courseInfo A,courseInfo B where A.courseMarks=B.courseMarks AND A.courseid!=B.courseid + + + +select * from scoreInfo +--课程表 +select * from stuInfo +--学生表 +select * from courseInfo +--分数表 + + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select Y.stuid 学号,Y.stuName 姓名,L.courseID 课程号,M.score 分数 from stuInfo Y inner join scoreInfo M on Y.stuid = M.stuid inner join courseInfo L on Y.stuid =L.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select Y.stuid 学号,M.courseid 课程号,M.courseName 课程名, M.courseMarks 课程学分,L.score 分数 from stuInfo Y inner join courseInfo M on Y.stuid =M.courseid inner join scoreInfo L on Y.stuid = L.courseID +--7.查询出没有参加考试的学生的学号和姓名 +select stuInfo.stuid,stuname from stuInfo left join scoreInfo on stuInfo.stuId=scoreInfo.stuid +where score is null +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like 'a%' + +--10.查询出选修了2门 课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select stuid 学号,avg(score)平均分,count(courseID)课程的数量 from scoreInfo group by stuid +having avg(score)>70 and count(courseID)>2 + + +select * from scoreInfo +--课程表 +select * from stuInfo +--学生表 +select * from courseInfo +--分数表 \ No newline at end of file diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" new file mode 100644 index 0000000..0edd51c --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\2271/SQLQuery6.sql" @@ -0,0 +1,138 @@ +create database dds + + + +on + +( + + name='dds', + + filename='E:\dds.mdf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +log on + +( + + name='dds_log', + + filename='E:\dds_log.ldf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +go + +use dds + +go +create table card --网卡信息表 +( + id varchar(30) primary key,--卡号,主键 + pasword varchar(30),--密码 + balance money,--卡上的余额 + userName varchar(50)--该上网卡所属的用户名 +) +create table computer --网吧机器说明表 +( + id varchar(30) primary key,--机器编号,主键 + onUse varchar(2) check(onUse=0 or onUse=1),--该机器是否正在使用,0为未使用,1为正在使用 + note ntext --该机器的说明 +) +create table record --上网记录表 +( + id varchar(30) primary key,--记录编号,主键 + cardId varchar(30) foreign key references card(id),--本次上网的卡号,外键 + ComputerId varchar(30) foreign key references computer(id),--本次上网记录所使用的机器号,外键 + beginTime datetime,--本次上网记录的开始时间 + endTime datetime,--本次上网记录的结束时间 + fee money --本次上网的费用 +) + +insert into card +select '0023_ABC','555','98','张军'union +select '0025_bbd','abe','300','朱俊'union +select '0036_CCD','何柳','100','何柳'union +select '0045_YGR','0045_YGR','58','证验'union +select '0078_RJV','55885fg','600','校庆'union +select '0089_EDE','张','134','张峻' + +select * from card + +insert into computer +select '02','0','25555' union +select '03','1','55555' union +select '04','0','66666' union +select '05','1','88888' union +select '06','0','688878' union +select 'B01','0','558558' + +select * from computer + +insert into record +select '23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20' union +select '34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23' union +select '45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6' union +select '47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50' union +select '48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6' union +select '55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50' union +select '64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3' union +select '65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23' union +select '98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23' + +select * from record -- --上网记录表 +select * from computer --网吧机器说明表 +select * from card --网卡信息表 + + + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 + select Y.cardId 卡号,L.userName 用户名,Y.ComputerId 机器编号,Y.beginTime 开始时间,Y.endTime 结束时间,Y.fee 消费金额 from record Y inner join card L on Y.cardId=L.id where L.userName ='张军' order by fee desc +--2. 查询出每台机器上的上网次数和消费的总金额 +select count(*) 上网次数, ComputerId 机器编号,sum(fee) 总金额 from record group by ComputerId + + + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardid 网卡, sum(fee) 消费总金额 from record group by cardid + + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select M.id 卡号, M.userName 用户名 from card M left join record Y on Y.cardId=M.id where fee is null GROUP BY M.id,M.userName + + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from card A,card B where A.pasword=B.userName + + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(*)使用次数 from record group by ComputerId + + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 from record inner join card on record.cardId=card.id where record.cardId like '%ABC' + + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from record order by fee desc + + -- Gitee From 94a41125afd47d0f96095c17a9902e3c39bf8468 Mon Sep 17 00:00:00 2001 From: weilijiang <3055679233@qq.com> Date: Thu, 1 Apr 2021 12:05:19 +0800 Subject: [PATCH 134/195] =?UTF-8?q?sql=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery\344\275\234\344\270\2322.sql" | 140 ++++++++++++++++++ .../SQL\344\275\234\344\270\2321.sql" | 126 ++++++++++++++++ 2 files changed, 266 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQLQuery\344\275\234\344\270\2322.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL\344\275\234\344\270\2321.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQLQuery\344\275\234\344\270\2322.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQLQuery\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000..a52ece6 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQLQuery\344\275\234\344\270\2322.sql" @@ -0,0 +1,140 @@ +--首先创建网吧计费系统的数据库,表结构和数据如2.bmp所示,表的说明如下: + +use master +go +create database payment +on( + name='payment', + filename='D:\sql\payment.mdf', + size=8mb, + maxsize=80mb, + filegrowth=10% +) +log on( + name='payment_log', + filename='D:\sql\payment_log.ldf', + size=8mb, + maxsize=80mb, + filegrowth=10% +) +--表一为上网卡信息表(tbl_card) +--id: 卡号,主键 +--PassWord:密码 + +--balance:卡上的余额 +--userName:用户名 +create table tbl_card +( + id nvarchar(20) primary key not null, + passWord nvarchar(20) not null, + balance int not null, + userName nvarchar(20) not null +) + + drop table tbl_card +insert into tbl_card +select '0023_ABC','555',98,'张军' union +select '0025_bbd','abe',300,'朱俊' union +select '0036_CCD','何柳',100,'何柳' union +select '0045_YGR','0045_YGR',58,'证验'union +select '0078_RJV','55885fg',600,'校庆' union +select '0089_EDE','zhang',134,'张峻' +--表2为网吧机器说明表(tbl_computer) +--id:机器编号,主键 +--onUse:该机器是否正在使用,0为未使用,1为正在使用 +--note:该机器的说明 +create table tbl_computer( + id nvarchar(20) primary key not null, + onUse nchar(2) default(1) check(onUse=1 or onUse=0), + note int not null +) +drop table tbl_computer +insert into tbl_computer +select '02',0,25555 union +select '03',1,55555 union +select '04',0,66666 union +select '05',1,88888 union +select '06',0,688878 union +select 'B01',0,558558 + +--表3为上网记录表(tbl_record): +--id:记录编号,主键 +--cardId:本次上网的卡号,外键 +--ComputerId:本次上网记录所使用的机器号,外键 +--beginTime:本次上网记录的开始时间 +--endTime:本次上网记录的结束时间 +--fee:本次上网的费用 +create table tbl_record +( + id int primary key not null, + cardId nvarchar(20) not null, + ComputerId nvarchar(20) not null, + beginTime datetime not null, + endTime datetime not null, + fee int +) +DROP TABLE tbl_record +insert into tbl_record +select 23,'0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00',20 UNION +select 34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23 UNION +select 45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00 ', 50 union +select 46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00', 6 union +select 47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00', 50 union +select 48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 ',6 union +select 55,'0023_ABC','03','2006-07-21 15:26:00', '2006-07-21 22:55:00',50 union +select 64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',300 union +select 65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23 union +select 98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23 + +--请完成以下题目: +SELECT * FROM tbl_card +SELECT * FROM tbl_computer +SELECT * FROM tbl_record +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +SELECT tbl_card.id 卡号,tbl_card.userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 +from tbl_card inner join tbl_record + on tbl_card.id=tbl_record.cardId + where tbl_card.userName='张军' order by fee desc +SELECT * FROM tbl_card +SELECT * FROM tbl_computer +SELECT * FROM tbl_record +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(cardId)上网次数,sum(fee)总金额 +from tbl_record group by cardId,ComputerId +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId,sum(fee) 总金额 +from tbl_record group by cardId +--4. 查询出从未消费过的上网卡的卡号和用户名 +select tbl_card.id 卡号,userName 用户名 from tbl_card +left join tbl_record on tbl_card.id =tbl_record.cardId +where fee is null group by tbl_card.id,userName +SELECT * FROM tbl_card +SELECT * FROM tbl_computer +SELECT * FROM tbl_record +--5. 将密码与用户名一样的上网卡信息查询出来 +select a.* FROM tbl_card a,tbl_card b where a.PassWord=b.userName +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号,count(ComputerId)使用次数 +from tbl_record group by ComputerId order by count(ComputerId) desc +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardId 卡号,userName 用户名,ComputerId 机器号, fee 消费金额 +from tbl_card inner join tbl_record on tbl_card.id=tbl_record.cardId +where tbl_record.cardId like '%ABC' +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select * from tbl_card,tbl_record +select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,beginTime 消费金额,endTime 结束时间,fee 消费金额 +from tbl_record inner join tbl_card on tbl_card.id=tbl_record.cardId group by tbl_card.id, userName, + ComputerId,beginTime,endTime,fee + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select * from tbl_card,tbl_record +select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额,count(endTime-beginTime)上网记录时间 + from tbl_record inner join tbl_card on tbl_card.id=tbl_record.cardId group by tbl_card.id, userName, + ComputerId,beginTime,endTime,fee +having count(endTime-beginTime)>=12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardId 卡号,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_record order by fee desc + + + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL\344\275\234\344\270\2321.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL\344\275\234\344\270\2321.sql" new file mode 100644 index 0000000..862ce57 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQL\344\275\234\344\270\2321.sql" @@ -0,0 +1,126 @@ +use master +go + +drop database StudentInfo + +create database StudentInfo +on( + name = 'StudentInfo', + filename = 'D:\sql\StudentInfo.mdf', + size = 8mb, + maxsize= 80mb, + filegrowth=10% +) +log on ( + + name = 'StudentInfo_log', + filename = 'D:\sql\StudentInfo_log.ldf', + size = 8mb, + maxsize= 80mb, + filegrowth=10% +) +go +use StudentInfo +go + +create table stuInfo +( + stuID int primary key identity(1,1), + stuName nvarchar(10) not null, + stuAge nvarchar(10) not null, + stuSex nchar(2) default(1) check(stuSex='1' or stuSex='0') not null, + time datetime, + +) +insert into stuInfo +select 'Tom',19,'1',null union +select 'Jack', 20,'0',null union +select 'Rose',21,'1',null union +select 'Lulu',19,'1',null union +select 'Lili',21,'0',null union +select 'abc',20,'1','2007-01-07 01:11:36.590' +create table courseInfo +( + courseID INT PRIMARY KEY IDENTITY(1,1), + courseName nvarchar(20) not null, + courseMarks int not null, +) +drop table courseInfo + + +insert into courseInfo +select 'JavaBase',4 union +select 'HTML',2 union +select 'JavaScript',2 union +select 'SqlBase',2 + + + + +create table scoreInfo +( + scoreID INT PRIMARY KEY identity(1,1) not null, + stuID INT NOT NULL, + courseID INT NOT NULL, + score INT +) +DROP TABLE scoreInfo + +insert into scoreInfo +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + + + + + + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +select * from stuInfo +select * from courseInfo +select * from scoreInfo +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select * from courseInfo,scoreInfo +select stuID 序号, + count(courseName) 课程的数量,avg(score) 考试的平均分 FROM courseInfo INNER JOIN scoreInfo + ON courseInfo.courseID=scoreInfo.courseID + GROUP BY stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +SELECT courseName 每门课程,SUM(stuID) 学生的人数,sum(score) 考试的总分 from courseInfo inner join scoreInfo +on courseInfo.courseID=scoreInfo.courseID group by courseName +--3.查询出性别一样并且年龄一样的学生的信息 +select A. * from stuInfo A ,stuInfo B where A.stuAge=B.stuAge and A.stuSex=B.stuSex and A.stuID!=B.stuID + +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks AND A.courseID!=B.courseID +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select * from stuInfo,courseInfo,scoreInfo +select scoreInfo.stuID 学生学号,stuName 名字,courseID 课程,score 分数 from scoreInfo +left join stuInfo on scoreInfo.stuID=stuInfo.stuID +group by scoreInfo.stuID,stuName,courseID,score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号,courseInfo.courseID 课程号,courseName 课程名,courseMarks 课程学分,score 分数 from courseInfo left join scoreInfo +on courseInfo.courseID=scoreID +--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 stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select * from scoreInfo +select stuID 学号,avg(score) 平均分,count(courseID) 课程的数量 FROM scoreInfo GROUP BY stuID HAVING count(courseID)>=2 AND avg(score)>=70 -- Gitee From 7eb4192298a140d3ca3376848805e33d28d884f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=8F=98=E5=B0=8F=E7=8C=AA?= <1589953126@qq.com> Date: Thu, 1 Apr 2021 12:15:57 +0800 Subject: [PATCH 135/195] SQL --- .../SQLQuery1.sql" | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" new file mode 100644 index 0000000..7154600 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" @@ -0,0 +1,104 @@ + +create database Jxc + +on +( + name='Jxc', + filename='D:\Jxc.mdf' +) +log on +( + name='Jxc_log', + filename='D:\Jxc.ldf_log' +) +use Jxc +create table stuInfo +( + stuID int primary key , + stuName varchar(20), + stuAge int , + stuSex nvarchar(1), + stime datetime +) + +create table courseInfo +( + courseID int primary key , + courseName varchar(25), + courseMarks varchar(5) +) +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int foreign key references stuInfo(stuID) , + courseID int foreign key references courseInfo(courseID), + score int +) +--学生信息表 +insert into stuInfo(stuID,stuName,stuAge,stuSex) +select 1,'Tom',19,1 union +select 2,'Jack',20,0union +select 3,'Rose',21,1union +select 4,'Lulu',19,1 union +select 5,'Lili',21,0union +select 6,'abc',20,1 + +update stuInfo set stime='2007-01-07 01:11:36.590'where stuName='abc' +--课程表 +insert into courseInfo(courseID,courseName,courseMarks) +select 1,'JavaBase',4 union +select 2,'HTML',2 union +select 3,'JavaScript',2 union +select 4,'SqlBase',2 +-- 成绩表 +insert into scoreInfo(stuID,courseID,score) +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +select * from stuInfo --学生信息表 +select * from courseInfo --课程表 +select * from scoreInfo -- 成绩表 +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseID 课程, count(courseID)选修个数, sum(score)总分 from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A, stuInfo B +where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stuID!=B.stuID +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks AND A.courseID!=B.courseID +--5.查询出参加了 考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo +left join stuInfo on scoreInfo.stuID=stuInfo.stuID group by scoreInfo.stuID,stuName,courseID,score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo +left join courseInfo on scoreInfo.courseID=courseInfo.courseID +--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 stuName like '%a%' +--10.查询出 选修了2门课程 以上的 并且 考试平均分 在70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo +group by stuID +having avg(score)>=70 and count(courseID)>=2 + +select * from courseInfo --课程表 +select * from scoreInfo -- 成绩表 +select * from stuInfo --学生信息表 \ No newline at end of file -- Gitee From 5dde5b00ef8e6cd56f85024ac882220b6a227f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=8F=98=E5=B0=8F=E7=8C=AA?= <1589953126@qq.com> Date: Thu, 1 Apr 2021 12:16:04 +0800 Subject: [PATCH 136/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/SQLQuery?= =?UTF-8?q?1.sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 104 ------------------ 1 file changed, 104 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" deleted file mode 100644 index 7154600..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/SQLQuery1.sql" +++ /dev/null @@ -1,104 +0,0 @@ - -create database Jxc - -on -( - name='Jxc', - filename='D:\Jxc.mdf' -) -log on -( - name='Jxc_log', - filename='D:\Jxc.ldf_log' -) -use Jxc -create table stuInfo -( - stuID int primary key , - stuName varchar(20), - stuAge int , - stuSex nvarchar(1), - stime datetime -) - -create table courseInfo -( - courseID int primary key , - courseName varchar(25), - courseMarks varchar(5) -) -create table scoreInfo -( - scoreID int primary key identity(1,1), - stuID int foreign key references stuInfo(stuID) , - courseID int foreign key references courseInfo(courseID), - score int -) ---学生信息表 -insert into stuInfo(stuID,stuName,stuAge,stuSex) -select 1,'Tom',19,1 union -select 2,'Jack',20,0union -select 3,'Rose',21,1union -select 4,'Lulu',19,1 union -select 5,'Lili',21,0union -select 6,'abc',20,1 - -update stuInfo set stime='2007-01-07 01:11:36.590'where stuName='abc' ---课程表 -insert into courseInfo(courseID,courseName,courseMarks) -select 1,'JavaBase',4 union -select 2,'HTML',2 union -select 3,'JavaScript',2 union -select 4,'SqlBase',2 --- 成绩表 -insert into scoreInfo(stuID,courseID,score) -select 1,1,80 union -select 1,2,85 union -select 1,4,50 union -select 2,1,75 union -select 2,3,45 union -select 2,4,75 union -select 3,1,45 union -select 4,1,95 union -select 4,2,75 union -select 4,3,90 union -select 4,4,45 - ---有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) -select * from stuInfo --学生信息表 -select * from courseInfo --课程表 -select * from scoreInfo -- 成绩表 ---题目: ---1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 -select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID ---2.查询出每门课程的选修的学生的个数和学生考试的总分 -select courseID 课程, count(courseID)选修个数, sum(score)总分 from scoreInfo group by courseID - ---3.查询出性别一样并且年龄一样的学生的信息 -select A.* from stuInfo A, stuInfo B -where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stuID!=B.stuID ---4.查询出学分一样的课程信息 -select distinct A.* from courseInfo A,courseInfo B -where A.courseMarks=B.courseMarks AND A.courseID!=B.courseID ---5.查询出参加了 考试的学生的学号,姓名,课程号和分数 -select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo -left join stuInfo on scoreInfo.stuID=stuInfo.stuID group by scoreInfo.stuID,stuName,courseID,score ---6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 -select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo -left join courseInfo on scoreInfo.courseID=courseInfo.courseID ---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 stuName like '%a%' ---10.查询出 选修了2门课程 以上的 并且 考试平均分 在70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 -select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo -group by stuID -having avg(score)>=70 and count(courseID)>=2 - -select * from courseInfo --课程表 -select * from scoreInfo -- 成绩表 -select * from stuInfo --学生信息表 \ No newline at end of file -- Gitee From 1ff5a51d7147606c0e39258eb18b855ac4870123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=8F=98=E5=B0=8F=E7=8C=AA?= <1589953126@qq.com> Date: Thu, 1 Apr 2021 12:16:37 +0800 Subject: [PATCH 137/195] SQL --- .../SQLQuery1.sql" | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" new file mode 100644 index 0000000..7154600 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" @@ -0,0 +1,104 @@ + +create database Jxc + +on +( + name='Jxc', + filename='D:\Jxc.mdf' +) +log on +( + name='Jxc_log', + filename='D:\Jxc.ldf_log' +) +use Jxc +create table stuInfo +( + stuID int primary key , + stuName varchar(20), + stuAge int , + stuSex nvarchar(1), + stime datetime +) + +create table courseInfo +( + courseID int primary key , + courseName varchar(25), + courseMarks varchar(5) +) +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int foreign key references stuInfo(stuID) , + courseID int foreign key references courseInfo(courseID), + score int +) +--学生信息表 +insert into stuInfo(stuID,stuName,stuAge,stuSex) +select 1,'Tom',19,1 union +select 2,'Jack',20,0union +select 3,'Rose',21,1union +select 4,'Lulu',19,1 union +select 5,'Lili',21,0union +select 6,'abc',20,1 + +update stuInfo set stime='2007-01-07 01:11:36.590'where stuName='abc' +--课程表 +insert into courseInfo(courseID,courseName,courseMarks) +select 1,'JavaBase',4 union +select 2,'HTML',2 union +select 3,'JavaScript',2 union +select 4,'SqlBase',2 +-- 成绩表 +insert into scoreInfo(stuID,courseID,score) +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +select * from stuInfo --学生信息表 +select * from courseInfo --课程表 +select * from scoreInfo -- 成绩表 +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseID 课程, count(courseID)选修个数, sum(score)总分 from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A, stuInfo B +where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stuID!=B.stuID +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks AND A.courseID!=B.courseID +--5.查询出参加了 考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo +left join stuInfo on scoreInfo.stuID=stuInfo.stuID group by scoreInfo.stuID,stuName,courseID,score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo +left join courseInfo on scoreInfo.courseID=courseInfo.courseID +--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 stuName like '%a%' +--10.查询出 选修了2门课程 以上的 并且 考试平均分 在70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo +group by stuID +having avg(score)>=70 and count(courseID)>=2 + +select * from courseInfo --课程表 +select * from scoreInfo -- 成绩表 +select * from stuInfo --学生信息表 \ No newline at end of file -- Gitee From d6e14f7cfd7ccbc47f7348dedfcb0ad11729088a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=8F=B6=E5=B8=85?= <2876015251@qq.com> Date: Thu, 1 Apr 2021 12:40:59 +0800 Subject: [PATCH 138/195] SQL --- .../SQLQuery1.sql" | 109 +++++++++++++++ .../SQLQuery2.sql" | 125 ++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" new file mode 100644 index 0000000..c6dc5ac --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" @@ -0,0 +1,109 @@ +create database student +on +( + name='student', + filename='D:\stu\student.mdf', + size=10mb, + maxsize=100mb, + filegrowth=2mb +) +log on +( + name='student_log', + filename='D:\stu\student_log.ldf', + size=10mb, + maxsize=100mb, + filegrowth=2mb +) +use student +go +create table stuInfo +( + stuID int not null identity primary key, + stuName nchar(10), + stuAge nchar(10), + stuSex varchar(1), + time datetime +) + +create table courseInfo +( + courseID int not null primary key identity, + courseName nvarchar(10), + courseMarks nvarchar(5) +) +create table scoreInfo +( + scoreID int identity, + stuID INT FOREIGN KEY(stuId) references stuInfo(stuID), + courseID int foreign key(courseID) references courseInfo(courseID), + score int +) + + + +insert into stuInfo(stuName,stuAge,stuSex)values +('Tom',19,1), +('Jack',20,0), +('Rose',21,1), +('Lulu',19,1), +('Lili',21,0) +insert into stuInfo(stuName,stuAge,stuSex,time)values +('adc',20,1,'2007-01-07 01:11:36.590') +select * from stuInfo +insert into courseInfo(courseName,courseMarks)values +('JavaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) +select * from courseInfo +drop table courseInfo +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) +select * from scoreInfo--分数信息表 +select * from courseInfo--课程信息表 +select * from stuInfo--学生信息表 +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuName 姓名,count(courseInfo.courseID) 课程的数量, avg(score) 平均分 from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID group by stuName +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select * from scoreInfo--分数信息表 +select sc.courseID 课程编号,count(sc.stuID)学生个数,sum(sc.score) 分数 from scoreInfo sc +left join courseInfo co on sc.courseID = co.courseID +group by sc.courseID +--3.查询出性别一样并且年龄一样的学生的信息 +select b.* from stuInfo a,stuInfo b where a.stuSex = b.stuSex and a.stuAge = b.stuAge and a.stuName != b.stuName +--4.查询出学分 一样的课程信息 +select a.courseID,a.courseName,a.courseMarks from courseInfo a,courseInfo b +where a.courseMarks=b.courseMarks and a.courseName != b.courseName +group by a.courseID, a.courseName,a.courseMarks + +select * from courseInfo +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select scoreInfo.scoreId 学号, stuName 学生姓名, scoreInfo.courseID 课程号 ,score 分数 from scoreInfo left join stuInfo on +scoreInfo.stuid=stuInfo.stuid inner join courseInfo on scoreInfo.courseID=courseInfo.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.scoreId 学号, courseName 课程名, courseInfo.courseID ,coursemarks ,score 分数 from courseInfo left join scoreInfo on +courseInfo.courseID=scoreInfo.courseID +--7.查询出没有参加考试的学生的 学号和姓 + select *from stuInfo where stuID NOT IN( select stuID from scoreInfo ) +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" new file mode 100644 index 0000000..39c308f --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" @@ -0,0 +1,125 @@ +use master +go +create database wangba +on +( + name='wangba', + filename='D:\wb\wangba.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='wangba_log', + filename='D:\wb\wangba_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + + +use wangba +go +create table tbl_card +( + id varchar(25) primary key, + [passWord] varchar(30) not null, + balance money not null, + userName varchar(20) not null +) + + + +insert into tbl_card values +('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'验证'), +('0078_RJV','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张峻') + +select * from tbl_card + +use wangba +go +create table tbl_computer +( + id varchar(20) primary key, + onUse char(2) check(onUse=0 or onUse=1), + note text +) +go + +insert into tbl_computer values('02','0','25555'), +('03','1','55555'), +('04','0','66666'), +('05','1','88888'), +('06','0','688878'), +('B01','0','558558') + +select * from tbl_computer + +use wangba +go +create table tbl_record +( + id varchar(30) primary key, + cardId varchar(25) constraint FK_tbl_record_cardId references tbl_card(id), + ComputerId varchar(20) constraint FK_tbl_record_ComputerId references tbl_computer(id), + beginTime time, + endTime time, + fee money +) +go + +insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values +('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +('47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3'), +('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId +where userName='张军' order by fee desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(*)次数,sum(fee)总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId 卡号,sum(fee)总金额 from tbl_record group by cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select cardId 卡号,userName 用户名 from tbl_record +right join tbl_card on tbl_card.id = tbl_record.cardId where tbl_card.id not in(select cardId from tbl_record) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card A,tbl_card B where A.passWord = B.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 使用最多的机器号,count(*)次数 from tbl_record group by ComputerId order by count(*) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +--I can't do it + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -- Gitee From f401e0940e5dcbedfac4ab68f2a0608e70577875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=8F=B6=E5=B8=85?= <2876015251@qq.com> Date: Thu, 1 Apr 2021 12:42:36 +0800 Subject: [PATCH 139/195] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC=E5=8D=81=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/?= =?UTF-8?q?=E9=BB=84=E5=8F=B6=E5=B8=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 109 --------------- .../SQLQuery2.sql" | 125 ------------------ 2 files changed, 234 deletions(-) delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" delete mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" deleted file mode 100644 index c6dc5ac..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" +++ /dev/null @@ -1,109 +0,0 @@ -create database student -on -( - name='student', - filename='D:\stu\student.mdf', - size=10mb, - maxsize=100mb, - filegrowth=2mb -) -log on -( - name='student_log', - filename='D:\stu\student_log.ldf', - size=10mb, - maxsize=100mb, - filegrowth=2mb -) -use student -go -create table stuInfo -( - stuID int not null identity primary key, - stuName nchar(10), - stuAge nchar(10), - stuSex varchar(1), - time datetime -) - -create table courseInfo -( - courseID int not null primary key identity, - courseName nvarchar(10), - courseMarks nvarchar(5) -) -create table scoreInfo -( - scoreID int identity, - stuID INT FOREIGN KEY(stuId) references stuInfo(stuID), - courseID int foreign key(courseID) references courseInfo(courseID), - score int -) - - - -insert into stuInfo(stuName,stuAge,stuSex)values -('Tom',19,1), -('Jack',20,0), -('Rose',21,1), -('Lulu',19,1), -('Lili',21,0) -insert into stuInfo(stuName,stuAge,stuSex,time)values -('adc',20,1,'2007-01-07 01:11:36.590') -select * from stuInfo -insert into courseInfo(courseName,courseMarks)values -('JavaBase',4), -('HTML',2), -('JavaScript',2), -('SqlBase',2) -select * from courseInfo -drop table courseInfo -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) -select * from scoreInfo--分数信息表 -select * from courseInfo--课程信息表 -select * from stuInfo--学生信息表 ---有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) - ---题目: ---1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 -select stuName 姓名,count(courseInfo.courseID) 课程的数量, avg(score) 平均分 from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID -inner join courseInfo on scoreInfo.courseID=courseInfo.courseID group by stuName ---2.查询出每门课程的选修的学生的个数和学生考试的总分 -select * from scoreInfo--分数信息表 -select sc.courseID 课程编号,count(sc.stuID)学生个数,sum(sc.score) 分数 from scoreInfo sc -left join courseInfo co on sc.courseID = co.courseID -group by sc.courseID ---3.查询出性别一样并且年龄一样的学生的信息 -select b.* from stuInfo a,stuInfo b where a.stuSex = b.stuSex and a.stuAge = b.stuAge and a.stuName != b.stuName ---4.查询出学分 一样的课程信息 -select a.courseID,a.courseName,a.courseMarks from courseInfo a,courseInfo b -where a.courseMarks=b.courseMarks and a.courseName != b.courseName -group by a.courseID, a.courseName,a.courseMarks - -select * from courseInfo ---5.查询出参加了考试的学生的学号,姓名,课程号和分数 -select scoreInfo.scoreId 学号, stuName 学生姓名, scoreInfo.courseID 课程号 ,score 分数 from scoreInfo left join stuInfo on -scoreInfo.stuid=stuInfo.stuid inner join courseInfo on scoreInfo.courseID=courseInfo.courseID - ---6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 -select scoreInfo.scoreId 学号, courseName 课程名, courseInfo.courseID ,coursemarks ,score 分数 from courseInfo left join scoreInfo on -courseInfo.courseID=scoreInfo.courseID ---7.查询出没有参加考试的学生的 学号和姓 - select *from stuInfo where stuID NOT IN( select stuID from scoreInfo ) ---8.查询出是周六周天来报到的学生 - ---9.查询出姓名中有字母a的学生的信息 - ---10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 - diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" deleted file mode 100644 index 39c308f..0000000 --- "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" +++ /dev/null @@ -1,125 +0,0 @@ -use master -go -create database wangba -on -( - name='wangba', - filename='D:\wb\wangba.mdf', - size=5mb, - maxsize=50mb, - filegrowth=10% -) - -log on -( - name='wangba_log', - filename='D:\wb\wangba_log.ldf', - size=5mb, - maxsize=50mb, - filegrowth=10% -) - - -use wangba -go -create table tbl_card -( - id varchar(25) primary key, - [passWord] varchar(30) not null, - balance money not null, - userName varchar(20) not null -) - - - -insert into tbl_card values -('0023_ABC','555',98,'张军'), -('0025_bbd','abe',300,'朱俊'), -('0036_CCD','何柳',100,'何柳'), -('0045_YGR','0045_YGR',58,'验证'), -('0078_RJV','55885fg',600,'校庆'), -('0089_EDE','zhang',134,'张峻') - -select * from tbl_card - -use wangba -go -create table tbl_computer -( - id varchar(20) primary key, - onUse char(2) check(onUse=0 or onUse=1), - note text -) -go - -insert into tbl_computer values('02','0','25555'), -('03','1','55555'), -('04','0','66666'), -('05','1','88888'), -('06','0','688878'), -('B01','0','558558') - -select * from tbl_computer - -use wangba -go -create table tbl_record -( - id varchar(30) primary key, - cardId varchar(25) constraint FK_tbl_record_cardId references tbl_card(id), - ComputerId varchar(20) constraint FK_tbl_record_ComputerId references tbl_computer(id), - beginTime time, - endTime time, - fee money -) -go - -insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values -('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), -('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), -('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), -('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), -('47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), -('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), -('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), -('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3'), -('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), -('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') - -select * from tbl_card -select * from tbl_computer -select * from tbl_record - ---请完成以下题目: ---1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 -select tbl_card.id 卡号,userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_card -inner join tbl_record on tbl_card.id = tbl_record.cardId -where userName='张军' order by fee desc - ---2. 查询出每台机器上的上网次数和消费的总金额 -select ComputerId 机器,count(*)次数,sum(fee)总金额 from tbl_record group by ComputerId - ---3. 查询出所有已经使用过的上网卡的消费总金额 -select cardId 卡号,sum(fee)总金额 from tbl_record group by cardId - ---4. 查询出从未消费过的上网卡的卡号和用户名 -select cardId 卡号,userName 用户名 from tbl_record -right join tbl_card on tbl_card.id = tbl_record.cardId where tbl_card.id not in(select cardId from tbl_record) - ---5. 将密码与用户名一样的上网卡信息查询出来 -select * from tbl_card A,tbl_card B where A.passWord = B.userName - ---6. 查询出使用次数最多的机器号和使用次数 -select top 1 ComputerId 使用最多的机器号,count(*)次数 from tbl_record group by ComputerId order by count(*) desc - ---7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 - - ---8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 ---I can't do it - ---9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_card -inner join tbl_record on tbl_card.id = tbl_record.cardId - ---10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -- Gitee From 711cc1807ce502db453a0cafe1c5819259a019f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=8F=B6=E5=B8=85?= <2876015251@qq.com> Date: Thu, 1 Apr 2021 12:46:08 +0800 Subject: [PATCH 140/195] SQL --- .../SQLQuery1.sql" | 111 ++++++++++++++++ .../SQLQuery2.sql" | 125 ++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" new file mode 100644 index 0000000..30f53ad --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" @@ -0,0 +1,111 @@ +create database student +on +( + name='student', + filename='D:\stu\student.mdf', + size=10mb, + maxsize=100mb, + filegrowth=2mb +) +log on +( + name='student_log', + filename='D:\stu\student_log.ldf', + size=10mb, + maxsize=100mb, + filegrowth=2mb +) +use student +go +create table stuInfo +( + stuID int not null identity primary key, + stuName nchar(10), + stuAge nchar(10), + stuSex varchar(1), + time datetime +) + +create table courseInfo +( + courseID int not null primary key identity, + courseName nvarchar(10), + courseMarks nvarchar(5) +) +create table scoreInfo +( + scoreID int identity, + stuID INT FOREIGN KEY(stuId) references stuInfo(stuID), + courseID int foreign key(courseID) references courseInfo(courseID), + score int +) + + + +insert into stuInfo(stuName,stuAge,stuSex)values +('Tom',19,1), +('Jack',20,0), +('Rose',21,1), +('Lulu',19,1), +('Lili',21,0) +insert into stuInfo(stuName,stuAge,stuSex,time)values +('adc',20,1,'2007-01-07 01:11:36.590') +select * from stuInfo +insert into courseInfo(courseName,courseMarks)values +('JavaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) +select * from courseInfo +drop table courseInfo +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) +select * from scoreInfo--分数信息表 +select * from courseInfo--课程信息表 +select * from stuInfo--学生信息表 +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuName 姓名,count(courseInfo.courseID) 课程的数量, avg(score) 平均分 from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID group by stuName +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select * from scoreInfo--分数信息表 +select sc.courseID 课程编号,count(sc.stuID)学生个数,sum(sc.score) 分数 from scoreInfo sc +left join courseInfo co on sc.courseID = co.courseID +group by sc.courseID +--3.查询出性别一样并且年龄一样的学生的信息 +select b.* from stuInfo a,stuInfo b where a.stuSex = b.stuSex and a.stuAge = b.stuAge and a.stuName != b.stuName +--4.查询出学分 一样的课程信息 +select a.courseID,a.courseName,a.courseMarks from courseInfo a,courseInfo b +where a.courseMarks=b.courseMarks and a.courseName != b.courseName +group by a.courseID, a.courseName,a.courseMarks + +select * from courseInfo +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select scoreInfo.scoreId 学号, stuName 学生姓名, scoreInfo.courseID 课程号 ,score 分数 from scoreInfo left join stuInfo on +scoreInfo.stuid=stuInfo.stuid inner join courseInfo on scoreInfo.courseID=courseInfo.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.scoreId 学号, courseName 课程名, courseInfo.courseID ,coursemarks ,score 分数 from courseInfo left join scoreInfo on +courseInfo.courseID=scoreInfo.courseID +--7.查询出没有参加考试的学生的 学号和姓 + select *from stuInfo where stuID NOT IN( select stuID from scoreInfo ) +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from StuInfo where stuName like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuInfo.stuID 学号,avg(score)平均分,count(*)选修课程数量 from stuInfo +inner join scoreInfo on stuInfo.stuID = scoreInfo.stuID group by stuInfo.stuID +having count(*)>2 and avg(score)>70 diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" new file mode 100644 index 0000000..660f429 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery2.sql" @@ -0,0 +1,125 @@ +use master +go +create database wangba +on +( + name='wangba', + filename='D:\wb\wangba.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='wangba_log', + filename='D:\wb\wangba_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + + +use wangba +go +create table tbl_card +( + id varchar(25) primary key, + [passWord] varchar(30) not null, + balance money not null, + userName varchar(20) not null +) + + + +insert into tbl_card values +('0023_ABC','555',98,'张军'), +('0025_bbd','abe',300,'朱俊'), +('0036_CCD','何柳',100,'何柳'), +('0045_YGR','0045_YGR',58,'验证'), +('0078_RJV','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张峻') + +select * from tbl_card + +use wangba +go +create table tbl_computer +( + id varchar(20) primary key, + onUse char(2) check(onUse=0 or onUse=1), + note text +) +go + +insert into tbl_computer values('02','0','25555'), +('03','1','55555'), +('04','0','66666'), +('05','1','88888'), +('06','0','688878'), +('B01','0','558558') + +select * from tbl_computer + +use wangba +go +create table tbl_record +( + id varchar(30) primary key, + cardId varchar(25) constraint FK_tbl_record_cardId references tbl_card(id), + ComputerId varchar(20) constraint FK_tbl_record_ComputerId references tbl_computer(id), + beginTime time, + endTime time, + fee money +) +go + +insert into tbl_record(id,cardId,ComputerId,beginTime,endTime,fee) values +('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +('47','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','3'), +('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器编号,beginTime 开始时间,endTime 结束时间,fee 消费金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId +where userName='张军' order by fee desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId 机器,count(*)次数,sum(fee)总金额 from tbl_record group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardId 卡号,sum(fee)总金额 from tbl_record group by cardId + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select cardId 卡号,userName 用户名 from tbl_record +right join tbl_card on tbl_card.id = tbl_record.cardId where tbl_card.id not in(select cardId from tbl_record) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card A,tbl_card B where A.passWord = B.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 使用最多的机器号,count(*)次数 from tbl_record group by ComputerId order by count(*) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_card.id 卡号,userName 用户名,ComputerId 机器号,beginTime 开始时间,endTime 结束时间,fee 金额 from tbl_card +inner join tbl_record on tbl_card.id = tbl_record.cardId + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 -- Gitee From 0dbcce534adc1391cf48b45f5fd2251376c559f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=BE=E5=A4=A7=E6=98=9F=E5=91=80?= <2454478226@qq.com> Date: Thu, 1 Apr 2021 12:49:29 +0800 Subject: [PATCH 141/195] zy --- .../zy.sql" | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" new file mode 100644 index 0000000..7154600 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" @@ -0,0 +1,104 @@ + +create database Jxc + +on +( + name='Jxc', + filename='D:\Jxc.mdf' +) +log on +( + name='Jxc_log', + filename='D:\Jxc.ldf_log' +) +use Jxc +create table stuInfo +( + stuID int primary key , + stuName varchar(20), + stuAge int , + stuSex nvarchar(1), + stime datetime +) + +create table courseInfo +( + courseID int primary key , + courseName varchar(25), + courseMarks varchar(5) +) +create table scoreInfo +( + scoreID int primary key identity(1,1), + stuID int foreign key references stuInfo(stuID) , + courseID int foreign key references courseInfo(courseID), + score int +) +--学生信息表 +insert into stuInfo(stuID,stuName,stuAge,stuSex) +select 1,'Tom',19,1 union +select 2,'Jack',20,0union +select 3,'Rose',21,1union +select 4,'Lulu',19,1 union +select 5,'Lili',21,0union +select 6,'abc',20,1 + +update stuInfo set stime='2007-01-07 01:11:36.590'where stuName='abc' +--课程表 +insert into courseInfo(courseID,courseName,courseMarks) +select 1,'JavaBase',4 union +select 2,'HTML',2 union +select 3,'JavaScript',2 union +select 4,'SqlBase',2 +-- 成绩表 +insert into scoreInfo(stuID,courseID,score) +select 1,1,80 union +select 1,2,85 union +select 1,4,50 union +select 2,1,75 union +select 2,3,45 union +select 2,4,75 union +select 3,1,45 union +select 4,1,95 union +select 4,2,75 union +select 4,3,90 union +select 4,4,45 + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +select * from stuInfo --学生信息表 +select * from courseInfo --课程表 +select * from scoreInfo -- 成绩表 +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo group by stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseID 课程, count(courseID)选修个数, sum(score)总分 from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 +select A.* from stuInfo A, stuInfo B +where A.stuSex=B.stuSex AND A.stuAge=B.stuAge AND A.stuID!=B.stuID +--4.查询出学分一样的课程信息 +select distinct A.* from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks AND A.courseID!=B.courseID +--5.查询出参加了 考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID 学号,stuName 姓名,courseID 课程号,score from scoreInfo +left join stuInfo on scoreInfo.stuID=stuInfo.stuID group by scoreInfo.stuID,stuName,courseID,score +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID 学号, scoreInfo.courseID 课程号,courseInfo.courseName 课程名,courseMarks 学分,scoreInfo.score 分数 from scoreInfo +left join courseInfo on scoreInfo.courseID=courseInfo.courseID +--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 stuName like '%a%' +--10.查询出 选修了2门课程 以上的 并且 考试平均分 在70以上 的学生的 学号 和 考试平均分 以及 选修课程的数量 +select stuID,count(courseID)课程的数量,avg(score)平均分 from scoreInfo +group by stuID +having avg(score)>=70 and count(courseID)>=2 + +select * from courseInfo --课程表 +select * from scoreInfo -- 成绩表 +select * from stuInfo --学生信息表 \ No newline at end of file -- Gitee From 2c912e3d62440f87f3f3d5c9450e520a875070ff Mon Sep 17 00:00:00 2001 From: jckyang <235723419@qq.com> Date: Thu, 1 Apr 2021 13:22:22 +0800 Subject: [PATCH 142/195] 2 --- .../\346\261\237\346\264\213/SQLQuery1.sql" | 125 +++++++++++++++++ .../\346\261\237\346\264\213/SQLQuery2.sql" | 126 ++++++++++++++++++ 2 files changed, 251 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" create mode 100644 "\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" new file mode 100644 index 0000000..61779bd --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" @@ -0,0 +1,125 @@ +create database AKA +on +( + name='D:\AKA', + filename='D:\AKA.mdf', + size=5, + maxsize=50, + filegrowth=10% +) +log +on +( + name='D:\AKA_log', + filename='D:\AKA_log.ldf', + size=5, + maxsize=50, + filegrowth=10% +) +use AKA +create table stu +( + stuID int identity primary key not null, + stuName varchar(10) not null, + stuAge int not null, + stuSex varchar(2) not null check(stuSex='男' or stuSex='女'), + stutime datetime +) +create table cou +( + courseID int identity primary key not null, + courseName varchar(15) not null, + courseMarks int not null +) +create table sco +( + scoreID int identity not null, + stuID int foreign key references stu(stuID), + courseID int foreign key references cou(courseID), + score int not null, +) +insert into stu values +('Tom',19,'男',null), +('Jack',20,'女',null), +('Rose',21,'男',null), +('Lulu',19,'男',null), +('Lili',21,'女',null), +('abc',20,'男','2007-01-07 01:11:36.590') +select * from stu + +insert into cou values +('JavaBase',4), +('HTML',2), +('JavaScript',2), +('SqlBase',2) + +select * from cou + +insert into sco 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) + +select * from sco + +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) + +--题目: +select * from stu +select * from cou +select * from sco +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 + +select stu.stuID 学号,count(*) 课程数量,avg(score)平均分 from stu left join sco on stu.stuID=sco.stuID group by stu.stuID + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + +select courseName 课程,count(*)人数,sum(score)总分 from cou left join sco on cou.courseID=sco.stuID group by courseName + +--3.查询出性别一样并且年龄一样的学生的信息 + +select c.* from stu c,stu s where c.stuAge=s.stuAge and c.stuSex=s.stuSex and c.stuID!=s.stuID + + +--4.查询出学分一样的课程信息 + +select distinct A.* from cou A,cou B where A.courseMarks=B.courseMarks and A.courseID!=B.courseID + +select * from stu +select * from cou +select * from sco + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +select stu.stuID 学号,stuName 姓名,sco.courseID 课程号,score 分数 from stu right join sco on stu.stuID=sco.stuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +select stuID 学号,sco.courseID 课程号,courseName 课程名,courseMarks 课程学分,score 分数 from sco left join cou on sco.courseID=cou.courseID + +--7.查询出没有参加考试的学生的学号和姓名 + +select stu.stuID,stuName from stu left join sco on stu.stuID=sco.stuID where score is null + +--8.查询出是周六周天来报到的学生 +select stuName from stu where DATEPART(WEEKDAY,stutime)=1 or DATEPART(WEEKDAY,stutime)=7 + +--9.查询出姓名中有字母a的学生的信息 + + +select * from stu where stuname like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select avg(score)平均分,stuID 学号,count(*)课程数 from sco group by stuID having avg(score)>70 and count(*)>2 +select * from stu +select * from cou +select * from sco diff --git "a/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery2.sql" new file mode 100644 index 0000000..14fb6de --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery2.sql" @@ -0,0 +1,126 @@ +create database wb +on +( name='wb', + filename='D:\wb-mdf', + size=5, + maxsize=500, + filegrowth=1 +) + log on +( name='wb_log', + filename='D:\wb_log-ldf', + size=5, + maxsize=500, + filegrowth=1 +) +go +use wb +go +create table tbl_card +( + id varchar(8) primary key, + passWord varchar(15) not null, + balance money not null, + userName nchar(5) +) +create table tbl_computer +( + id char(5) primary key, + onUse int not null, + note text not null +) +create table tbl_record +( + id int primary key, + cardld varchar(8) references tbl_card(id), + ComputerId char(5) references tbl_computer(id), + beginTime datetime , + endTime datetime, + fee money not null +) +insert into tbl_card values('0023_ABC','555',99,'张军'),('0025_bbd','abc',300,'朱俊'),('0036_CCD','何柳',100,'何柳'),('0045_YGR','0045_YGR',58,'验证'),('0078_RJV','55885fg',600,'校庆'),('0089_EDE','zhang',134,'张俊') + +insert into tbl_computer values('02',0,'25555'),('03',1,'55555'),('04',0,'66666'),('05',1,'888888'),('06',0,'688878'),('B01',0,'558558') + + +insert into tbl_record values +('23','0078_RJV','B01','2007-07-15 19:00:00','2007-07-15 21:00:00','20'), +('34','0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00','23'), +('45','0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00','50'), +('46','0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00','6'), +('47','0023_ABC','03','2006-12-23 15:26:00','2007-12-23 22:55:00','50'), +('48','0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00','6'), +('55','0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00','50'), +('64','0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00','30'), +('65','0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00','23'), +('98','0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00','23') + +select*from tbl_card +select*from tbl_computer +select*from tbl_record +--请完成以下题目: +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select cardld 卡号, userName 用户名, beginTime 开始时间, endTime 结束时间, fee 消费金额 + from tbl_record + join tbl_computer + on tbl_computer.id=tbl_record.ComputerId + join tbl_card + on cardld=tbl_card.id + where userName='张军' + order by fee + + +--2. 查询出每台机器上的上网次数和消费的总金额 +select ComputerId, count(ComputerId) 上网次数,sum(fee) 消费总金额 + from tbl_record + group by ComputerId + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select cardld 网卡, sum(fee) 消费总金额 from tbl_record group by cardld + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select id 卡号 , userName 用户名 + from tbl_card + where id not in (select cardld from tbl_record ) + +--5. 将密码与用户名一样的上网卡信息查询出来 +select T.id 卡号,T.passWord 密码,T.balance 卡上的余额,T.userName 用户名 + from tbl_card,tbl_card T + where tbl_card.passWord=T.userName + +select T.* + from tbl_card,tbl_card T + where tbl_card.passWord=T.userName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerId 机器号, count(ComputerId) 使用次数 + from tbl_record + group by ComputerId + order by count(ComputerId) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,fee 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + where cardld like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + where datediff(HOUR,beginTime,endTime)>=12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 cardld 卡号, userName 用户名, ComputerId 机器号,beginTime 开始时间,endTime 结束时间, fee 消费金额 + from tbl_record + join tbl_card + on tbl_card.id=cardld + order by fee desc \ No newline at end of file -- Gitee From f84859e42656c6feeed684e4d6494b3aaa3f3b71 Mon Sep 17 00:00:00 2001 From: zhangyife2020 <1599857331@qq.com> Date: Thu, 1 Apr 2021 19:00:45 +0800 Subject: [PATCH 143/195] =?UTF-8?q?=E7=AC=AC12=E6=AC=A1=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git commit -m绗12娆′綔涓氣 --- .../SQLQuery1.sql" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" new file mode 100644 index 0000000..fa5e44d --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SQLQuery1.sql" @@ -0,0 +1,62 @@ +use master +go +create database GoodsDB +on +( name='GoodsDB', + filename='D:\GoodsDB.mdf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +log on +( name='GoodsDB_log', + filename='D:\GoodsDB_log.ldf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +go +use GoodsDB +go + +create table GoodsType +( + TypeID int primary key identity, + TypeName nvarchar(20) not null + +) + +create table GoodsInfo +( + GoodsID int primary key identity, + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) not null, + GoodsMoney money not null, + TypeID int references GoodsType(TypeID) +) + +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + +insert into GoodsInfo values('提花小西装', '红色', '菲曼琪', '300', 1),('百搭短裤', '绿色', '哥弟', '100', 1), + ('无袖背心', '白色', '阿依莲', '700', 1),('低帮休闲鞋', '红色', '菲曼琪', '900', 2), + ('中跟单鞋', '绿色', '哥弟', '400', 2),('平底鞋', '白色', '阿依莲','200', 2), + ('迷你照相机', '红色', '尼康', '500', 3),('硬盘', '黑色', '希捷', '600', 3), + ('显卡', '黑色', '技嘉','800', 3) +select*from GoodsType +select*from GoodsInfo + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + select GoodsName 商品名称, GoodsColor 商品颜色, GoodsMoney 商品价格 + from GoodsInfo + where GoodsMoney=(select max(GoodsMoney) from GoodsInfo) + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格, avg(GoodsMoney) 平均价格 + from GoodsInfo + join GoodsType + on GoodsType.TypeID=GoodsInfo.TypeID + group by TypeName + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and (GoodsMoney between 300 and 600) \ No newline at end of file -- Gitee From 6d66b8dfada3167cb1549666648842561666d7f5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 1 Apr 2021 19:14:20 +0800 Subject: [PATCH 144/195] 44444 --- .../\345\220\264\347\205\214/SQLQuery1.sql" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/SQLQuery1.sql" new file mode 100644 index 0000000..c2dd0f6 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\220\264\347\205\214/SQLQuery1.sql" @@ -0,0 +1,56 @@ +drop database GoodsDB +create database GoodsDB +on +( + name='GoodsDB', + filename='F:\GoodsDB.mdf' +) +log on +( + name='GoodsDB_log', + filename='F:\GoodsDB_log.mdf' +) +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 references GoodsType(TypeID) +) +insert into GoodsType +select '服装内衣' union +select '鞋包配饰' union +select '手机数码' +select * from GoodsType +insert into GoodsInfo(GoodsName,GoodsColor,GoodsBrand,GoodsMoney,TypeID) +select '提花小西装', '红色', '菲曼琪', '300', 1 union +select '百搭短裤', '绿色', '哥弟', '100 ', 1 union +select '无袖背心', '白色', '阿依莲', '700 ', 1 union +select '低帮休闲鞋', '红色', '菲曼琪', '900', 2 union +select '中跟单鞋', '绿色', '哥弟', '400', 2 union +select '平底鞋', '白色', '阿依莲', '200 ', 2 union +select '迷你照相机', '红色', '尼康', '500', 3 union +select '硬盘', '黑色', '希捷 ', '600 ', 3 union +select '显卡 ', '黑色', '技嘉', '800 ', 3 +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + +select GoodsName 商品名称,GoodsColor 商品颜色 ,GoodsMoney 商品价格 from GoodsInfo +where GoodsMoney in (select max(GoodsMoney) from GoodsInfo) +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID,max(GoodsMoney)最高价格,min(GoodsMoney)最低价格,avg(GoodsMoney)平均价格 +from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 + +select * from GoodsType +select * from GoodsInfo \ No newline at end of file -- Gitee From 894e2e83e84ebdd8a446ff1d61596f3ae2f5c7d1 Mon Sep 17 00:00:00 2001 From: chenshuaihui <1926162199@qq.com> Date: Thu, 1 Apr 2021 20:25:15 +0800 Subject: [PATCH 145/195] =?UTF-8?q?=E9=99=88=E5=B8=85=E8=BE=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" new file mode 100644 index 0000000..577d15d --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\345\270\205\350\276\211/SQLQuery1.sql" @@ -0,0 +1,53 @@ +use master +go +create database GoodsDB +on +( + name='GoodsDB', + filename='D:\GoodsDB.mdf', + size=5MB, + maxsize=50MB, + filegrowth=10% +) +log on +( + name='GoodsDB_log', + filename='D:\GoodsDB_log.ldf', + size=5MB, + maxsize=50MB, + filegrowth=10% +) +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null, + +) +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + +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) not null, + GoodsMoney money not null, + TypeID int references GoodsType(TypeID) +) +insert into GoodsInfo values('提花小西装','红色','菲曼琪' ,'300', 1),('百搭短裤','绿色','哥弟' ,'100', 1), +('无袖背心', '白色', '阿依莲', '700', 1),('低帮休闲鞋', '红色',' 菲曼琪',' 900', 2),('中跟单鞋','绿色','哥弟','400', 2), +('平底鞋','白色','阿依莲','200', 2),('迷你照相机','红色','尼康','500',3),('硬盘','黑色','希捷', '600', 3), +('显卡','黑色','技嘉','800',3) +select * from GoodsInfo +select * from GoodsType +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称, GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney desc + + +select GoodsName 商品名称, GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney in (select max(GoodsMoney) from GoodsInfo) +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型编号,max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and (GoodsMoney between 300 and 600) + + -- Gitee From 9a953a23c9e7466defae09e0391846c34038f8ff Mon Sep 17 00:00:00 2001 From: li-qingcai <2811189126@qq.com> Date: Thu, 1 Apr 2021 20:25:52 +0800 Subject: [PATCH 146/195] 4.1 --- .../SQLQuery1.sql" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery1.sql" new file mode 100644 index 0000000..f4f9a30 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\216\345\272\206\346\211\215/SQLQuery1.sql" @@ -0,0 +1,49 @@ +use master +go +create database GoodsDB +on +( + name='GoodsDB', + filename='D:\GoodsDB.mdf', + size=5MB, + maxsize=50MB, + filegrowth=10% +) +log on +( + name='GoodsDB_log', + filename='D:\GoodsDB_log.ldf', + size=5MB, + maxsize=50MB, + filegrowth=10% +) +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null, + +) +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + +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) not null, + GoodsMoney money not null, + TypeID int references GoodsType(TypeID) +) +insert into GoodsInfo values('提花小西装','红色','菲曼琪' ,'300', 1),('百搭短裤','绿色','哥弟' ,'100', 1), +('无袖背心', '白色', '阿依莲', '700', 1),('低帮休闲鞋', '红色',' 菲曼琪',' 900', 2),('中跟单鞋','绿色','哥弟','400', 2), +('平底鞋','白色','阿依莲','200', 2),('迷你照相机','红色','尼康','500',3),('硬盘','黑色','希捷', '600', 3), +('显卡','黑色','技嘉','800',3) +select * from GoodsInfo +select * from GoodsType +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney in(select max(GoodsMoney) from GoodsInfo) + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型编号,max(GoodsMoney)最高价格,min(GoodsMoney)最低价格,avg(GoodsMoney)平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select *from GoodsInfo where GoodsColor='红色'and (GoodsMoney between 300 and 600) \ No newline at end of file -- Gitee From 7c6056c11832a67e0342e955f7d37541fe4709be Mon Sep 17 00:00:00 2001 From: lazy-scholar-cat <2220771866@qq.com> Date: Thu, 1 Apr 2021 20:31:54 +0800 Subject: [PATCH 147/195] cat --- .../SQLQuery1.sql" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery1.sql" new file mode 100644 index 0000000..c87ad33 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\224\220\344\274\237\345\273\272/SQLQuery1.sql" @@ -0,0 +1,67 @@ +create database GoodsDB + +use GoodsDB +go + +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) + +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null , + GoodsColor nvarchar(20) not null , + GoodsBrand nvarchar(20) , + GoodsMoney money not null, + TypeID int foreign key references GoodsType(TypeID) +) + +insert into GoodsType values +('服装内衣'), +('鞋包配饰'), +('手机数码') + + +insert into GoodsInfo values +('提花小西装','红色','菲曼琪','300',1), +('百搭短裤','绿色','哥弟','100',1), +('无袖背心','白色','阿依莲','700',1), +('低帮休闲鞋','红色','菲曼琪','900',2), +('中跟单鞋','绿色','哥弟','400',2), +('平底鞋','白色','阿依莲','200',2), +('迷你照相机','红色','尼康','500',3), +('硬盘','黑色','希捷','600',3), +('显卡','黑色','技嘉','800',3) + + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney in (select max(GoodsMoney) from GoodsInfo) +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型编号,Max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格,AVG(GoodsMoney) 平均价格 from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between '300' and '600' + + + + + + + + + + + + + + + + + + + + + -- Gitee From af41f42ad14bf11e19074a59d1bbad3da4f111f3 Mon Sep 17 00:00:00 2001 From: yangwenrong <956352682@qq.com> Date: Thu, 1 Apr 2021 20:43:50 +0800 Subject: [PATCH 148/195] 2021.4.1.20 --- .../SQLQuery1.sql" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" new file mode 100644 index 0000000..90775fd --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SQLQuery1.sql" @@ -0,0 +1,63 @@ +use master +go + +create database GoodsDB +on +( + name='GoodsDB', + filename='C:\学习\数据库\GoodsDB.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +log on +( + name='GoodsDB_log', + filename='C:\学习\数据库\GoodsDB_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +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 references GoodsType(TypeID) +) + +insert into GoodsType values +('服装内衣'), +('鞋包配饰'), +('手机数码') + +insert into GoodsInfo values +('提花小西装','红色','菲曼琪',300,1), +('百搭短裤','绿色','哥弟',100,1), +('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2), +('中跟单鞋','绿色','哥弟',400,2), +('平底鞋','白色','阿依莲',200,2), +('迷你照相机','红色','尼康',500,3), +('硬盘','黑色','希捷',600,3), +('显卡','黑色','技嘉',800,3) +select * from GoodsInfo +select * from GoodsType +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney in (select max(GoodsMoney) from GoodsInfo) + +--4、按商品类型编号 分组查询 商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型编号,max(GoodsMoney) 商品最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney)平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney>=300 and GoodsMoney<=600 -- Gitee From 1557cefdf35dc10148efc8337ee9c1d079dfd528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=80?= <8332095+Xone-by-one@user.noreply.gitee.com> Date: Thu, 1 Apr 2021 20:46:34 +0800 Subject: [PATCH 149/195] 123 --- .../SQLQuery1.sql" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" new file mode 100644 index 0000000..2bd05e8 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\220\346\261\237\346\273\250/SQLQuery1.sql" @@ -0,0 +1,58 @@ +create database GoodsDB +on +( +name='GoodsDB_data', +filename='C:\app\GoodsDB_data.mdf', +size=10mb, +maxsize=100mb, +filegrowth=10% +) +log on +( +name='GoodsDB_log', +filename='C:\app\GoodsDB_log.ldf', +size=10mb, +filegrowth=1mb +) +USE GoodsDB +go +create table GoodsType +( +TypeID int primary key IDENTITY(1,1) not null, +TypeName nvarchar(20) +) +insert GoodsType(TypeID,TypeName) +select 1,'服装内衣' union +select 2,'鞋包配饰' union +select 3,'手机数码' + +go +create table GoodsInfo +( +GoodsID int primary key IDENTITY(1,1) not null, +GoodsName nvarchar(20), +GoodsColor nvarchar(20), +GoodsBrand nvarchar(20), +GoodsMoney money, +TypeID int foreign key references GoodsType(TypeID) +) +insert GoodsInfo(GoodsID,GoodsName,GoodsColor,GoodsBrand,GoodsMoney,TypeID) +select 1,'提花小西装','红色','菲曼琪',300,1 union +select 2,'百搭短裤','绿色','哥弟',100,1 union +select 3,'无袖背心','白色','阿依莲',700,1 union +select 4,'低帮休闲鞋','红色','菲曼琪',900,2 union +select 5,'中跟单鞋','绿色','哥弟',400,2 union +select 6,'平底鞋','白色','阿依莲',200,2 union +select 7,'迷你照相机','红色','尼康',500,3 union +select 8,'硬盘','黑色','希捷',600,3 union +select 9,'显卡','黑色','技嘉',800,3 + +Select * from GoodsType +select * from GoodsInfo + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName,GoodsColor,GoodsMoney from GoodsInfo where GoodsMoney=(select max(GoodsMoney) from GoodsInfo ) +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select max(GoodsMoney),min(GoodsMoney),avg(GoodsMoney) from GoodsInfo inner join GoodsType on GoodsInfo.TypeID=GoodsType.TypeID group by TypeName +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +Select GoodsID,GoodsColor='红色',GoodsMoney from GoodsInfo where GoodsMoney between 300 and 600 \ No newline at end of file -- Gitee From 3db42053b04f2563f2816b3fe11e5c1dcc44c866 Mon Sep 17 00:00:00 2001 From: source-wan <842143662@QQ.COM> Date: Thu, 1 Apr 2021 21:24:57 +0800 Subject: [PATCH 150/195] work --- .../SQLQuery1.sql" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" new file mode 100644 index 0000000..75fed28 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" @@ -0,0 +1,43 @@ +use master +go + +create database GoodsDB +go + +use GoodsDB +go +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) + +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) , + GoodsMoney money not null, + TypeID int foreign key references GoodsType(TypeID) +) + +insert into GoodsType +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 + +--查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select TOP 1 GoodsMoney 商品价格,GoodsName 商品名称,GoodsColor 商品颜色 from GoodsInfo + group by GoodsName,GoodsMoney,GoodsColor order by GoodsMoney DESC + +--按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 类型编号,max(GoodsMoney) 商品最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID + +--查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 100 and 600 -- Gitee From 1230c1739d56e970af576406ad9c20cc0b3bfe6f Mon Sep 17 00:00:00 2001 From: source-wan <842143662@QQ.COM> Date: Thu, 1 Apr 2021 21:26:04 +0800 Subject: [PATCH 151/195] work --- .../\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" index 75fed28..9d8dfb7 100644 --- "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\270\207\347\250\213\347\245\245/SQLQuery1.sql" @@ -40,4 +40,4 @@ select TOP 1 GoodsMoney select TypeID 类型编号,max(GoodsMoney) 商品最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID --查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 -select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 100 and 600 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 -- Gitee From 142e54b56e00f7965984d51f16f889b059c0b838 Mon Sep 17 00:00:00 2001 From: putar Date: Thu, 1 Apr 2021 21:56:23 +0800 Subject: [PATCH 152/195] 2021-4-1 21:56 --- .../SQLQuery1.sql" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" new file mode 100644 index 0000000..7808825 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" @@ -0,0 +1,45 @@ +use master +go + +create database GoodsDB +go + +use GoodsDB +go + +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null +) +go + +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 constraint FK_GoodsInfo_TypeID references GoodsType(TypeID) +) +go + +insert into GoodsType values ('服装内衣'),('鞋包数码'),('手机数码') + +insert into GoodsInfo values('提花小西装','红色','菲曼琪',300,1), +('百搭短裤','绿色','哥弟',100,1),('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2),('中跟单鞋','绿色','哥弟 ',400,2), +('平底鞋','白色','阿依莲',200,2),('迷你照相机','红色 ','尼康',500 ,3), +('硬盘','黑色','希捷',600,3),('显卡 ','黑色','技嘉',800,3) + +--查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) +--按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型,MAX(GoodsMoney)最高价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID +--查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 ,包含300和600么?咱不知道,咱也懒的问 +select * from GoodsInfo where (GoodsColor = '红色') and (GoodsMoney between 300 and 600) +select * from GoodsInfo where (GoodsColor = '红色') and (GoodsMoney >= 300 and GoodsMoney <= 600) +-- 如果不包含300和600 +select * from GoodsInfo where (GoodsColor = '红色') and ((GoodsMoney between 300 and 600) and (GoodsMoney not in(300,600))) +select * from GoodsInfo where (GoodsColor = '红色') and (GoodsMoney > 300 and GoodsMoney < 600) \ No newline at end of file -- Gitee From cc6ba72645289cc4faa7124eb3dac533fc2d2f1e Mon Sep 17 00:00:00 2001 From: linghuanye <1271919148@qq.com> Date: Thu, 1 Apr 2021 21:59:04 +0800 Subject: [PATCH 153/195] first commit --- .../SQLQuery1.sql" | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/SQLQuery1.sql" new file mode 100644 index 0000000..09f65f4 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\207\214\347\204\225\344\270\232/SQLQuery1.sql" @@ -0,0 +1,94 @@ +--1、创建商品数据库(GoodsDB) +use master +go + +create database GoodsDB +on +( + name='GoodsDB', + filename='E:\数据库\GoodsDB.mdf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) + +log on +( + name='GoodsDB_log', + filename='E:\数据库\GoodsDB_log.ldf', + size=5mb, + maxsize=100mb, + filegrowth=10% +) + +use GoodsDB +go +--商品类型表(GoodsType) +--字段名 说明 类型 长度 可否为空 约束 +--TypeID 商品类型编号 int 否 主键约束,自增约束,标识种子和标识增量都是1 +--TypeName 商品类型名称 nvarchar 20 否 +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null +) + +--商品信息表(GoodsInfo) +--字段名 说明 类型 长度 可否为空 约束 +--GoodsID 商品编号 int 否 主键约束,自增约束,标识种子和标识增量都是1 +--GoodsName 商品名称 nvarchar 20 否 +--GoodsColor商品颜色 nvarchar 20 否 +--GoodsBrand商品品牌 nvarchar 20 +--GoodsMoney商品价格 money 否 +--TypeID 商品类型编号 int 外键,参照GoodsType中的TypeID +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 references GoodsType(TypeID) +) + +--2、使用插入语句为两张表添加数据 +--商品类型表(GoodsType) +--商品类型编号 商品类型名称 +--1 服装内衣 +--2 鞋包配饰 +--3 手机数码 +select * from GoodsType +insert into GoodsType values ('服装内衣'),('鞋包配饰'),('手机数码') + +--商品信息表(GoodsInfo) +--商品编号 商品名称 商品颜色 商品品牌 商品价格 商品类型编号 +--1 提花小西装 红色 菲曼琪 300 1 +--2 百搭短裤 绿色 哥弟 100 1 +--3 无袖背心 白色 阿依莲 700 1 +--4 低帮休闲鞋 红色 菲曼琪 900 2 +--5 中跟单鞋 绿色 哥弟 400 2 +--6 平底鞋 白色 阿依莲 200 2 +--7 迷你照相机 红色 尼康 500 3 +--8 硬盘 黑色 希捷 600 3 +--9 显卡 黑色 技嘉 800 3 +select * from GoodsInfo +insert into GoodsInfo values +('提花小西装','红色','菲曼琪','300','1'), +('百搭短裤','绿色','哥弟','100','1'), +('无袖背心','白色','阿依莲','700','1'), +('低帮休闲鞋','红色','菲曼琪','900','2'), +('中跟单鞋','绿色','哥弟','400','2'), +('平底鞋','白色','阿依莲','200','2'), +('迷你照相机','红色','尼康','500','3'), +('硬盘','黑色','希捷','600','3'), +('显卡','黑色','技嘉','800','3') + + +--3、查询 价格最贵的 商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney desc + +--4、按 商品类型编号 分组查询商品 最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型编号 ,MAX(GoodsMoney)最高价格,MIN(GoodsMoney)最低价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney>=300 and GoodsMoney<=600 \ No newline at end of file -- Gitee From 698af0f7c5e1aec1c39df01bccbeb0ae9af9c5ba Mon Sep 17 00:00:00 2001 From: putar Date: Thu, 1 Apr 2021 22:14:27 +0800 Subject: [PATCH 154/195] 2021-4-1 21:56 --- .../\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" index 7808825..820a27a 100644 --- "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\350\257\227\346\235\260/SQLQuery1.sql" @@ -36,7 +36,7 @@ insert into GoodsInfo values(' --查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) --按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 -select TypeID 商品类型,MAX(GoodsMoney)最高价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID +select TypeID 商品类型,MAX(GoodsMoney)最高价格,MIN(GoodsMoney)最低价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID --查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 ,包含300和600么?咱不知道,咱也懒的问 select * from GoodsInfo where (GoodsColor = '红色') and (GoodsMoney between 300 and 600) select * from GoodsInfo where (GoodsColor = '红色') and (GoodsMoney >= 300 and GoodsMoney <= 600) -- Gitee From 2a6ceedc462f1e92d236a98cd0271709c9e8be2f Mon Sep 17 00:00:00 2001 From: meng-lingkun <1725116698@qq.com> Date: Thu, 1 Apr 2021 22:25:41 +0800 Subject: [PATCH 155/195] aaaa --- ...\345\244\215\344\271\240\351\242\2301.sql" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\345\244\215\344\271\240\351\242\2301.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\345\244\215\344\271\240\351\242\2301.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\345\244\215\344\271\240\351\242\2301.sql" new file mode 100644 index 0000000..054115d --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\255\237\344\273\244\345\235\244/\345\244\215\344\271\240\351\242\2301.sql" @@ -0,0 +1,45 @@ +use master +go +create database GoodsDB +go + +use GoodsDB + +go + +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null +) +go + +use GoodsDB + +go + +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, + TypeID int references GoodsType(TypeID) +) + +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + +insert into GoodsInfo values('提花小西装','红色','菲曼琪','300',1),('百搭短裤','绿色','哥弟','100',1),('无袖背心','白色','阿依莲','700',1), +('低帮休闲鞋','红色','菲曼琪','900',2),('中跟单鞋','绿色','哥弟','400',2),('平底鞋','白色','阿依莲','200',2),('迷你照相机','红色','尼康','500',3), +('硬盘','黑色','希捷','600',3),('显卡','黑色','技嘉','800',3) + + +select * from GoodsType +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID,MAX(GoodsMoney) 最高价格,MIN(GoodsMoney) 最低价格,AVG(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor = '红色'and GoodsMoney >= 300 and GoodsMoney <=600 \ No newline at end of file -- Gitee From 9472310ac0de8ae9b0106cd9d3bb72bec2b4836a Mon Sep 17 00:00:00 2001 From: yu-sijie <1609873552@qq.com> Date: Thu, 1 Apr 2021 22:37:32 +0800 Subject: [PATCH 156/195] =?UTF-8?q?SQL=E4=BD=9C=E4=B8=9A12-=E5=A4=8D?= =?UTF-8?q?=E4=B9=A0=E9=A2=98--4/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...-\345\244\215\344\271\240\351\242\230.sql" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--\345\244\215\344\271\240\351\242\230.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--\345\244\215\344\271\240\351\242\230.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--\345\244\215\344\271\240\351\242\230.sql" new file mode 100644 index 0000000..75145f4 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\231\346\200\235\346\235\260/SQLQuery--\345\244\215\344\271\240\351\242\230.sql" @@ -0,0 +1,59 @@ +use master +go +create database GoodsDB +on +( + name='GoodsDB', + filename='D:\SQL作业\SQL作业12--复习题\GoodsDB.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='GoodsDB_log', + filename='D:\SQL作业\SQL作业12--复习题\GoodsDB_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null +) +go + +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + + +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 constraint FK_GoodsInfo_TypeID references GoodsType(TypeID) +) +go + +insert into GoodsInfo values('提花小西装','红色','菲曼琪','300','1'),('百搭短裤','绿色','哥弟','100','1'), +('无袖背心','白色','阿依莲','700','1'),('低帮休闲鞋','红色','菲曼琪','900','2'),('中跟单鞋','绿色','哥弟','400','2'), +('平底鞋','白色','阿依莲','200','2'),('迷你照相机','红色','尼康','500','3'),('硬盘','黑色','希捷','600','3'),('显卡','黑色','技嘉','800','3') + +select * from GoodsType +select * from GoodsInfo + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型,max(GoodsMoney)最高价格,min(GoodsMoney)最低价格,avg(GoodsMoney)平均价格 from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 + -- Gitee From 7bc71c7efdb1991be21a07db5a2d4e43ad660cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E6=A2=A6=E6=9E=97?= <2777141796@qq.com> Date: Thu, 1 Apr 2021 23:39:11 +0800 Subject: [PATCH 157/195] =?UTF-8?q?=E8=8A=B1=E5=A7=91=E5=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery2.sql" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery2.sql" new file mode 100644 index 0000000..c229e08 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\250\346\242\246\346\236\227/SQLQuery2.sql" @@ -0,0 +1,85 @@ +create database GOOdSDB + + + +on + +( + + name='GOOdSDB', + + filename='E:\GOOdSDB.mdf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +log on + +( + + name='GOOdSDB_log', + + filename='E:\GOOdSDB_log.ldf', + + size=5mb, + + maxsize=50mb, + + filegrowth=10% + +) + +go + +use GOOdSDB + +create table GoodsType --商品类型表 +( +Typeid int primary key not null, +TypeName nvarchar(20) not null, +) +drop table GoodsInfo +create table GoodsInfo --商品信息表 +( +Goodsid int primary key not null, +GoodsName nvarchar(20) not null, +GoodsColor nvarchar(20) not null, +GoodsBrand nvarchar(20), +GoodsMoney money not null, +Typeid int foreign key references GoodsType(Typeid) +) +insert into GoodsType +select 1,'服装内衣' union +select 2,'鞋包配饰' union +select 3,'手机数码' + +select * from GoodsType + +insert into GoodsInfo +select 1, '提花小西装', '红色', '菲曼琪', 300 ,1union +select 2, '百搭短裤', '绿色', '哥弟', 100, 1 union +select 3,'无袖背心', '白色', '阿依莲',700, 1 union +select 4,'低帮休闲鞋', '红色', '菲曼琪', 900, 2 union +select 5,'中跟单鞋 ', '绿色', '哥弟', 400, 2 union +select 6, '平底鞋 ', '白色', '阿依莲', 200, 2 union +select 7, '迷你照相机', '红色', '尼康', 500, 3 union +select 8,'硬盘', '黑色', '希捷', 600, 3 union +select 9,'显卡', '黑色', '技嘉' ,800, 3 + +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 颜色, max(GoodsMoney) 价格 from GoodsInfo group by GoodsName,GoodsColor,GoodsMoney order by GoodsMoney desc + + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select Typeid 商品类型编号, max(GoodsMoney)最高价格,min(GoodsMoney)最低价格, avg (GoodsMoney)平均价格 from GoodsInfo group by Typeid + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +select*from GoodsInfo where GoodsMoney between 300 and 600 and GoodsColor='红色' + -- Gitee From 6d8794923bc85cf1129b00a505cf91a198a8f021 Mon Sep 17 00:00:00 2001 From: adios <1347358158@qq.com> Date: Fri, 2 Apr 2021 09:35:53 +0800 Subject: [PATCH 158/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E6=A2=81=E4=B8=96?= =?UTF-8?q?=E8=B4=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\346\242\201\344\270\226\350\264\244/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/.keep" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/.keep" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 890c8a073694497f0473f9bbf77ac9a0c05e0a7e Mon Sep 17 00:00:00 2001 From: adios <1347358158@qq.com> Date: Fri, 2 Apr 2021 09:36:23 +0800 Subject: [PATCH 159/195] =?UTF-8?q?=E6=A2=81=E4=B8=96=E8=B4=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5.sql" | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery5.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery5.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery5.sql" new file mode 100644 index 0000000..9598dfc --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\242\201\344\270\226\350\264\244/SQLQuery5.sql" @@ -0,0 +1,101 @@ +use master +go + +create database GoodsDB +on primary +( +name='GoodsDB', +filename='D:\.mdf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) + +log on +( +name='GoodsDB_log', +filename='D:\_log.ldf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +go + +use GoodsDB + +----字段名 说明 类型 长度 可否为空 约束 +----TypeID 商品类型编号 int 否 主键约束,自增约束,标识种子和标识增量都是1 +----TypeName 商品类型名称 nvarchar 20 否 + +create table GoodsType --建立商品类型表 +( +TypeID int primary key identity not null, +TypeName nvarchar(20) not null +) +go + +--字段名 说明 类型 长度 可否为空 约束 +--GoodsID 商品编号 int 否 主键约束,自增约束,标识种子和标识增量都是1 +--GoodsName 商品名称 nvarchar 20 否 +--GoodsColor 商品颜色 nvarchar 20 否 +--GoodsBrand 商品品牌 nvarchar 20 +--GoodsMoney 商品价格 money 否 +--TypeID 商品类型编号 int 外键,参照GoodsType中的TypeID + +create table GoodsInfo --建立商品信息表 +( +GoodsID int primary key identity 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) +) +go + +select * from GoodsType + +insert into GoodsType(TypeName) values +('服饰内衣'), +('鞋包配饰'), +('手机数码') + +--商品信息表(GoodsType) +--商品编号 商品名称 商品颜色 商品品牌 商品价格 商品类型编号 +--1 提花小西装 红色 菲曼琪 300 1 +--2 百搭短裤 绿色 哥弟 100 1 +--3 无袖背心 白色 阿依莲 700 1 +--4 低帮休闲鞋 红色 菲曼琪 900 2 +--5 中跟单鞋 绿色 哥弟 400 2 +--6 平底鞋 白色 阿依莲 200 2 +--7 迷你照相机 红色 尼康 500 3 +--8 硬盘 黑色 希捷 600 3 +--9 显卡 黑色 技嘉 800 3 + +select * from GoodsInfo + +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 GoodsType +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + +select top 1 s1.GoodsName 商品名称,s1.GoodsColor 商品颜色,s1.GoodsMoney 商品价格 from GoodsInfo s1 order by s1.GoodsMoney desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 + +select s2.TypeID,count(s2.TypeID)数量,max(s2.GoodsMoney) 最高价格,min(s2.GoodsMoney) 最低价格,avg(s2.GoodsMoney) 平均价格 from GoodsInfo s2 group by s2.TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +select * from(select top 6 s1.GoodsName,s1.GoodsColor,s1.GoodsMoney from GoodsInfo s1 order by s1.GoodsMoney) s2 where s2.GoodsColor='红色' + -- Gitee From 71dc449221469d2bcbb13f7c62953b2726fbb957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E6=B5=B7=E5=BD=AA?= <3305448617@qq.com> Date: Fri, 2 Apr 2021 09:56:58 +0800 Subject: [PATCH 160/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery1.sql" new file mode 100644 index 0000000..22c6247 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\234\346\265\267\345\275\252/SQLQuery1.sql" @@ -0,0 +1,61 @@ +create database GoodsDB +on +( +name='GoodsDB', +filename='D:\GoodsDB.mdf', +size=500mb, +filegrowth=15%, +maxsize=15mb +) +log on +( +name='GoodsDB_log', +filename='D:\GoodsDB_log.ldf', +size=500mb, +filegrowth=15%, +maxsize=15mb +) +go +use GoodsDB +go + +create table GoodsType +( +TypeID int primary key not null, +TypeName nvarchar(20) not null +) + +create table GoodsInfo +( +GoodsID int not null primary key , +GoodsName nvarchar(20) not null, +GoodsColor nvarchar(20) not null, +GoodsBrand nvarchar(20), +GoodsMoney money not null, +TypeID int foreign key references GoodsType(TypeID) +) + +select * from GoodsType +select * from GoodsInfo +insert into GoodsType values (1,'服装内衣'),(2,'鞋包配饰'),(3,'手机数码') +drop table GoodsInfo +insert into GoodsInfo values +(1,'提花小西装','红色','菲曼琪 ','300 ',1), +(2,'百搭短裤','绿色','哥弟','100',1), +(3,'无袖背心','白色','阿依莲','700',1), +(4,'低帮休闲鞋','红色','菲曼琪','900',2), +(5,'中跟单鞋','绿色','哥弟','400',2), +(6,'平底鞋','白色','阿依莲','200',2), +(7,'迷你照相机','红色','尼康','500',3), +(8,'硬盘','黑色','希捷','500',3), +(9,'显卡','黑色','技嘉','800',3) + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 max(GoodsMoney)价格最贵,GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo +group by GoodsMoney,GoodsName,GoodsColor order by GoodsMoney desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID,max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo +group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select GoodsColor,GoodsMoney from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 \ No newline at end of file -- Gitee From db76eb1a742c0fbbc2c9bae023311ac5237999c1 Mon Sep 17 00:00:00 2001 From: EoL <1179233990@qq.com> Date: Fri, 2 Apr 2021 10:05:39 +0800 Subject: [PATCH 161/195] 1 --- .../SQLQuery1.sql" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" new file mode 100644 index 0000000..481daaf --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" @@ -0,0 +1,51 @@ +use master +go + +create database GoodsDB +on +( name='GoodsDB', + filename='D:\SQL\GoodsDB.mdf', + size=5mb, + maxsize=50mb, + filegrowth=5mb +) +log on +( name='GoodsDB_log', + filename='D:\SQL\GoodsDB_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=5mb +) + +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 constraint FK_GoodsInfo_TypeID references GoodsType(TypeID) +) +insert into GoodsType values ('服装内衣'),('鞋包数码'),('手机数码') + +insert into GoodsInfo values('提花小西装','红色','菲曼琪',300,1), +('百搭短裤','绿色','哥弟',100,1),('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2),('中跟单鞋','绿色','哥弟 ',400,2), +('平底鞋','白色','阿依莲',200,2),('迷你照相机','红色 ','尼康',500 ,3), +('硬盘','黑色','希捷',600,3),('显卡 ','黑色','技嘉',800,3) + +--查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) +--按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型,MAX(GoodsMoney)最高价格,MIN(GoodsMoney)最低价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID +--查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +select * from GoodsInfo where GoodsColor = '红色' and GoodsMoney >= 300 and GoodsMoney <= 600 -- Gitee From 7e48571c7bcddf5a4193a0e0797b37bb954725e0 Mon Sep 17 00:00:00 2001 From: EoL <1179233990@qq.com> Date: Fri, 2 Apr 2021 10:06:48 +0800 Subject: [PATCH 162/195] 1 --- .../SQLQuery1.sql" | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" index 481daaf..0c60954 100644 --- "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\224\241\351\233\252\345\274\272/SQLQuery1.sql" @@ -16,10 +16,8 @@ log on maxsize=50mb, filegrowth=5mb ) - use GoodsDB go - create table GoodsType ( TypeID int primary key identity(1,1) not null, @@ -34,18 +32,15 @@ create table GoodsInfo GoodsMoney money not null, TypeID int constraint FK_GoodsInfo_TypeID references GoodsType(TypeID) ) -insert into GoodsType values ('服装内衣'),('鞋包数码'),('手机数码') - -insert into GoodsInfo values('提花小西装','红色','菲曼琪',300,1), -('百搭短裤','绿色','哥弟',100,1),('无袖背心','白色','阿依莲',700,1), -('低帮休闲鞋','红色','菲曼琪',900,2),('中跟单鞋','绿色','哥弟 ',400,2), -('平底鞋','白色','阿依莲',200,2),('迷你照相机','红色 ','尼康',500 ,3), -('硬盘','黑色','希捷',600,3),('显卡 ','黑色','技嘉',800,3) - ---查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 -select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) ---按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 -select TypeID 商品类型,MAX(GoodsMoney)最高价格,MIN(GoodsMoney)最低价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID ---查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 - -select * from GoodsInfo where GoodsColor = '红色' and GoodsMoney >= 300 and GoodsMoney <= 600 +insert into GoodsType values ('鏈嶈鍐呰。'),('闉嬪寘鏁扮爜'),('鎵嬫満鏁扮爜') +insert into GoodsInfo values('鎻愯姳灏忚タ瑁','绾㈣壊','鑿叉浖鐞',300,1), +('鐧炬惌鐭¥','缁胯壊','鍝ュ紵',100,1),('鏃犺鑳屽績','鐧借壊','闃夸緷鑾',700,1), +('浣庡府浼戦棽闉','绾㈣壊','鑿叉浖鐞',900,2),('涓窡鍗曢瀷','缁胯壊','鍝ュ紵 ',400,2), +('骞冲簳闉','鐧借壊','闃夸緷鑾',200,2),('杩蜂綘鐓х浉鏈','绾㈣壊 ','灏煎悍',500 ,3), +('纭洏','榛戣壊','甯屾嵎',600,3),('鏄惧崱 ','榛戣壊','鎶鍢',800,3) +--鏌ヨ浠锋牸鏈璐电殑鍟嗗搧鍚嶇О锛屽晢鍝侀鑹插拰鍟嗗搧浠锋牸锛岃姹備娇鐢ㄥ埆鍚嶆樉绀哄垪鍚 +select GoodsName 鍟嗗搧鍚嶇О,GoodsColor 鍟嗗搧棰滆壊,GoodsMoney 鍟嗗搧浠锋牸 from GoodsInfo where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) +--鎸夊晢鍝佺被鍨嬬紪鍙峰垎缁勬煡璇㈠晢鍝佹渶楂樹环鏍硷紝鏈浣庝环鏍煎拰骞冲潎浠锋牸锛岃姹備娇鐢ㄥ埆鍚嶆樉绀哄垪鍚 +select TypeID 鍟嗗搧绫诲瀷,MAX(GoodsMoney)鏈楂樹环鏍,MIN(GoodsMoney)鏈浣庝环鏍,AVG(GoodsMoney)骞冲潎浠锋牸 from GoodsInfo group by TypeID +--鏌ヨ鍟嗗搧淇℃伅鎵鏈夊垪锛岃姹傚晢鍝侀鑹蹭负绾㈣壊锛屼环鏍煎湪300~600涔嬮棿 +select * from GoodsInfo where GoodsColor = '绾㈣壊' and GoodsMoney >= 300 and GoodsMoney <= 600 -- Gitee From 59821cb3711968ccef41be7f60a90d7d955541a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= <3148578490@qq.com> Date: Fri, 2 Apr 2021 10:08:37 +0800 Subject: [PATCH 163/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=BB=84=E6=96=87?= =?UTF-8?q?=E8=81=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\273\204\346\226\207\350\201\252/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From c60fabc2785b2717ffe764fbd2ffe2945aeb82c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= <3148578490@qq.com> Date: Fri, 2 Apr 2021 10:09:08 +0800 Subject: [PATCH 164/195] =?UTF-8?q?=E9=BB=84=E6=96=87=E8=81=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery1.sql" new file mode 100644 index 0000000..df2269d --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\226\207\350\201\252/SQLQuery1.sql" @@ -0,0 +1,95 @@ +use master +go +--1、创建商品数据库(GoodsDB) +create database GoodsDB +on +( + name='GoodsDB', + filename='E:\数据库文件\数据库跟目录文件\商品库(复习多表查询)\GoodsDB.mdf', + size=5, + maxsize=50, + filegrowth=10% +) +log on +( + name='GoodsDB_log', + filename='E:\数据库文件\数据库跟目录文件\商品库(复习多表查询)\GoodsDB_log.ldf', + size=5, + maxsize=50, + filegrowth=10% +) +go +use GoodsDB + +--然后建立表GoodsType(商品类型表)表结构分别如下: +--商品类型表(GoodsType) +--字段名 说明 类型 长度 可否为空 约束 +--TypeID 商品类型编号 int 否 主键约束,自增约束,标识种子和标识增量都是1 +--TypeName 商品类型名称 nvarchar 20 否 +create table GoodsType +( + TypeID int not null primary key identity(1,1) , + TypeName nvarchar(20) not null +) +--GoodsInfo(商品信息表),表结构分别如下: +--商品信息表(GoodsInfo) +--字段名 说明 类型 长度 可否为空 约束 +--GoodsID 商品编号 int 否 主键约束,自增约束,标识种子和标识增量都是1 +--GoodsName 商品名称 nvarchar 20 否 +--GoodsColor 商品颜色 nvarchar 20 否 +--GoodsBrand 商品品牌 nvarchar 20 +--GoodsMoney 商品价格 money 否 +--TypeID 商品类型编号 int 外键,参照GoodsType中的TypeID +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) null, + GoodsMoney money not null, + TypeID int foreign key references GoodsType(TypeID) +) +--2、使用插入语句为两张表添加数据 +--商品类型表(GoodsType) +--商品类型编号 商品类型名称 + --1 服装内衣 + --2 鞋包配饰 + --3 手机数码] +insert into GoodsType values +('服装内衣'), +('鞋包配饰'), +('手机数码') + +--商品信息表(GoodsType) +--商品编号 商品名称 商品颜色 商品品牌 商品价格 商品类型编号 +--1 提花小西装 红色 菲曼琪 300 1 +--2 百搭短裤 绿色 哥弟 100 1 +--3 无袖背心 白色 阿依莲 700 1 +--4 低帮休闲鞋 红色 菲曼琪 900 2 +--5 中跟单鞋 绿色 哥弟 400 2 +--6 平底鞋 白色 阿依莲 200 2 +--7 迷你照相机 红色 尼康 500 3 +--8 硬盘 黑色 希捷 600 3 +--9 显卡 黑色 技嘉 800 3 +insert into GoodsInfo values +('提花小西装' ,'红色', '菲曼琪' ,300 ,1), +('百搭短裤' ,'绿色', '哥弟' ,100 ,1), +('无袖背心' ,'白色' ,'阿依莲' ,700 ,1), +('低帮休闲鞋' ,'红色', '菲曼琪' ,900 ,2), +('中跟单鞋' ,'绿色' ,'哥弟' ,400 ,2), +('平底鞋' ,'白色', '阿依莲' ,200 ,2), +('迷你照相机' ,'红色', '尼康' ,500 ,3), +('硬盘' ,'黑色', '希捷' ,600 ,3), +('显卡' ,'黑色' ,'技嘉' ,800 ,3) +select*from GoodsType +select*from GoodsInfo + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney=(select max(GoodsMoney)from GoodsInfo) + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select GoodsType.TypeID 商品类型编号,max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsType inner join GoodsInfo on +GoodsType.TypeID=GoodsInfo.TypeID group by GoodsType.TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select*from GoodsInfo where GoodsColor='红色' and GoodsMoney>300and GoodsMoney<600 -- Gitee From 2b9d9f41ab4b0b9568be5b3b2525bc300a4aed2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Fri, 2 Apr 2021 10:09:30 +0800 Subject: [PATCH 165/195] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=99=88=E6=B5=A9?= =?UTF-8?q?=E5=AE=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\351\231\210\346\265\251\345\256\207/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 9080b3b07fbd9e595ef3ebfbd6d6fe3cd647fd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B5=A9=E5=AE=87?= <1130029615@qq.com> Date: Fri, 2 Apr 2021 10:09:54 +0800 Subject: [PATCH 166/195] 1 --- .../SQLQuery12.sql" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery12.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery12.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery12.sql" new file mode 100644 index 0000000..cac6083 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\265\251\345\256\207/SQLQuery12.sql" @@ -0,0 +1,36 @@ +create database GoodsDB +go + +use GoodsDB +go + +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null +) +go + +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 constraint FK_GoodsInfo_TypeID references GoodsType(TypeID) +) +go +insert into GoodsType values ('服装内衣'),('鞋包数码'),('手机数码') +insert into GoodsInfo values('提花小西装','红色','菲曼琪',300,1), +('百搭短裤','绿色','哥弟',100,1),('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2),('中跟单鞋','绿色','哥弟 ',400,2), +('平底鞋','白色','阿依莲',200,2),('迷你照相机','红色 ','尼康',500 ,3), +('硬盘','黑色','希捷',600,3),('显卡 ','黑色','技嘉',800,3) +--查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) +--按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型,MAX(GoodsMoney)最高价格,MIN(GoodsMoney)最低价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID +--查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where (GoodsColor = '红色') and (GoodsMoney between 300 and 600) +select * from GoodsInfo where (GoodsColor = '红色') and (GoodsMoney >= 300 and GoodsMoney <= 600) -- Gitee From b7c5d90dd44bc780314c85a63a210a80190072f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=BC=E7=9D=80=E5=A5=B6=E7=93=B6=E5=8E=BB=E6=89=93?= =?UTF-8?q?=E8=99=8E?= <1348328020@qq.com> Date: Fri, 2 Apr 2021 10:12:13 +0800 Subject: [PATCH 167/195] 2021-4-2 --- .../2021-4-2.sql" | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/2021-4-2.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/2021-4-2.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/2021-4-2.sql" new file mode 100644 index 0000000..573b3b9 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\255\217\346\265\267\350\215\243/2021-4-2.sql" @@ -0,0 +1,108 @@ +--有如图所示的三张表结构,学生信息表(stuInfo),课程信息表(courseInfo),分数信息表(scoreInfo) +create database Student +go +use Student +go + +create table stuInfo +( + stuID int identity(1,1) primary key, + stuName varchar(20) not null, + stuAge int, + stuSex varchar(1) default(1) check(stuSex in('1','0')), + time date +) +insert into stuInfo(stuName,stuAge,stuSex) values +('Tom',19,'1'), +('Jack',20,'0'), +('Rose',21,'1'), +('Lulu',19,'1'), +('Lili',21,'0') +insert into stuInfo values ('abc',20,1,'2001-01-07 01:11:36.590') + + +create table courseInfo +( + courseID int identity(1,1) primary key, + courseName varchar(20) not null, + courseMarks int +) +insert into courseInfo values ('JavaBase',4),('HTML',2),('JavaScript',2),('SqlBase',2) + +create table scoreInfo +( + scoreID int identity(1,1) primary key, + stuID int references stuInfo(stuID), + courseID int references courseInfo(courseID), + score int +) +insert into scoreInfo 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) + +select * from stuInfo +select * from courseInfo +select * from scoreInfo +--题目: +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 + +select StuID 学生编号,count(courseID) 所选修课程数量,avg(score) 平均分 +from scoreInfo group by StuID + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 + +select courseID 课程编号,count(StuID) 课程所选修学生个数,sum(score) 总分 +from scoreInfo group by courseID + +--3.查询出性别一样并且年龄一样的学生的信息 + +select A.stuID,A.stuName,A.stuAge,A.stuSex,A.time from StuInfo A,StuInfo B +where A.stuSex=B.stuSex and A.stuAge=B.stuAge and A.stuID != b.stuID + +--4.查询出学分一样的课程信息 + +select difference(A.courseID,A.courseName,A.courseMarks from courseInfo A,courseInfo B +where A.courseMarks=B.courseMarks and A.courseID != b.courseID + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 + +select A.stuID 学号,A.stuName 姓名,B.courseID 课程编号,B.score 分数 +from stuInfo A inner join scoreInfo B on A.stuID=B.stuID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 + +select A.stuID 学号,B.courseID 课程编号,C.courseName 课程名,C.courseMarks 课程学分,B.score 分数 +from stuInfo A inner join scoreInfo B on A.stuID=B.stuID +inner join courseInfo C on C.courseID=B.courseID + +--7.查询出没有参加考试的学生的学号和姓名 + +select A.stuID 学号,A.stuName 姓名 +from stuInfo A left join scoreInfo B on A.stuID=B.stuID +where score is null + +--8.查询出是周六周天来报到的学生 + + --学生愚昧,请老师解惑! + select * from stuInfo where time= + (select time ,datename(dw,time) from stuInfo + group by time having datename(dw,time)='星期六' or datename(dw,time)='星期日') + +--9.查询出姓名中有字母a的学生的信息 + +select * from stuInfo where stuName like '%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select A.StuID 学号,sum(score) 平均分,count(courseID) 选修数量 +from stuInfo A join scoreInfo B on A.stuID=B.stuID +group by A.StuID having count(courseID)>2 \ No newline at end of file -- Gitee From d8c5ca13d227892223dac4cc125621868ab44b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E9=82=B5=E6=98=A0?= <2934277968@qq.com> Date: Fri, 2 Apr 2021 10:13:21 +0800 Subject: [PATCH 168/195] 1 --- .../goodsDB.sql" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/goodsDB.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/goodsDB.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/goodsDB.sql" new file mode 100644 index 0000000..c558474 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\203\221\351\202\265\346\230\240/goodsDB.sql" @@ -0,0 +1,38 @@ +use master +go + +create database GoodsDB +go + +use GoodsDB +go +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) + +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) , + GoodsMoney money not null, + TypeID int foreign key references GoodsType(TypeID) +) +insert into GoodsType +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 +--查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select TOP 1 GoodsMoney 商品价格,GoodsName 商品名称,GoodsColor 商品颜色 from GoodsInfo + group by GoodsName,GoodsMoney,GoodsColor order by GoodsMoney DESC +--按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 类型编号,max(GoodsMoney) 商品最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 \ No newline at end of file -- Gitee From 2ed608e5711385d3abc2f06fffeacbcf86699697 Mon Sep 17 00:00:00 2001 From: PilRio <2535341085@qq.com> Date: Fri, 2 Apr 2021 10:15:46 +0800 Subject: [PATCH 169/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" new file mode 100644 index 0000000..381a66d --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\236\227\346\265\267\346\266\233/SQLQuery1.sql" @@ -0,0 +1,53 @@ +create database GoodsDB +on +( + name = 'GoodsDB', + filename = 'D:\数据库\GoodsDB.mdf' +) +log on +( + name = 'GoodsDB_log', + filename = 'D:\数据库\GoodsDB_log.ldf' +) +use GoodsDB + +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20), + GoodsMoney money not null , + TypeID int references GoodsType(TypeID) +) +insert into GoodsType values +('服装内衣'),('鞋包配饰'),('手机数码') +insert into GoodsInfo values +('提米小西装','红色','菲曼琪',300,1), +('百搭短裤','绿色','哥弟',100,1), +('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2), +('中跟单鞋','绿色','哥弟',400,2), +('平底鞋 ','白色','阿依莲',200,2), +('迷你照相机','红色','尼康',500,3), +('硬盘','黑色','希捷',600,3), +('显卡','黑色','希捷',800,3) +select * from GoodsType +select * from GoodsInfo + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 名称,GoodsColor 颜色 ,GoodsMoney 价格 from GoodsInfo +where GoodsMoney in (select max(GoodsMoney) from GoodsInfo) + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TYPEID 编号,MIN(GoodsMoney)最低价, Max(GoodsMoney)最高价,avg(GoodsMoney)平均价 from GoodsInfo +group by TYPEID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor = '红色' and GoodsMoney between 300 and 600 + -- Gitee From 45287cd4c393d33fd8d2de1547395866c5b4efab Mon Sep 17 00:00:00 2001 From: cowlong <1220590642@qq.com> Date: Fri, 2 Apr 2021 10:23:08 +0800 Subject: [PATCH 170/195] =?UTF-8?q?=E6=9F=AF=E6=96=87=E9=BE=99=E7=AC=AC?= =?UTF-8?q?=E5=8D=81=E4=BA=8C=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery1.sql" new file mode 100644 index 0000000..1a772e6 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\237\257\346\226\207\351\276\231/SQLQuery1.sql" @@ -0,0 +1,47 @@ +use master +go + +create database GoodsDB +on +( name='GoodsDB', + filename='D:\SQL\GoodsDB.mdf', + size=5mb, + maxsize=50mb, + filegrowth=5mb +) +log on +( name='GoodsDB_log', + filename='D:\SQL\GoodsDB_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=5mb +) +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 constraint FK_GoodsInfo_TypeID references GoodsType(TypeID) +) +insert into GoodsType values ('服装内衣'),('鞋包数码'),('手机数码') +insert into GoodsInfo values('提花小西装','红色','菲曼琪',300,1), +('百搭短裤','绿色','哥弟',100,1),('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2),('中跟单鞋','绿色','哥弟 ',400,2), +('平底鞋','白色','阿依莲',200,2),('迷你照相机','红色 ','尼康',500 ,3), +('硬盘','黑色','希捷',600,3),('显卡 ','黑色','技嘉',800,3) +--查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo +where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) +--按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型,MAX(GoodsMoney)最高价格,MIN(GoodsMoney)最低价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID +--查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor = '红色' and GoodsMoney >= 300 and GoodsMoney <= 600 \ No newline at end of file -- Gitee From 635a50866ff48126bc8e0d191ed720c28bc14b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E6=98=82?= <2636153719@qq.com> Date: Fri, 2 Apr 2021 10:26:18 +0800 Subject: [PATCH 171/195] 1 --- .../SQLQuery1.sql" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" new file mode 100644 index 0000000..72cf4dc --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\222\262\346\231\223\351\252\217/SQLQuery1.sql" @@ -0,0 +1,48 @@ +create database GoodsDB + +use GoodsDB +go + +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) + +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null , + GoodsColor nvarchar(20) not null , + GoodsBrand nvarchar(20) , + GoodsMoney money not null, + TypeID int foreign key references GoodsType(TypeID) +) + +insert into GoodsType values +('服装内衣'), +('鞋包配饰'), +('手机数码') + + +insert into GoodsInfo values +('提花小西装','红色','菲曼琪','300',1), +('百搭短裤','绿色','哥弟','100',1), +('无袖背心','白色','阿依莲','700',1), +('低帮休闲鞋','红色','菲曼琪','900',2), +('中跟单鞋','绿色','哥弟','400',2), +('平底鞋','白色','阿依莲','200',2), +('迷你照相机','红色','尼康','500',3), +('硬盘','黑色','希捷','600',3), +('显卡','黑色','技嘉','800',3) + +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsMoney 商品价格,GoodsName 商品名称,GoodsColor 商品颜色 from GoodsInfo group by GoodsName,GoodsColor,GoodsMoney order by GoodsMoney desc +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 类型编号,max(GoodsMoney) 最高价格,min(GoodsMoney ) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor ='红色'and GoodsMoney>300 and GoodsMoney<600 + + + -- Gitee From 198b29a39bcfa278c855e19694859377a6046120 Mon Sep 17 00:00:00 2001 From: wang-jiawen-rjjs <2903977615@qq.com> Date: Fri, 2 Apr 2021 10:45:01 +0800 Subject: [PATCH 172/195] =?UTF-8?q?=E7=8E=8B=E4=BD=B3=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/SQLQuery1.sql" new file mode 100644 index 0000000..0ec655b --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\347\216\213\344\275\263\346\226\207/SQLQuery1.sql" @@ -0,0 +1,64 @@ +use master +go +create database GoodsDB +on( + name='GoodsDB', + filename='C:\TEXT\GoodsDB.mdf', + size=5, + maxsize=100, + filegrowth=10% +) +log on ( + name='GoodsDB_log', + filename='C:\TEXT\GoodsDB_log.ldf', + size=5, + maxsize=100, + filegrowth=10% +) +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 references GoodsType(TypeID), +) + select * from GoodsType + select * from GoodsInfo + insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + insert into GoodsInfo values('提花小西装','红色','菲曼琪',300.00,1),('百搭短裤','绿色','哥弟',100.00,1), + ('无袖背心','白色','阿依莲',700.00,1),('低帮休闲鞋','红色','菲曼琪',900.00,2), + ('中跟单鞋', '绿色', '哥弟', 400.00, 2),('平底鞋', '白色', '阿依莲', 200, 2), + ('迷你照相机','红色','尼康',500.00,3),('硬盘','黑色','希捷',600.00,3), + ('显卡','黑色','技嘉',800.00,3) + +--3、查询 价格最贵 的商品名称,商品颜色和商品价格,要求使用别名显示列名 + select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品金额 from GoodsInfo order by GoodsMoney DESC + select top 1 GoodsName as 商品名称,GoodsColor as 商品颜色,GoodsMoney as 商品金额 from GoodsInfo order by GoodsMoney DESC + select top 1 商品名称=GoodsName , 商品颜色=GoodsColor , 商品金额=GoodsMoney from GoodsInfo order by GoodsMoney DESC +--4、按商品 类型编号 分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 + select TypeID 类型编号,MAX(GoodsMoney) 最高价格,MIN(GoodsMoney) 最低价格,AVG(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + select * from GoodsInfo where GoodsColor='红色' and GoodsMoney>=300 and GoodsMoney<=600 + select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 + + + + + + + + + + + + -- Gitee From 7242a806ecaa692ba2c81e353344ce0558bb01ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=BF=E6=A3=AE?= <2287431003@qq.com> Date: Fri, 2 Apr 2021 10:49:21 +0800 Subject: [PATCH 173/195] sql --- .../\346\273\225\351\221\253/SQLQuery1.sql" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" new file mode 100644 index 0000000..a41c8a5 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\273\225\351\221\253/SQLQuery1.sql" @@ -0,0 +1,48 @@ +create database GoodsDB +on +( name='GoodsDB', + filename='D:\GoodsDB.mdf', + size=5mb, + maxsize=100mb, + filegrowth=5mb +) +log on +( name='GoodsDB_log', + filename='D:\GoodsDB_log.ldf', + size=5mb, + maxsize=100mb, + filegrowth=5mb +) +go +use GoodsDB +go + +create table GoodsType +( + TypeID int primary key identity, + TypeName nvarchar(20) not null + +) + +create table GoodsInfo +( + GoodsID int primary key identity, + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) not null, + GoodsMoney money not null, + TypeID int references GoodsType(TypeID) +) + +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + +insert into GoodsInfo values('提花小西装', '红色', '菲曼琪', '300', 1),('百搭短裤', '绿色', '哥弟', '100', 1), + ('无袖背心', '白色', '阿依莲', '700', 1),('低帮休闲鞋', '红色', '菲曼琪', '900', 2), + ('中跟单鞋', '绿色', '哥弟', '400', 2),('平底鞋', '白色', '阿依莲','200', 2), + ('迷你照相机', '红色', '尼康', '500', 3),('硬盘', '黑色', '希捷', '600', 3), + ('显卡', '黑色', '技嘉','800', 3) +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney desc +select max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney>=300 and GoodsMoney<=600 + + -- Gitee From e39f055dea0b1ec9914acbd9b067f447d1f07b9f Mon Sep 17 00:00:00 2001 From: heiiii <1390105108@qq.com> Date: Fri, 2 Apr 2021 11:04:33 +0800 Subject: [PATCH 174/195] 55 --- .../\351\231\210\346\227\255/SQLQuery2.sql" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" new file mode 100644 index 0000000..a348567 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\231\210\346\227\255/SQLQuery2.sql" @@ -0,0 +1,43 @@ +create database xxx +go +use xxx +go + +create table GoodsType +( + TypeID int primary key identity, + TypeName nvarchar(20) not null + +) + +create table GoodsInfo +( + GoodsID int primary key identity, + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) not null, + GoodsMoney money not null, + TypeID int references GoodsType(TypeID) +) + +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + +insert into GoodsInfo values('提花小西装', '红色', '菲曼琪', '300', 1), +('百搭短裤', '绿色', '哥弟', '100', 1), +('无袖背心', '白色', '阿依莲', '700', 1), +('低帮休闲鞋', '红色', '菲曼琪', '900', 2), +('中跟单鞋', '绿色', '哥弟', '400', 2), +('平底鞋', '白色', '阿依莲','200', 2), +('迷你照相机', '红色', '尼康', '500', 3), +('硬盘', '黑色', '希捷', '600', 3), +('显卡', '黑色', '技嘉','800', 3) + + +select * from GoodsType +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo ORDER BY GoodsMoney DESC +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney<=600 and GoodsMoney>=300 -- Gitee From 2024f622937bddb9f70e3dd5f25ba985404af83f Mon Sep 17 00:00:00 2001 From: huangziyi <3120130015@qq.com> Date: Fri, 2 Apr 2021 11:11:02 +0800 Subject: [PATCH 175/195] first commit --- .../\345\244\215\344\271\240\351\242\230.sql" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\345\244\215\344\271\240\351\242\230.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\345\244\215\344\271\240\351\242\230.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\345\244\215\344\271\240\351\242\230.sql" new file mode 100644 index 0000000..417577f --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\345\255\220\346\200\241/\345\244\215\344\271\240\351\242\230.sql" @@ -0,0 +1,73 @@ +use master +go + +create database GoodsDB +on +( + name='GoodsDB', + filename='C:\test\GoodsDB.mdf', + size=20, + maxsize=200, + filegrowth=10% + ) + log on +( + name='GoodsDB_log', + filename='C:\test\GoodsDB_log.ldf', + size=20, + maxsize=200, + filegrowth=10% + ) + + go + use GoodsDB + go + +create table GoodsType + +( + TypeID int primary key identity (1,1) not null, + TypeName nvarchar (20) not null, + ) + + insert into GoodsType(TypeName) values ('服装内衣'),('鞋包配饰'),('手机数码') + + select * from GoodsType + + create table GoodsInfo +( + GoodsID int primary key identity (1,1), + GoodsName nvarchar (20) not null, + GoodsColor nvarchar (20) not null, + GoodsBrand nvarchar (20) not null, + GoodsMoney money not null, + TyoeID int references GoodsType(TypeID) + ) + + insert into GoodsInfo(GoodsName,GoodsColor,GoodsBrand,GoodsMoney,TyoeID) + values ('提花小西装','红色','菲曼琪','300','1') , + ('百搭短裤','绿色','哥弟','300','1'), + ('无袖背心','白色','阿依莲','700','1'), + ('低帮休闲鞋','红色','菲曼琪','900','2'), + ('中跟单鞋','绿色','哥弟','400','2'), + ('平底','白色','阿依莲','700','1'), + ('迷你照相机','红色','尼康','500','3') + + select * from GoodsInfo + + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + + select top 1 GoodsName as 商品名称,GoodsColor as 商品颜色,GoodsMoney as 商品价格 from GoodsInfo + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 + + select GoodsName as 商品名称 ,max(GoodsMoney) as 最高价格,min(GoodsMoney)as 最低价格,avg(GoodsMoney)as 平均价格 from GoodsInfo + group by GoodsMoney,GoodsName + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + select GoodsName as 商品名称,GoodsColor as 商品颜色,GoodsMoney as 商品价格 from GoodsInfo + where GoodsColor='红色' and GoodsMoney >=300 and GoodsMoney <=600 + + select GoodsName as 商品名称,GoodsColor as 商品颜色,GoodsMoney as 商品价格 from GoodsInfo + where GoodsColor='红色' and GoodsMoney between 300 and 600 \ No newline at end of file -- Gitee From 2bd0d9c02e739e6b80b0cbc713e595ef1019aabc Mon Sep 17 00:00:00 2001 From: yiQ <1325307033@qq.com> Date: Fri, 2 Apr 2021 11:40:53 +0800 Subject: [PATCH 176/195] 12 --- .../SQLQuery1.sql" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" new file mode 100644 index 0000000..0386f3e --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\203\255\350\211\272\346\263\211/SQLQuery1.sql" @@ -0,0 +1,59 @@ +use master +go +create database GoodsDB +on +( + name='GoodsDB', + filename='D:\SQL作业\SQL作业12--复习题\GoodsDB.mdf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) + +log on +( + name='GoodsDB_log', + filename='D:\SQL作业\SQL作业12--复习题\GoodsDB_log.ldf', + size=5mb, + maxsize=50mb, + filegrowth=10% +) +go + +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null +) +go + +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + + +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 constraint FK_GoodsInfo_TypeID references GoodsType(TypeID) +) +go + +insert into GoodsInfo values('提花小西装','红色','菲曼琪','300','1'),('百搭短裤','绿色','哥弟','100','1'), +('无袖背心','白色','阿依莲','700','1'),('低帮休闲鞋','红色','菲曼琪','900','2'),('中跟单鞋','绿色','哥弟','400','2'), +('平底鞋','白色','阿依莲','200','2'),('迷你照相机','红色','尼康','500','3'),('硬盘','黑色','希捷','600','3'),('显卡','黑色','技嘉','800','3') + +select * from GoodsType +select * from GoodsInfo + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型,max(GoodsMoney)最高价格,min(GoodsMoney)最低价格,avg(GoodsMoney)平均价格 from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 + -- Gitee From 3fb2aaf4036dd7d684a17edce4fd14e3ea8b3601 Mon Sep 17 00:00:00 2001 From: weilijiang <3055679233@qq.com> Date: Fri, 2 Apr 2021 11:50:48 +0800 Subject: [PATCH 177/195] sql --- .../SQLQuery1.sql" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQLQuery1.sql" new file mode 100644 index 0000000..73b08c1 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\237\246\344\270\275\346\261\237/SQLQuery1.sql" @@ -0,0 +1,58 @@ +use master +go +create database GoodsDB +on( + name='GoodsType', + filename='D:\sql\GoodsType.mdf', + size=8mb, + maxsize=80mb, + filegrowth=10% + +) +log on( + + name='GoodsType_log', + filename='D:\sql\GoodsType_log.ldf', + size=8mb, + maxsize=80mb, + filegrowth=10% + +) +go +use GoodsDB +go +create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null, +) +select * from GoodsType +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') +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 references GoodsType(TypeID), +) +select * from GoodsInfo +insert into GoodsInfo +values('提花小西装','红色','菲曼琪',300.00,1), + ('百搭短裤','绿色','哥弟',100.00,1), + ('无袖背心','白色','阿依莲',700.00,1), + ('低帮休闲鞋','红色','菲曼琪',900.00,2), + ('中跟单鞋', '绿色', '哥弟', 400.00, 2), + ('平底鞋', '白色', '阿依莲', 200, 2), + ('迷你照相机','红色','尼康',500.00,3), + ('硬盘','黑色','希捷',600.00,3), + ('显卡','黑色','技嘉',800.00,3) +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select * from GoodsType +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney DESC +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select * from GoodsInfo +select TypeID 类型编号,max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色'and GoodsMoney>=300 and GoodsMoney<=600 -- Gitee From 14f382b085a6a184e35c574c997aa1f8f23bec2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=96=E7=BA=B7?= <8332024+o2444091281@user.noreply.gitee.com> Date: Fri, 2 Apr 2021 11:50:52 +0800 Subject: [PATCH 178/195] =?UTF-8?q?=E9=BB=84=E9=94=9F=E5=AE=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQL1.sql" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL1.sql" new file mode 100644 index 0000000..794ea0a --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\351\224\237\345\256\207/SQL1.sql" @@ -0,0 +1,53 @@ +create database GoodsDB + +use GoodsDB +go + +create table GoodsType +( +TypeID int not null primary key identity(1,1), +TypeName nvarchar(20) not null +) + +create table GoodsInfo +( +GoodsID int not null primary key identity(1,1), +GoodsName nvarchar(20) not null , +GoodsColor nvarchar(20) not null , +GoodsBrand nvarchar(20) , +GoodsMoney money not null, +TypeID int foreign key references GoodsType(TypeID) +) + +insert into GoodsType values +('鏈嶈鍐呰。'), +('闉嬪寘閰嶉グ'), +('鎵嬫満鏁扮爜') + + +insert into GoodsInfo values +('鎻愯姳灏忚タ瑁','绾㈣壊','鑿叉浖鐞','300',1), +('鐧炬惌鐭¥','缁胯壊','鍝ュ紵','100',1), +('鏃犺鑳屽績','鐧借壊','闃夸緷鑾','700',1), +('浣庡府浼戦棽闉','绾㈣壊','鑿叉浖鐞','900',2), +('涓窡鍗曢瀷','缁胯壊','鍝ュ紵','400',2), +('骞冲簳闉','鐧借壊','闃夸緷鑾','200',2), +('杩蜂綘鐓х浉鏈','绾㈣壊','灏煎悍','500',3), +('纭洏','榛戣壊','甯屾嵎','600',3), +('鏄惧崱','榛戣壊','鎶鍢','800',3) + +select * from GoodsInfo +--3銆佹煡璇环鏍兼渶璐电殑鍟嗗搧鍚嶇О锛屽晢鍝侀鑹插拰鍟嗗搧浠锋牸锛岃姹備娇鐢ㄥ埆鍚嶆樉绀哄垪鍚 +select top 1 GoodsMoney 鍟嗗搧浠锋牸,GoodsName 鍟嗗搧鍚嶇О,GoodsColor 鍟嗗搧棰滆壊 +from GoodsInfo +group by GoodsName,GoodsColor,GoodsMoney +order by GoodsMoney desc + +--4銆佹寜鍟嗗搧绫诲瀷缂栧彿鍒嗙粍鏌ヨ鍟嗗搧鏈楂樹环鏍硷紝鏈浣庝环鏍煎拰骞冲潎浠锋牸锛岃姹備娇鐢ㄥ埆鍚嶆樉绀哄垪鍚 +select TypeID 绫诲瀷缂栧彿,max(GoodsMoney) 鏈楂樹环鏍,min(GoodsMoney ) 鏈浣庝环鏍,avg(GoodsMoney) 骞冲潎浠锋牸 +from GoodsInfo +group by TypeID +--5銆佹煡璇㈠晢鍝佷俊鎭墍鏈夊垪锛岃姹傚晢鍝侀鑹蹭负绾㈣壊锛屼环鏍煎湪300~600涔嬮棿 +select * +from GoodsInfo +where GoodsColor ='绾㈣壊'and GoodsMoney>300 and GoodsMoney<600 \ No newline at end of file -- Gitee From 7f497d3cfde6be8e51141cf1bff1d33c9621d472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=84=E4=B8=BA?= <2608359793@qq.com> Date: Fri, 2 Apr 2021 11:52:35 +0800 Subject: [PATCH 179/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery2.sql" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery2.sql" new file mode 100644 index 0000000..4466dd1 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\345\230\211\344\277\212/SQLQuery2.sql" @@ -0,0 +1,65 @@ +USE master +GO +CREATE DATABASE GoodsDB +on +( +name='wq', +filename='D:\wq.mdf', +size=1 +) +log on +( +name='wq_log', +filename='D:\wq_log.ldf', +size=1 +) +GO +use GoodsDB +GO +CREATE TABLE GoodsType +( +TypeID INT NOT NULL IDENTITY(1,1), +TypeName NVARCHAR(20) NOT NULL +) +GO +ALTER TABLE GoodsType add constraint DK_GoodsType_TYPEID PRIMARY KEY(TYPEID) +SELECT * FROM GoodsType +INSERT INTO GoodsType(TypeName) +values('服装内衣'), +('鞋包配饰'), +('手机数码') +CREATE TABLE GoodsInfo +( +GoodsID INT NOT NULL IDENTITY(1,1), +GoodsName NVARCHAR(20) NOT NULL, +GoodsColor NVARCHAR(20) NOT NULL , +GoodsBrand NVARCHAR(20) , +GoodsMoney MONEY NOT NULL, +TypeID INT +) +GO +ALTER TABLE GoodsInfo ADD CONSTRAINT GK_GoodsInfo_GoodsID primary key(GoodsID) +ALTER TABLE GoodsInfo ADD CONSTRAINT JK_GoodsInfo_TypeID FOREIGN KEY(TYPEID) references GoodsType(TypeID) +SELECT * FROM GoodsInfo +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) +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + +SELECT top 1 GoodsName 名称,GoodsColor 颜色,max(GoodsMoney) 价格 FROM GoodsInfo group by GoodsName,GoodsColor order by max(GoodsMoney) desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 + +select TypeID 编号,MAX(GoodsMoney)最高,min(GoodsMoney)最低,avg(GoodsMoney)平均 from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 + -- Gitee From 9b2d172beddd43bda7d898a9ae5bd3468facebf3 Mon Sep 17 00:00:00 2001 From: zyq520lcx <2642587822@qq.com> Date: Fri, 2 Apr 2021 11:55:43 +0800 Subject: [PATCH 180/195] frist commit --- .../SQLQuery1.sql" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/SQLQuery1.sql" new file mode 100644 index 0000000..cb3c148 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\216\346\231\250\351\234\236/SQLQuery1.sql" @@ -0,0 +1,57 @@ +use master +go + +create database GoodsDB +go + +use GoodsDB +go + +create table GoodsType --商品类型表 +( + TypeID int not null primary key identity(1,1), --商品类型编号 + TypeName nvarchar(20) not null --商品类型名称 +) + + +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), --商品编号 + GoodsName nvarchar(20) not null, --商品名称 + GoodsColor nvarchar(20) not null, --商品颜色 + GoodsBrand nvarchar(20) , --商品品牌 + GoodsMoney money not null, --商品价格 + TypeID int references GoodsType (TypeID) --商品类型编号 +) + +insert into GoodsType +values (1,'服装内衣'), + (2,'鞋包配饰'), + (3,'手机数码') + + + +insert into GoodsInfo(GoodsID,GoodsName,GoodsColor,GoodsBrand,GoodsMoney,TypeID) +values (1,'提花小西装','红色','菲曼琪','300',1), + (2,'百搭短裤','绿色','哥弟','100',1), + (3,'无袖背心','白色','阿依莲','700',1), + (4,'低帮休闲鞋','红色','菲曼琪','900',2), + (5,'中跟单鞋','绿色','哥弟','400',2), + (6,'平底鞋','白色','阿依莲','200',2), + (7,'迷你照相机','红色','尼康','500',3), + (8,'硬盘','黑色','希捷','600',3), + (9,'显卡','黑色','技嘉','800',3) + + +--3、查询价格最贵的 商品名称, 商品颜色 和 商品价格,要求使用 别名 显示列名 +select TOP 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo +order by GoodsMoney DESC + +--4、按 商品类型编号 分组查询 商品最高价格, 最低价格 和 平均价格,要求使用别名显示列名 +select TypeID 商品类型编号,max(GoodsMoney)最高价格,min(GoodsMoney)最低价格,avg(GoodsMoney)平均价格 from GoodsInfo +group by TypeID + + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney>=300 and GoodsMoney<=600 + -- Gitee From fe3bf659a93c340db05844eebef95723f3a24ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E5=8F=98=E5=B0=8F=E7=8C=AA?= <1589953126@qq.com> Date: Fri, 2 Apr 2021 11:56:02 +0800 Subject: [PATCH 181/195] SQL --- .../SQLQuery1.sql" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" new file mode 100644 index 0000000..e1ff12d --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\261\237\346\226\260\344\274\240/SQLQuery1.sql" @@ -0,0 +1,73 @@ +create database Jxc + +on + +( +name='Jxc', +filename='D:\Jxc.mdf', +size=5, +maxsize=100, +filegrowth=10% +) +log on + +( +name='Jxc_log', +filename='D:\Jxc_log.ldf', +size=5, +maxsize=100, +filegrowth=10% +) + +use Jxc + +create table GoodsType +( +TypeID int not null primary key identity(1,1), +TypeName nvarchar(20) not null +) + +create table GoodInfo + + ( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null , + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) not null , + GoodsMoney money not null, + TypeID int foreign key references GoodsType(TypeID) + ) + + insert into GoodsType + + select '服装内衣' union + select '鞋包配饰' union + select '手机数码' + + insert into GoodInfo + + select '提花小西装','红色','菲曼琪',300 ,1 union + select '百搭短裤','绿色','哥弟',100,1 union + select '无袖背心','白色',' 阿依莲',700,1 union + select '低帮休闲鞋',' 红色','菲曼琪',900,2 union + select ' 中跟单鞋','绿色','哥弟',400,2 union + select '平底鞋','白色',' 阿依莲',200,2 union + select '迷你照相机 ','红色','尼康 ',500,3 union + select ' 硬盘','黑色','希捷',600,3 union + select ' 显卡','黑色','技嘉',800,3 + + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + select GoodsName 商品名称 ,GoodsColor 商品颜色 ,GoodsMoney 商品价格 from GoodInfo + where GoodsMoney in (select max(GoodsMoney) from GoodInfo) + +--4、按商品类型编号分组 查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 + +select TypeID 类型编号, max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 from GoodInfo +group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +select * from GoodInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 + + -- Gitee From cef928f81cd5d331915fb8779d6ffd7bd1d8bfa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=93=A6=E7=89=B9=E5=8F=91?= <3144531710@qq.com> Date: Fri, 2 Apr 2021 12:02:07 +0800 Subject: [PATCH 182/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\346\275\230\345\256\207/SQLQuery2.sql" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" new file mode 100644 index 0000000..4466dd1 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\275\230\345\256\207/SQLQuery2.sql" @@ -0,0 +1,65 @@ +USE master +GO +CREATE DATABASE GoodsDB +on +( +name='wq', +filename='D:\wq.mdf', +size=1 +) +log on +( +name='wq_log', +filename='D:\wq_log.ldf', +size=1 +) +GO +use GoodsDB +GO +CREATE TABLE GoodsType +( +TypeID INT NOT NULL IDENTITY(1,1), +TypeName NVARCHAR(20) NOT NULL +) +GO +ALTER TABLE GoodsType add constraint DK_GoodsType_TYPEID PRIMARY KEY(TYPEID) +SELECT * FROM GoodsType +INSERT INTO GoodsType(TypeName) +values('服装内衣'), +('鞋包配饰'), +('手机数码') +CREATE TABLE GoodsInfo +( +GoodsID INT NOT NULL IDENTITY(1,1), +GoodsName NVARCHAR(20) NOT NULL, +GoodsColor NVARCHAR(20) NOT NULL , +GoodsBrand NVARCHAR(20) , +GoodsMoney MONEY NOT NULL, +TypeID INT +) +GO +ALTER TABLE GoodsInfo ADD CONSTRAINT GK_GoodsInfo_GoodsID primary key(GoodsID) +ALTER TABLE GoodsInfo ADD CONSTRAINT JK_GoodsInfo_TypeID FOREIGN KEY(TYPEID) references GoodsType(TypeID) +SELECT * FROM GoodsInfo +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) +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + +SELECT top 1 GoodsName 名称,GoodsColor 颜色,max(GoodsMoney) 价格 FROM GoodsInfo group by GoodsName,GoodsColor order by max(GoodsMoney) desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 + +select TypeID 编号,MAX(GoodsMoney)最高,min(GoodsMoney)最低,avg(GoodsMoney)平均 from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 + -- Gitee From 603f758c57a25a4ac6ce94977931f169d5c06dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BB=BA=E5=B3=B0?= <357616491@qq.com> Date: Fri, 2 Apr 2021 12:03:42 +0800 Subject: [PATCH 183/195] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery2.sql" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/SQLQuery2.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/SQLQuery2.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/SQLQuery2.sql" new file mode 100644 index 0000000..4466dd1 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\345\273\272\345\263\260/SQLQuery2.sql" @@ -0,0 +1,65 @@ +USE master +GO +CREATE DATABASE GoodsDB +on +( +name='wq', +filename='D:\wq.mdf', +size=1 +) +log on +( +name='wq_log', +filename='D:\wq_log.ldf', +size=1 +) +GO +use GoodsDB +GO +CREATE TABLE GoodsType +( +TypeID INT NOT NULL IDENTITY(1,1), +TypeName NVARCHAR(20) NOT NULL +) +GO +ALTER TABLE GoodsType add constraint DK_GoodsType_TYPEID PRIMARY KEY(TYPEID) +SELECT * FROM GoodsType +INSERT INTO GoodsType(TypeName) +values('服装内衣'), +('鞋包配饰'), +('手机数码') +CREATE TABLE GoodsInfo +( +GoodsID INT NOT NULL IDENTITY(1,1), +GoodsName NVARCHAR(20) NOT NULL, +GoodsColor NVARCHAR(20) NOT NULL , +GoodsBrand NVARCHAR(20) , +GoodsMoney MONEY NOT NULL, +TypeID INT +) +GO +ALTER TABLE GoodsInfo ADD CONSTRAINT GK_GoodsInfo_GoodsID primary key(GoodsID) +ALTER TABLE GoodsInfo ADD CONSTRAINT JK_GoodsInfo_TypeID FOREIGN KEY(TYPEID) references GoodsType(TypeID) +SELECT * FROM GoodsInfo +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) +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + +SELECT top 1 GoodsName 名称,GoodsColor 颜色,max(GoodsMoney) 价格 FROM GoodsInfo group by GoodsName,GoodsColor order by max(GoodsMoney) desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 + +select TypeID 编号,MAX(GoodsMoney)最高,min(GoodsMoney)最低,avg(GoodsMoney)平均 from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 + -- Gitee From 80946a64f3d96485989d25ed3e03255f0f57d140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E5=BF=A7?= <2486779710@qq.com> Date: Fri, 2 Apr 2021 12:04:09 +0800 Subject: [PATCH 184/195] zy --- .../sql.sql" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/sql.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/sql.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/sql.sql" new file mode 100644 index 0000000..ffbec08 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/sql.sql" @@ -0,0 +1,62 @@ +use master +go +create database GoodsDB +on +( name='GoodsDB', + filename='D:\GoodsDB.mdf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +log on +( name='GoodsDB_log', + filename='D:\GoodsDB_log.ldf', + size=5mb, + maxsize=5000mb, + filegrowth=1mb +) +go +use GoodsDB +go + +create table GoodsType +( + TypeID int primary key identity, + TypeName nvarchar(20) not null + +) + +create table GoodsInfo +( + GoodsID int primary key identity, + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) not null, + GoodsMoney money not null, + TypeID int references GoodsType(TypeID) +) + +insert into GoodsType values('服装内衣'),('鞋包配饰'),('手机数码') + +insert into GoodsInfo values('提花小西装', '红色', '菲曼琪', '300', 1),('百搭短裤', '绿色', '哥弟', '100', 1), + ('无袖背心', '白色', '阿依莲', '700', 1),('低帮休闲鞋', '红色', '菲曼琪', '900', 2), + ('中跟单鞋', '绿色', '哥弟', '400', 2),('平底鞋', '白色', '阿依莲','200', 2), + ('迷你照相机', '红色', '尼康', '500', 3),('硬盘', '黑色', '希捷', '600', 3), + ('显卡', '黑色', '技嘉','800', 3) +select*from GoodsType +select*from GoodsInfo + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + select GoodsName 商品名称, GoodsColor 商品颜色, GoodsMoney 商品价格 + from GoodsInfo + where GoodsMoney=(select max(GoodsMoney) from GoodsInfo) + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格, avg(GoodsMoney) 平均价格 + from GoodsInfo + join GoodsType + on GoodsType.TypeID=GoodsInfo.TypeID + group by TypeName + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and (GoodsMoney between 300 and 600) \ No newline at end of file -- Gitee From fdb7050185a77924305f53226848b5dfa6f0f5b9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 2 Apr 2021 12:05:38 +0800 Subject: [PATCH 185/195] 12 --- ...5\344\271\240\344\275\234\344\270\232.sql" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/\345\244\215\344\271\240\344\275\234\344\270\232.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/\345\244\215\344\271\240\344\275\234\344\270\232.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/\345\244\215\344\271\240\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..696d82b --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\350\203\241\350\266\212/\345\244\215\344\271\240\344\275\234\344\270\232.sql" @@ -0,0 +1,67 @@ +--创建商品数据库(GoodsDB),然后建立两张表,GoodsType(商品类型表),GoodsInfo(商品信息表),表结构分别如下: +create database GoodsDB +go + +use GoodsDB +go + +create table GoodsType( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) + +create table GoodsInfo( + GoodsID int not null primary key identity(1,1), + 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) +) + +--2、使用插入语句为两张表添加数据 +--商品类型表(GoodsType) +--商品类型编号 商品类型名称 +--1 服装内衣 +--2 鞋包配饰 +--3 手机数码 +insert GoodsType(TypeName) values +('服装内衣'), +('鞋包配饰'), +('手机数码') + +--商品信息表(GoodsType) +--商品编号 商品名称 商品颜色 商品品牌 商品价格 商品类型编号 +--1 提花小西装 红色 菲曼琪 300 1 +--2 百搭短裤 绿色 哥弟 100 1 +--3 无袖背心 白色 阿依莲 700 1 +--4 低帮休闲鞋 红色 菲曼琪 900 2 +--5 中跟单鞋 绿色 哥弟 400 2 +--6 平底鞋 白色 阿依莲 200 2 +--7 迷你照相机 红色 尼康 500 3 +--8 硬盘 黑色 希捷 600 3 +--9 显卡 黑色 技嘉 800 3 + +--set identity_insert GoodsType ON--打开 +--set identity_insert GoodsInfo ON--打开 + +insert into GoodsInfo values +('提花小西装','红色','菲曼琪','300',1), +('百搭短裤','绿色','哥弟','100',1), +('无袖背心','白色','阿依莲','700',1), +('低帮休闲鞋','红色','菲曼琪','900',2), +('中跟单鞋','绿色','哥弟','400',2), +('平底鞋','白色','阿依莲','200',2), +('迷你照相机','红色','尼康','500',3), +('硬盘','黑色','希捷','600',3), +('显卡','黑色','技嘉','800',3) + +select * from GoodsInfo +----3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsMoney 商品价格,GoodsName 商品名称,GoodsColor 商品颜色 from GoodsInfo order by GoodsMoney desc + +----4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 类型编号,MAX(GoodsMoney)最高价格,AVG(GoodsMoney)平均价格,MIN(GoodsMoney)最低价格 from GoodsInfo group by typeID + +----5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and (GoodsMoney>300 and GoodsMoney<600) -- Gitee From 65b13d23c40d27bbf07ffc40b761b7a557b2c1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=BE=E5=A4=A7=E6=98=9F=E5=91=80?= <2454478226@qq.com> Date: Fri, 2 Apr 2021 12:06:13 +0800 Subject: [PATCH 186/195] zy --- .../zy.sql" | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" new file mode 100644 index 0000000..69d7340 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\344\270\226\350\276\211/zy.sql" @@ -0,0 +1,100 @@ +use master +go + +create database GoodsDB +on primary +( +name='GoodsDB', +filename='D:\.mdf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) + +log on +( +name='GoodsDB_log', +filename='D:\_log.ldf', +size=5MB, +filegrowth=1MB, +maxsize=5MB +) +go + +use GoodsDB + +----字段名 说明 类型 长度 可否为空 约束 +----TypeID 商品类型编号 int 否 主键约束,自增约束,标识种子和标识增量都是1 +----TypeName 商品类型名称 nvarchar 20 否 + +create table GoodsType --建立商品类型表 +( +TypeID int primary key identity not null, +TypeName nvarchar(20) not null +) +go + +--字段名 说明 类型 长度 可否为空 约束 +--GoodsID 商品编号 int 否 主键约束,自增约束,标识种子和标识增量都是1 +--GoodsName 商品名称 nvarchar 20 否 +--GoodsColor 商品颜色 nvarchar 20 否 +--GoodsBrand 商品品牌 nvarchar 20 +--GoodsMoney 商品价格 money 否 +--TypeID 商品类型编号 int 外键,参照GoodsType中的TypeID + +create table GoodsInfo --建立商品信息表 +( +GoodsID int primary key identity 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) +) +go + +select * from GoodsType + +insert into GoodsType(TypeName) values +('服饰内衣'), +('鞋包配饰'), +('手机数码') + +--商品信息表(GoodsType) +--商品编号 商品名称 商品颜色 商品品牌 商品价格 商品类型编号 +--1 提花小西装 红色 菲曼琪 300 1 +--2 百搭短裤 绿色 哥弟 100 1 +--3 无袖背心 白色 阿依莲 700 1 +--4 低帮休闲鞋 红色 菲曼琪 900 2 +--5 中跟单鞋 绿色 哥弟 400 2 +--6 平底鞋 白色 阿依莲 200 2 +--7 迷你照相机 红色 尼康 500 3 +--8 硬盘 黑色 希捷 600 3 +--9 显卡 黑色 技嘉 800 3 + +select * from GoodsInfo + +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 GoodsType +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 + +select top 1 s1.GoodsName 商品名称,s1.GoodsColor 商品颜色,s1.GoodsMoney 商品价格 from GoodsInfo s1 order by s1.GoodsMoney desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 + +select s2.TypeID,count(s2.TypeID)数量,max(s2.GoodsMoney) 最高价格,min(s2.GoodsMoney) 最低价格,avg(s2.GoodsMoney) 平均价格 from GoodsInfo s2 group by s2.TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +select * from(select top 6 s1.GoodsName,s1.GoodsColor,s1.GoodsMoney from GoodsInfo s1 order by s1.GoodsMoney) s2 where s2.GoodsColor='红色' -- Gitee From 356b890de10f025cef697a75fc068d3725119e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E7=91=BE=E8=A8=80?= <2220660532@qq.com> Date: Fri, 2 Apr 2021 12:08:44 +0800 Subject: [PATCH 187/195] =?UTF-8?q?=E6=AE=B5=E5=97=A3=E5=87=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery1.sql" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery1.sql" new file mode 100644 index 0000000..72cf4dc --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\256\265\345\227\243\345\207\257/SQLQuery1.sql" @@ -0,0 +1,48 @@ +create database GoodsDB + +use GoodsDB +go + +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) + +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null , + GoodsColor nvarchar(20) not null , + GoodsBrand nvarchar(20) , + GoodsMoney money not null, + TypeID int foreign key references GoodsType(TypeID) +) + +insert into GoodsType values +('服装内衣'), +('鞋包配饰'), +('手机数码') + + +insert into GoodsInfo values +('提花小西装','红色','菲曼琪','300',1), +('百搭短裤','绿色','哥弟','100',1), +('无袖背心','白色','阿依莲','700',1), +('低帮休闲鞋','红色','菲曼琪','900',2), +('中跟单鞋','绿色','哥弟','400',2), +('平底鞋','白色','阿依莲','200',2), +('迷你照相机','红色','尼康','500',3), +('硬盘','黑色','希捷','600',3), +('显卡','黑色','技嘉','800',3) + +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsMoney 商品价格,GoodsName 商品名称,GoodsColor 商品颜色 from GoodsInfo group by GoodsName,GoodsColor,GoodsMoney order by GoodsMoney desc +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 类型编号,max(GoodsMoney) 最高价格,min(GoodsMoney ) 最低价格,avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor ='红色'and GoodsMoney>300 and GoodsMoney<600 + + + -- Gitee From b5335c448b44c2e58d60031b2f7aa95c13d0ce63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=8F=B6=E5=B8=85?= <2876015251@qq.com> Date: Fri, 2 Apr 2021 12:20:06 +0800 Subject: [PATCH 188/195] SQL --- .../SQLQuery1.sql" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" new file mode 100644 index 0000000..c06b445 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\345\217\266\345\270\205/SQLQuery1.sql" @@ -0,0 +1,55 @@ +create database GoodsDB +on +( + name='GoodsDB', + filename='D:\sp\GoodsDB.mdf', + size=10mb, + filegrowth=2mb +) +log on +( + name='GoodsDB_log', + filename='D:\sp\GoodsDB_log.ldf', + size=10mb, + filegrowth=2mb +) +use GoodsDB +go +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null , + GoodsColor nvarchar(20) not null , + GoosdBrand 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,GoosdBrand,GoodsMoney,TypeID)values +('提花小西装',' 红色',' 菲曼琪', 300, 1), +('百搭短裤 ','绿色',' 哥弟', 100, 1), +('无袖背心', '白色',' 阿依莲', 700, 1), +('低帮休闲鞋',' 红色',' 菲曼琪', 900, 2), +('中跟单鞋',' 绿色',' 哥弟', 400, 2), +('平底鞋',' 白色',' 阿依莲', 200, 2), +('迷你照相机',' 红色', '尼康', 500, 3), +('硬盘', '黑色',' 希捷', 600, 3), +(' 显卡',' 黑色', '技嘉' ,800, 3) +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney in (select max(GoodsMoney) from GoodsInfo) + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID,max(GoodsMoney)最高价格,min(GoodsMoney)最低价格 ,avg(GoodsMoney)平均价格 from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where (GoodsMoney>=300 and GoodsMoney<=600) and GoodsColor=' 红色' \ No newline at end of file -- Gitee From 036e6257ee57897365444b478c8b3a220f66aa26 Mon Sep 17 00:00:00 2001 From: BMxhd796815 <2396054158@qq.com> Date: Fri, 2 Apr 2021 12:22:59 +0800 Subject: [PATCH 189/195] first commit --- .../SQLQuery1.sql" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery1.sql" new file mode 100644 index 0000000..06ef567 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\351\237\265\345\251\267/SQLQuery1.sql" @@ -0,0 +1,44 @@ +use master +go +create database GoodsDB +go +use GoodsDB +go + +--商品类型表 +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null, +) +go +use GoodsDB +go +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20), + GoodsMoney money not null, + TypeID int references GoodsType(TypeID), +) +go +insert into GoodsType(TypeName) values('服装内衣'),('鞋包配饰'),('手机数码') + +insert into GoodsInfo values('提花小西装','红色','菲曼琪','300',1),('百搭短裤', '绿色', '哥弟', '100', 1),('无袖背心' ,'白色' ,'阿依莲' ,'700' ,1), +('低帮休闲鞋',' 红色 ','菲曼琪',' 900', 2),('中跟单鞋',' 绿色',' 哥弟' ,'400', 2),('平底鞋',' 白色',' 阿依莲',' 200', 2),('迷你照相机', '红色',' 尼康', '500', 3), +('硬盘',' 黑色', '希捷', '600', 3),('显卡' ,'黑色',' 技嘉', '800', 3) + + +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,goodscolor 商品颜色,GoodsMoney 商品价格 +from GoodsInfo order by GoodsMoney desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 类型编号,MAX(GoodsMoney) 最高价格,MIN(GoodsMoney) 最低价格,AVG(GoodsMoney) 平均价格 +from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo +where GoodsColor='红色' or GoodsMoney='300' and GoodsMoney='600' \ No newline at end of file -- Gitee From 1b99b1b8109ecc891e127cbe2b2bd5329546af5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E6=96=B0=E6=96=B0?= <2523868292@qq.com> Date: Fri, 2 Apr 2021 12:27:43 +0800 Subject: [PATCH 190/195] =?UTF-8?q?=E7=BD=97=E5=AE=87=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery5555.sql" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery5555.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery5555.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery5555.sql" new file mode 100644 index 0000000..8fb5b7e --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\347\275\227\345\256\207\346\226\260/SQLQuery5555.sql" @@ -0,0 +1,65 @@ +use master +go + +create database GoodsDB +on +( + name='GoodsDB', + filename='D:\GoodsDB.mdf', + size=10Mb, + maxsize=50Mb, + filegrowth=10% +) +log on +( + name='GoodsDB_log', + filename='D:\GoodsDB_log.ldf', + size=10Mb, + maxsize=50Mb, + filegrowth=10% +) +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 references GoodsType(TypeID) +) + +insert into GoodsType values +('服装内衣'), +('鞋服配饰'), +('手机数码') + +insert into GoodsInfo values +('提花小西装','红色','菲曼琪','300',1), +('百搭短裤','绿色','哥弟','100',1), +('无袖背心','白色','阿依莲','700',1), +('低帮休闲鞋','红色','菲曼琪','900',2), +('中跟单鞋', '绿色', '哥弟', '400', 2), +('平底鞋', '白色', '阿依莲', '200', 2), +('迷你照相机','红色','尼康','500',3), +('硬盘','黑色','希捷','600',3), +('显卡','黑色','技嘉','800',3) + +select * from GoodsInfo +select * from GoodsType +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney DESC +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID, MAX(GoodsMoney) 最高价格,MIN(GoodsMoney) 最低价格,AVG(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and GoodsMoney>=300 and GoodsMoney<=600 \ No newline at end of file -- Gitee From ff39431ceaedcea0e9a34fbfd871c109f288bff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=9D=B0=E7=83=A8?= Date: Fri, 2 Apr 2021 12:33:11 +0800 Subject: [PATCH 191/195] =?UTF-8?q?=E9=BB=84=E6=9D=B0=E7=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1111.sql" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/1111.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/1111.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/1111.sql" new file mode 100644 index 0000000..3429252 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\273\204\346\235\260\347\203\250/1111.sql" @@ -0,0 +1,40 @@ +create database GoodsDB +on +( name='GoodsDB', + filename='D:\SQL\GoodsDB.mdf' +) +log on +( name='GoodsDB_log', + filename='D:\SQL\GoodsDB_log.ldf' +) +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 constraint FK_GoodsInfo_TypeID references GoodsType(TypeID) +) +insert into GoodsType values +('服装内衣'),('鞋包数码'),('手机数码') +insert into GoodsInfo values +('提花小西装','红色','菲曼琪',300,1), +('百搭短裤','绿色','哥弟',100,1),('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2),('中跟单鞋','绿色','哥弟 ',400,2), +('平底鞋','白色','阿依莲',200,2),('迷你照相机','红色 ','尼康',500 ,3), +('硬盘','黑色','希捷',600,3),('显卡 ','黑色','技嘉',800,3) + +--查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo where GoodsMoney = (select MAX(GoodsMoney) from GoodsInfo) +--按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型,MAX(GoodsMoney)最高价格,MIN(GoodsMoney)最低价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID +--查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor = '红色' and GoodsMoney >= 300 and GoodsMoney <= 600 \ No newline at end of file -- Gitee From 8d1d328a9ef6692d8cebd69ce4c8df75b4aff890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=86=E7=93=9Ca?= <1991416367@qq.com> Date: Fri, 2 Apr 2021 12:44:16 +0800 Subject: [PATCH 192/195] zy --- .../SQLQuery1.sql" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" new file mode 100644 index 0000000..9004746 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\210\230\346\226\207\345\274\272/SQLQuery1.sql" @@ -0,0 +1,43 @@ +use master +go +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) not null, +GoodsMoney money not null, +TypeID int foreign key references GoodsType(TypeID) +) +insert into GoodsType +select '服装内衣' union +select '鞋包配饰' union +select '手机数码' +select * from GoodsType +insert into GoodsInfo +select '提花小西装','红色','菲',300,1 union +select '百搭短裤','绿色','哥弟',100,1 union +select '无袖背心','白色','白色',700,1 union +select '低帮休闲鞋','红色','菲曼琪',900,2 union +select '中跟单鞋','绿色','哥弟',400,2 union +select '平底鞋','白色','阿依莲',200,2 union +select '迷你照相机','红色','尼康',500,3 union +select '硬盘','黑色','希捷',600,3 union +select '显卡','黑色','技嘉',800,3 +select * from GoodsType +select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 名称, max(GoodsMoney) 价格,GoodsColor 颜色 from GoodsInfo group by GoodsName ,GoodsColor, GoodsMoney order by GoodsMoney desc +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID,max(GoodsMoney) 最高价格,min(GoodsMoney) 最低价格, avg(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor = '红色' and GoodsMoney between 300 and 600 -- Gitee From 1753a83468bd74483aaa4200938db7fab8bca6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BA=8C=E6=9F=B1?= <2964399941@qq.com> Date: Fri, 2 Apr 2021 12:50:09 +0800 Subject: [PATCH 193/195] =?UTF-8?q?=E6=9D=8E=E5=98=89=E5=9F=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLQuery3.sql" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery3.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery3.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery3.sql" new file mode 100644 index 0000000..e9c7b0a --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/SQLQuery3.sql" @@ -0,0 +1,70 @@ +----1、创建商品数据库(GoodsDB),然后建立两张表,GoodsType(商品类型表),GoodsInfo(商品信息表), +use master +go +create database GoodsDB +on +( + name='GoodsDB', + filename='D:\GoodsDB.mdf', + size=10, + maxsize=50, + filegrowth=10% +) +log on +( + name='GoodsDB_log', + filename='D:\GoodsDB_log.ldf', + size=10, + maxsize=50, + filegrowth=10% +) +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 references GoodsType(TypeID) +) + +insert into GoodsType values +('服装内衣'), +('鞋包配饰'), +('手机数码') + +insert into GoodsInfo values +('提花小西装','红色','菲曼琪','300',1), +('百搭短裤','绿色','哥弟','100',1), +('无袖背心','白色','阿依莲','700',1), +('低帮休闲鞋','红色','菲曼琪','900',2), +('中跟单鞋', '绿色', '哥弟', '400', 2), +('平底鞋', '白色', '阿依莲', '200', 2), +('迷你照相机','红色','尼康','500',3), +('硬盘','黑色','希捷','600',3), +('显卡','黑色','技嘉','800',3) + + +select * from GoodsType +select * from GoodsInfo + +--3、查询 价格最贵的商品名称 ,商品颜色 和 商品价格,要求 使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类别,max(GoodsMoney)最高价格,min(GoodsMoney)最低价格,avg(GoodsMoney)平均价格 +from GoodsInfo group by TypeID + +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + select * from GoodsInfo where GoodsColor='红色' and GoodsMoney between 300 and 600 \ No newline at end of file -- Gitee From f772659b6f54476aea7215915eca8f723805514e Mon Sep 17 00:00:00 2001 From: jckyang <235723419@qq.com> Date: Fri, 2 Apr 2021 12:53:42 +0800 Subject: [PATCH 194/195] spl2 --- .../\346\261\237\346\264\213/SQLQuery1.sql" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" new file mode 100644 index 0000000..fa916cc --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\346\261\237\346\264\213/SQLQuery1.sql" @@ -0,0 +1,59 @@ +create database GoodsDB +on +( + name='E:\GoodsDB', + filename='E:\GoodsDB.mdf', + size=5, + maxsize=50, + filegrowth=10% +) +log +on +( + name='E:\GoodsDB_log', + filename='E:\GoodsDB_log.ldf', + size=5, + maxsize=50, + filegrowth=10% +) +use GoodsDB + +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null +) +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20) , + GoodsMoney money not null, + TypeID int foreign key references GoodsType(TypeID) +) + +insert into GoodsType values +('服饰内衣'), +('鞋包配饰'), +('手机数码') +insert into GoodsInfo values +('提花小西装','红色','菲曼琪',300,1), +('百搭短裤','绿色','哥弟',100,1), +('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2), +('中跟单鞋','绿色','哥弟',400,2), +('平底鞋','白色','阿依莲',200,2), +('迷你照相机','红色','尼康',500,3), +('硬盘','黑色','希捷',600,3), +('显卡','黑色','技嘉',800,3) +select * from GoodsType +select * from GoodsInfo + +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格 + from GoodsInfo order by GoodsMoney desc + +select TypeID 编号,max(GoodsMoney)最高价格,min(GoodsMoney)最低价格,avg(GoodsMoney)平均价格 + from GoodsInfo group by TypeID + + select * from GoodsInfo where GoodsColor='红色' and GoodsMoney<=600 and GoodsMoney>=300 \ No newline at end of file -- Gitee From 5a48f00e11b12800deb8b11a867c9d263817b911 Mon Sep 17 00:00:00 2001 From: hzt1993 <248875989@qq.com> Date: Fri, 2 Apr 2021 12:57:36 +0800 Subject: [PATCH 195/195] first commit --- .../SQLQuery1.sql" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" diff --git "a/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" new file mode 100644 index 0000000..1346b84 --- /dev/null +++ "b/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\345\207\214\345\256\217\344\270\275/SQLQuery1.sql" @@ -0,0 +1,34 @@ +create database GoodsDB +go +use GoodsDB +go + +--商品类型表 +create table GoodsType +( + TypeID int not null primary key identity(1,1), + TypeName nvarchar(20) not null, +) +insert into GoodsType(TypeName) values('服装内衣'),('鞋包配饰'),('手机数码') + + +--商品信息表 +create table GoodsInfo +( + GoodsID int not null primary key identity(1,1), + GoodsName nvarchar(20) not null, + GoodsColor nvarchar(20) not null, + GoodsBrand nvarchar(20), + GoodsMoney money not null, + TypeID int references GoodsType(TypeID), +) +insert into GoodsInfo values('提花小西装','红色','菲曼琪','300',1),('百搭短裤', '绿色', '哥弟', '100', 1),('无袖背心' ,'白色' ,'阿依莲' ,'700' ,1), +('低帮休闲鞋',' 红色 ','菲曼琪',' 900', 2),('中跟单鞋',' 绿色',' 哥弟' ,'400', 2),('平底鞋',' 白色',' 阿依莲',' 200', 2),('迷你照相机', '红色',' 尼康', '500', 3), +('硬盘',' 黑色', '希捷', '600', 3),('显卡' ,'黑色',' 技嘉', '800', 3) +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,goodscolor 商品颜色,GoodsMoney 商品价格 from GoodsInfo order by GoodsMoney desc + +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 类型编号,MAX(GoodsMoney) 最高价格,MIN(GoodsMoney) 最低价格,AVG(GoodsMoney) 平均价格 from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' or GoodsMoney='300' and GoodsMoney='600' \ No newline at end of file -- Gitee