diff --git "a/15\351\231\210\346\231\223\345\275\244/.keep" "b/15\351\231\210\346\231\223\345\275\244/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/lenovo20230217214915.png" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/lenovo20230217214915.png" new file mode 100644 index 0000000000000000000000000000000000000000..2a1af1b26fadda23a2bb3ef3da8453f12934f988 Binary files /dev/null and "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/lenovo20230217214915.png" differ diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321(1).sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321(1).sql" new file mode 100644 index 0000000000000000000000000000000000000000..f40e1fe16c772cba88cf9e1c40217ed4b0afcd10 --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321(1).sql" @@ -0,0 +1,67 @@ +create database student6 +go +use student6 + +create table student ( +stuno nvarchar(10) primary key, +stuname nvarchar(20) not null, +stuage int not null, +stuaddress nvarchar(20) not null, +stuseat int identity, +stusex nvarchar(1) not null +); + +insert into student(stuno, stuname, stuage, stuaddress, stusex) +values('s2501','张秋利',20,'美国硅谷',1) +insert into student(stuno, stuname, stuage, stuaddress, stusex) +values('s2502','李斯文',18,'湖北武汉',0), +('s2503','马文才',22,'湖南长沙',1), +('s2504','欧阳俊雄',21,'湖北武汉',0), +('s2505','梅超风',20,'湖北武汉',1), +('s2506','陈旋风',19,'美国硅谷',1), +('s2507','陈风',20,'美国硅谷',0) + +create table exam( +examno int primary key identity, +stuno nvarchar(10) references student (stuno), +writtenexam int not null, +labexam int not null +); + +insert into exam(stuno,writtenexam,labexam) +values('s2501',50,70), +('s2502',60,65), +('s2503',86,85), +('s2504',40,80), +('s2505',70,90), +('s2506',85,90) + +select * from exam +select * from student + +select stuno as 学生编号, stuname as 学生名, stuage as 学生年龄, stuaddress as 学生地址, stuseat as 学生座位, stusex as 性别 from student +select stuname,stuage,stuaddress from student + +select stuno 学号, writtenexam 笔试, labexam 机试 from exam +select stuno as 学号, writtenexam as 笔试, labexam as 机试 from exam +select 学号= stuno , 笔试= writtenexam,机试= labexam from exam + +select * ,stuname+'@'+stuaddress as 邮箱 from student +select stuno, writtenexam, labexam ,writtenexam+labexam as 总分 from exam + +select distinct stuaddress from student +select distinct stuage as 年龄 from student +select top 3 * from student +select top 4 stuname,stuseat from student +select top 50 percent * from student +select * from student where stuaddress='湖北武汉'and stuage=20 +select * from exam where labexam>60 and labexam<80 order by labexam desc + + +select * from student where stuaddress='湖北武汉'or stuaddress='湖南长沙' +select * from student where not(stuaddress='美国硅谷') + +select * from exam where writtenexam<70 or labexam>90 order by writtenexam asc + +select * from student where stuage=' ' +select * from student where not(stuage=' ') \ No newline at end of file diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_171911.png" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_171911.png" new file mode 100644 index 0000000000000000000000000000000000000000..af4ac59825f3fd95e3e6266c77eb02b509faf623 Binary files /dev/null and "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_171911.png" differ diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_173004.png" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_173004.png" new file mode 100644 index 0000000000000000000000000000000000000000..ffecaba5b0835540525db87b273c4fbd5828e14a Binary files /dev/null and "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_173004.png" differ diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_173823.png" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_173823.png" new file mode 100644 index 0000000000000000000000000000000000000000..7aec316b88f7425f3cda084a4e6e2a73e7d86f8c Binary files /dev/null and "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_173823.png" differ diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_191854.png" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_191854.png" new file mode 100644 index 0000000000000000000000000000000000000000..5cda83dff384f2b5790911aa1e1f544c245adc7e Binary files /dev/null and "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_191854.png" differ diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_192330.png" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_192330.png" new file mode 100644 index 0000000000000000000000000000000000000000..dbdb2640de34d611dda79c2cea5a8b7a4a27e15a Binary files /dev/null and "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/2023-02-20_192330.png" differ diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.sql" new file mode 100644 index 0000000000000000000000000000000000000000..a27759377c439732feb20985a675686a8986025a --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214.sql" @@ -0,0 +1,43 @@ +create database chen +use chen +create table orders( +orderid int primary key identity, +orderdate datetime +) + +create table orderitem( +itemid int primary key identity, +orderid tinyint, +itemtype varchar(10), +itemname varchar(10), +thenumber tinyint, +themoney tinyint + +) + +--查询所有订单订购的所有物品数量总和 +select sum(thenumber) as 总数 from orderitem + +--查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select sum(thenumber) as 总数 from orderitem where orderid<3 having avg(themoney)<10; +--查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select avg(thenumber) as pingjundanjia from orderitem where avg(themoney)<10 having sum(thenumber)>50 + +--查询每种类别的产品分别订购了几次,例如: + -- 文具 9 + -- 体育用品 3 + --日常用品 3 +select count(0) as '文具' from orderitem where itemtype='文具'; +select count(0) as '体育用品' from orderitem where itemtype='体育用品'; +select count(0) as '日常用品' from orderitem where itemtype='日常用品'; + +--查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select itemtype ,sum(thenumber) as shuliang from orderitem group by itemtype having sum(thenumber)>100 ; +select itemtype ,avg(themoney) from orderitem group by itemtype; + +--查询每种产品的订购次数,订购总数量和订购的平均单价,例如: + +--产品名称 订购次数 总数量 平均单价 +-- 笔 3 120 2 +select* from orderitem; +select itemname ,count(0) as次数 ,sum(thenumber) as 总数量 , avg(themoney) as 平均单价 from orderitem group by itemname ; \ No newline at end of file diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\221\250\346\234\253\344\275\234\344\270\232.docx" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\221\250\346\234\253\344\275\234\344\270\232.docx" new file mode 100644 index 0000000000000000000000000000000000000000..38119ab35fad64612bc765ae65563d732925f969 Binary files /dev/null and "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\221\250\346\234\253\344\275\234\344\270\232.docx" differ diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/zuoye.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/zuoye.sql" new file mode 100644 index 0000000000000000000000000000000000000000..f4e297f5b7f307afb962f3579fdc4a77fa30afc6 --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/zuoye.sql" @@ -0,0 +1,151 @@ +create database rong +use rong +create table class( +classid int primary key identity, +classname nvarchar(10) +) + +create table student( +studentid int primary key identity, +studentname nvarchar(10), +studentsex tinyint, +studentbirth date, +studentadress nvarchar(255), + +) + +insert into class(classname) values('软件一班') +insert into class(classname) values('软件二班'),('计算机应用技术班') + +--软件一班有3个同学,姓名、性别、生日、家庭住址 分别是: + +--刘正、男(1)、2000-01-01、广西省桂林市七星区空明西路10号鸾东小区 +--黄贵、男、2001-03-20、江西省南昌市青山湖区艾溪湖南路南150米广阳小区 +--陈美、女(2)、2000-07-08、福建省龙岩市新罗区曹溪街道万达小区 +insert into student(studentname,studentsex,studentbirth,studentadress) +values('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区') +insert into student(studentname,studentsex,studentbirth,studentadress) +values('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区'), + ('陈美',2,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区') + +--软件二班有2个同学,姓名、性别、生日、家庭住址 分别是: + +--江文、男、2000-08-10、安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光 +--钟琪、女、2001-03-21、湖南省长沙市雨花区红花坡社区 + +insert into student(studentname,studentsex,studentbirth,studentadress,classid) +values('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), + ('钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2) + +alter table student add classid int + +--计算机应用技术班有4个同学,姓名、性别、生日、家庭住址 分别是: + +--曾小林、男、1999-12-10、安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光 +--欧阳天天、女、2000-04-05、湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府 +--徐长卿、男、2001-01-30、江苏省苏州市苏州工业园区独墅湖社区 +--李逍遥、男、1999-11-11、广东省广州市白云区金沙洲岛御洲三街恒大绿洲 + +insert into student(studentname,studentsex,studentbirth,studentadress,classid) +values('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), + ('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), + ('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), + ('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3) + +--有2个学生尚未分配班级,姓名、性别、生日、家庭住址 分别是: + +-- 东方不败 保密 1999-12-11 河北省平定州西北四十余里的猩猩滩 +--令狐冲 男 2000-08-11 陕西省渭南市华阴市玉泉路南段 +insert into student(studentname,studentsex,studentbirth,studentadress) +values('东方不败',4,'1999-12-11','河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1,'2000-08-11','陕西省渭南市华阴市玉泉路南段') + +--软件一班开设课程,课程名称和学分分别为: + +--数据库高级应用、3 +--javascript编程基础、3 +--web前端程序设计基础、4 +--动态网页设计.net基础、6 + create table coure( + courename nvarchar(20), + score int, + coureid int primary key identity + ) + insert into coure(courename,score)values('数据库高级应用',3),('javascript编程基础',3), + ('web前端程序设计基础',4),('动态网页设计.net基础',6) + insert into classcoure(classid,coureid) + values(1,1),(1,2),(1,3),(1,4) + --软件二班开设课程,课程名称和学时分别为: + +--数据库高级应用、3 +--javascript编程基础、3 +--web前端程序设计基础、4 +--动态网页设计.net基础、6 +create table classcoure( +classid int, +coureid tinyint +) +insert into classcoure(classid,coureid) +values(2,1),(2,2),(2,3),(2,4) + +--计算机应用技术班开设课程,课程名称和学时分别为: + +--数据库高级应用、3 +--javascript编程基础、3 +--web前端程序设计基础、4 +--动态网页设计php基础、6 +insert into classcoure(classid,coureid) +values(3,1),(3,2),(3,3),(3,4) + +create table studentscore( +studentid int, +coureid int, +score int, +scoreid int + +) + +insert into studentscore (studentid,coureid,score)values(1,1,80); +insert into studentscore (studentid,coureid,score)values(1,2,78); +insert into studentscore (studentid,coureid,score)values(1,3,65); +insert into studentscore (studentid,coureid,score)values(1,4,90); + +insert into studentscore (studentid,coureid,score)values(2,1,60); +insert into studentscore (studentid,coureid,score)values(2,2,77); +insert into studentscore (studentid,coureid,score)values(2,3,68); +insert into studentscore (studentid,coureid,score)values(2,4,88); + +insert into studentscore (studentid,coureid,score)values(3,1,88); +insert into studentscore (studentid,coureid,score)values(3,2,45); +insert into studentscore (studentid,coureid,score)values(3,3,66); +insert into studentscore (studentid,coureid,score)values(3,4,75); + +insert into studentscore (studentid,coureid,score)values(4,1,56); +insert into studentscore (studentid,coureid,score)values(4,2,80); +insert into studentscore (studentid,coureid,score)values(4,3,75); +insert into studentscore (studentid,coureid,score)values(4,4,66); + +insert into studentscore (studentid,coureid,score)values(5,1,88); +insert into studentscore (studentid,coureid,score)values(5,2,79); +insert into studentscore (studentid,coureid,score)values(5,3,72); +insert into studentscore (studentid,coureid,score)values(5,4,85); + +insert into studentscore (studentid,coureid,score)values(6,1,68); +insert into studentscore (studentid,coureid,score)values(6,2,88); +insert into studentscore (studentid,coureid,score)values(6,3,73); +insert into studentscore (studentid,coureid,score)values(6,4,63); + +insert into studentscore (studentid,coureid,score)values(7,1,84); +insert into studentscore (studentid,coureid,score)values(7,2,90); +insert into studentscore (studentid,coureid,score)values(7,3,92); +insert into studentscore (studentid,coureid,score)values(7,4,78); + +insert into studentscore (studentid,coureid,score)values(8,1,58); +insert into studentscore (studentid,coureid,score)values(8,2,59); +insert into studentscore (studentid,coureid,score)values(8,3,65); +insert into studentscore (studentid,coureid,score)values(8,4,75); + +insert into studentscore (studentid,coureid,score)values(9,1,48); +insert into studentscore (studentid,coureid,score)values(9,2,67); +insert into studentscore (studentid,coureid,score)values(9,3,71); +insert into studentscore (studentid,coureid,score)values(9,4,56); diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b6af2b272f0b1dbacef9199bd6a1a2bc9492425e --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" @@ -0,0 +1,112 @@ +create database ju +use ju +create table class( +classid int primary key identity, +classname nvarchar(10) +) + +create table student( +studentid int primary key identity, +studentname nvarchar(10), +studentsex tinyint, +studentbirth date, +studentadress nvarchar(255) , +stuage tinyint, +classid int +) + + + + +--查询所有的班级 Class 信息 +select * from class + +--查询所有的学生 Student 信息。 +select * from student + +--只查询学生的姓名和地址信息。 +select studentname 姓名,地址=studentadress from student + +--查询获取学生信息表中20%的学生信息 +select top 20 percent * from student + +--查询学生信息表中的班级编号有哪些(去除重复值) +select distinct studentid from student + +create table Course( +Courseid int primary key identity, +Coursename nvarchar(20), +score tinyint not null, +credit tinyint not null, +classid int +) + + --数据排序 +--desc 降序 asc 升序 +--查询所有的课程 Course 信息,并且按照学分从大到小排列。 +select * from Course order by credit desc + +create table Score( +score tinyint, +studentid tinyint, +courseid tinyint, +avgscore tinyint +) + +--查询所有的分数 Score 信息,并且按照分数从小到大排列。 +select * from Score order by score asc + +--查询所有的学生 Student 信息,并且按照年龄从小到大排列 +select * from student order by stuage asc + +--条件筛选 +--select * from 表名 where 条件 + +--查询软件一班所有的学生信息,显示学生id,姓名、性别、生日、住址 +select * from student where classid=1 + +--查询所有的女生,显示学生id,姓名、性别、生日、住址 +select * from student where studentSex=2 + +--查询2000年出生的所有学生,显示学生id,姓名、性别、生日、住址。 +select * from student where studentBirth between '2000-01-01' and '2000-12-30' + +--查询姓是欧阳的学生 +select * from student where studentname like '欧阳%' + +--询地址是桂林市的学生 +select * from student where studentadress like '%桂林市%' + +--查询姓李的学生,并且是三个字的 +select * from student where studentname like '李__' + +--查询 软件一班 有几个学生 +select count(0) from Student where classid= 1; + +--查询 软件一班 有几门课程 +select count(0) from Course where classid= 1; + +--查询 刘正(学生编号为1) 的总分 +select sum(score) from Score where studentid= 1; + +--查询所有学生 数据库高级应用 的平均分 +--select avg(字段) from 表名 +select * from Score where courseid= 1; +select sum(score) as 总分,count(0) as 学生总数 from Score where courseid = 1; +select avg(score) from Score where courseid = 1; + +--查询 所有学生 的总分 +select * from score +select studentid,sum(score) as totalscore from score group by studentid + +--查询 所有学生 的平均分 +select * from score +select studentid,avg(score) as totalscore from score group by studentid + +--查询 所有学生 的平均分,并且按照平均分从高到低排列 +select * from score +select studentid,avg(score) as totalscore from score group by studentid order by avgscore desc + +--查询 所有学生中 平均分 大于80分的学生。(聚合查询 + 分组 + having) +select * from Score; +select StudentId, avg(Score) as AvgScore from Score group by StudentId having avg(Score) > 80 ; diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/zuoye.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/zuoye.sql" new file mode 100644 index 0000000000000000000000000000000000000000..5bfb9fbbd665f9decd63a19d6e21383d2d5de130 --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/zuoye.sql" @@ -0,0 +1,166 @@ +create database rong +use rong +create table class( +classid int primary key identity, +classname nvarchar(10) +) + +create table student( +studentid int primary key identity, +studentname nvarchar(10), +studentsex tinyint, +studentbirth date, +studentadress nvarchar(255), + +) + +insert into class(classname) values('软件一班') +insert into class(classname) values('软件二班'),('计算机应用技术班') + +--软件一班有3个同学,姓名、性别、生日、家庭住址 分别是: + +--刘正、男(1)、2000-01-01、广西省桂林市七星区空明西路10号鸾东小区 +--黄贵、男、2001-03-20、江西省南昌市青山湖区艾溪湖南路南150米广阳小区 +--陈美、女(2)、2000-07-08、福建省龙岩市新罗区曹溪街道万达小区 +insert into student(studentname,studentsex,studentbirth,studentadress) +values('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区') +insert into student(studentname,studentsex,studentbirth,studentadress) +values('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区'), + ('陈美',2,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区') + +--软件二班有2个同学,姓名、性别、生日、家庭住址 分别是: + +--江文、男、2000-08-10、安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光 +--钟琪、女、2001-03-21、湖南省长沙市雨花区红花坡社区 + +insert into student(studentname,studentsex,studentbirth,studentadress,classid) +values('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), + ('钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2) + +alter table student add classid int + +--计算机应用技术班有4个同学,姓名、性别、生日、家庭住址 分别是: + +--曾小林、男、1999-12-10、安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光 +--欧阳天天、女、2000-04-05、湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府 +--徐长卿、男、2001-01-30、江苏省苏州市苏州工业园区独墅湖社区 +--李逍遥、男、1999-11-11、广东省广州市白云区金沙洲岛御洲三街恒大绿洲 + +insert into student(studentname,studentsex,studentbirth,studentadress,classid) +values('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), + ('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), + ('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), + ('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3) + +--有2个学生尚未分配班级,姓名、性别、生日、家庭住址 分别是: + +-- 东方不败 保密 1999-12-11 河北省平定州西北四十余里的猩猩滩 +--令狐冲 男 2000-08-11 陕西省渭南市华阴市玉泉路南段 +insert into student(studentname,studentsex,studentbirth,studentadress) +values('东方不败',4,'1999-12-11','河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1,'2000-08-11','陕西省渭南市华阴市玉泉路南段') + +--软件一班开设课程,课程名称和学分分别为: + +--数据库高级应用、3 +--javascript编程基础、3 +--web前端程序设计基础、4 +--动态网页设计.net基础、6 + create table coure( + courename nvarchar(20), + score int, + coureid int primary key identity + ) + insert into coure(courename,score)values('数据库高级应用',3),('javascript编程基础',3), + ('web前端程序设计基础',4),('动态网页设计.net基础',6) + insert into classcoure(classid,coureid) + values(1,1),(1,2),(1,3),(1,4) + --软件二班开设课程,课程名称和学时分别为: + +--数据库高级应用、3 +--javascript编程基础、3 +--web前端程序设计基础、4 +--动态网页设计.net基础、6 +create table classcoure( +classid int, +coureid tinyint +) +insert into classcoure(classid,coureid) +values(2,1),(2,2),(2,3),(2,4) + +--计算机应用技术班开设课程,课程名称和学时分别为: + +--数据库高级应用、3 +--javascript编程基础、3 +--web前端程序设计基础、4 +--动态网页设计php基础、6 +insert into classcoure(classid,coureid) +values(3,1),(3,2),(3,3),(3,4) + +create table studentscore( +studentid int, +coureid int, +score int, +scoreid int + +) + +insert into studentscore (studentid,coureid,score)values(1,1,80); +insert into studentscore (studentid,coureid,score)values(1,2,78); +insert into studentscore (studentid,coureid,score)values(1,3,65); +insert into studentscore (studentid,coureid,score)values(1,4,90); + +insert into studentscore (studentid,coureid,score)values(2,1,60); +insert into studentscore (studentid,coureid,score)values(2,2,77); +insert into studentscore (studentid,coureid,score)values(2,3,68); +insert into studentscore (studentid,coureid,score)values(2,4,88); + +insert into studentscore (studentid,coureid,score)values(3,1,88); +insert into studentscore (studentid,coureid,score)values(3,2,45); +insert into studentscore (studentid,coureid,score)values(3,3,66); +insert into studentscore (studentid,coureid,score)values(3,4,75); + +insert into studentscore (studentid,coureid,score)values(4,1,56); +insert into studentscore (studentid,coureid,score)values(4,2,80); +insert into studentscore (studentid,coureid,score)values(4,3,75); +insert into studentscore (studentid,coureid,score)values(4,4,66); + +insert into studentscore (studentid,coureid,score)values(5,1,88); +insert into studentscore (studentid,coureid,score)values(5,2,79); +insert into studentscore (studentid,coureid,score)values(5,3,72); +insert into studentscore (studentid,coureid,score)values(5,4,85); + +insert into studentscore (studentid,coureid,score)values(6,1,68); +insert into studentscore (studentid,coureid,score)values(6,2,88); +insert into studentscore (studentid,coureid,score)values(6,3,73); +insert into studentscore (studentid,coureid,score)values(6,4,63); + +insert into studentscore (studentid,coureid,score)values(7,1,84); +insert into studentscore (studentid,coureid,score)values(7,2,90); +insert into studentscore (studentid,coureid,score)values(7,3,92); +insert into studentscore (studentid,coureid,score)values(7,4,78); + +insert into studentscore (studentid,coureid,score)values(8,1,58); +insert into studentscore (studentid,coureid,score)values(8,2,59); +insert into studentscore (studentid,coureid,score)values(8,3,65); +insert into studentscore (studentid,coureid,score)values(8,4,75); + +insert into studentscore (studentid,coureid,score)values(9,1,48); +insert into studentscore (studentid,coureid,score)values(9,2,67); +insert into studentscore (studentid,coureid,score)values(9,3,71); +insert into studentscore (studentid,coureid,score)values(9,4,56); + + +--1.分数表这边 李逍遥 数据库高级应用 成绩 插入重复了,请帮忙删除其中一条数据 +delete from studentscore where scoreid=15 +select * from studentscore + +--2.计算机应用技术班 的 欧阳天天 生日写错了,正确的生日应该是:2000-04-06,请用sql进行修改。 +update student set studentBirth='2000-04-06' +where studentId=7 +select * from student + +--3.计算机应用技术班的徐长卿的javascript编程基础分数填错,正确的分数应该是:61,请用sql进行修改。 +update studentscore set score=61 +where studentid=8 and courseid=2; +select * from studentscore \ No newline at end of file diff --git "a/15\351\231\210\346\231\223\345\275\244/\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\272\214.sql" "b/15\351\231\210\346\231\223\345\275\244/\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\272\214.sql" new file mode 100644 index 0000000000000000000000000000000000000000..8cd118574dada635132cd126cff1aabc3b6dcf64 --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\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\272\214.sql" @@ -0,0 +1,110 @@ +create database chen +use chen +create table orders( +orderid int primary key identity, +orderdate datetime +) + +create table orderitem( +itemid int primary key identity, +orderid tinyint, +itemtype varchar(10), +itemname varchar(10), +thenumber tinyint, +themoney tinyint + +) + +insert into orderitem(orderid,itemtype,itemname,thenumber,themoney) +values(1,'文具','笔',72,2) +insert into orderitem(orderid,itemtype,itemname,thenumber,themoney) +values(1,'文具','尺',10,1), + (1,'体育用品','篮球',1,56), + (2,'文具','笔',36,2), + (2,'文具','固体胶',20,3), + (2,'日常用品','透明胶',2,1), + (3,'体育用品','羽毛球',20,3), + (3,'文具','订书机',20,3), + (3,'文具','订书针',10,3), + (4,'文具','裁纸刀',5,5), + (4,'文具','笔',20,2), + (4,'文具','信纸',50,1), + (4,'日常用品','毛巾',4,5), + (4,'日常用品','透明胶',30,1), + (4,'体育用品','羽毛球',20,3) + + + + + + + +--查询所有订单订购的所有物品数量总和 +select sum(thenumber) as 总数 from orderitem + +--查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select sum(thenumber) as 总数 from orderitem where orderid<3 having avg(themoney)<10; +--查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select avg(thenumber) as pingjundanjia from orderitem where avg(themoney)<10 having sum(thenumber)>50 + +--查询每种类别的产品分别订购了几次,例如: + -- 文具 9 + -- 体育用品 3 + --日常用品 3 +select count(0) as '文具' from orderitem where itemtype='文具'; +select count(0) as '体育用品' from orderitem where itemtype='体育用品'; +select count(0) as '日常用品' from orderitem where itemtype='日常用品'; + +--查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select itemtype ,sum(thenumber) as shuliang from orderitem group by itemtype having sum(thenumber)>100 ; +select itemtype ,avg(themoney) from orderitem group by itemtype; + +--查询每种产品的订购次数,订购总数量和订购的平均单价,例如: + +--产品名称 订购次数 总数量 平均单价 +-- 笔 3 120 2 +select* from orderitem; +select itemname ,count(0) as次数 ,sum(thenumber) as 总数量 , avg(themoney) as 平均单价 from orderitem group by itemname ; + + + +--查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderid 订单编号,orderdate 订单日期,itemtype 类别,itemname 产品名称,thenumber 订购数量,themoney 订购单价 from orders +join orderitem on orders.orderid=orderitem.orderid + +--查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderid 订单编号,orderdate 订单日期,itemtype 类别,itemname 产品名称,thenumber 订购数量,themoney 订购单价 from orders +join orderitem on orders.orderid=orderitem.orderid +where thenumber>50 + +--查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderid 订单编号,orderdate 订单日期,itemtype 类别,itemname 产品名称,thenumber 订购数量,themoney 订购单价,sum(themoney)订购总价 from orders +join orderitem on orders.orderid=orderitem.orderid +group by orders.orderid ,orderdate ,itemtype ,itemname,thenumber,themoney + + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderid 订单编号,orderdate 订单日期,itemtype 类别,itemname 产品名称,thenumber 订购数量,themoney 订购单价,sum(themoney)订购总价 from orders +join orderitem on orders.orderid=orderitem.orderid +where themoney>=5 and thenumber>=50 +group by orders.orderid ,orderdate ,itemtype ,itemname,thenumber,themoney + + +--5.查询每个订单分别订购了几个产品,例如: + --编号 订购产品数 + -- 1 3 + -- 2 4 + +select orderitem.orderid 编号,count(thenumber)订购产品数 from orderitem +group by orderitem.orderid,thenumber +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + + --订单编号 产品类别 订购次数 总数量 + + -- 1 文具 2 82 + -- 1 体育用品 1 1 + -- 2 文具 2 56 + --2 体育用品 1 2 + -- 2 日常用品 1 20 +select orderitem.orderid 订单编号,itemtype 类别,thenumber 订购数量,sum(themoney)订购总价 from orderitem +group by orderitem.orderid,itemtype,thenumber,themoney \ No newline at end of file diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\344\275\234\344\270\232\345\233\233.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\344\275\234\344\270\232\345\233\233.sql" new file mode 100644 index 0000000000000000000000000000000000000000..72b65512d79a8586760f14d30a838e70811dbaf5 --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\344\275\234\344\270\232\345\233\233.sql" @@ -0,0 +1,212 @@ +create database STUDENT +go +use STUDENT +go +create table COURSE( +Courseid int identity not null primary key , +coursename nvarchar(50) not null , +coursecredit tinyint not null default 0 +); +create table CLASS( +CLASSID INT , +classname nvarchar(50) not null , + ); + create table COURSECLASS( + courseclassid int identity primary key not null , + classid int not null , + courseid int not null + ) + + + +create table STUDENT( +studentid int not null primary key identity , +studentname nvarchar(50) not null , +studentsex tinyint not null default 3 , +studentbirth date , +studentadress nvarchar(225) not null , +classid int ) +create table SCORE( +scorid int not null identity primary key , +studentid int not null , +courseid int not null , +score int not null , +foreign key (studentid) references STUDENT(studentid) ) +insert into CLASS(classname) +values('软件一班'),('软件二班'),('计算机应用技术班'); +insert into Student(studentname, studentsex, studentbirth, studentadress, classid) +values('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1) + +insert into Student(studentname, studentsex, studentbirth, studentadress, classid) +values('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), + ('陈美',2,'2000-07-08','福建省龙岩市新罗区曹溪街道万达小区',1); +insert into Student(studentname, studentsex, studentbirth, studentadress, classid) +values('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), + ('钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2); +insert into Student(studentname, studentsex, studentbirth, studentadress, classid) +values('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), + ('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), + ('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), + ('李逍',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3); +insert into Student(studentname, studentsex, studentbirth, studentadress) +values('东方不败',3,'1999-12-11','河北省平定州西北四十余里的猩猩滩'), + ('令狐冲',1,'2000-08-11', '陕西省渭南市华阴市玉泉路南段'); + + + + insert into Course(CourseName, CourseCredit) values ('数据库高级应用', 3); +insert into Course(CourseName, CourseCredit) values ('javascript编程基础', 3); +insert into Course(CourseName, CourseCredit) values ('web前端程序设计基础', 4); +insert into Course(CourseName, CourseCredit) values ('动态网页设计.net基础', 6); + +insert into COURSECLASS (ClassId, CourseId) values (1, 1); +insert into COURSECLASS (ClassId, CourseId) values (1, 2); +insert into COURSECLASS (ClassId, CourseId) values (1, 3); +insert into COURSECLASS (ClassId, CourseId) values (1, 4); +insert into COURSECLASS (ClassId, CourseId) values (2, 1); +insert into COURSECLASS (ClassId, CourseId) values (2, 2); +insert into COURSECLASS (ClassId, CourseId) values (2, 3); +insert into COURSECLASS (ClassId, CourseId) values (2, 4); +insert into Course(CourseName, CourseCredit) values ('动态网页设计php基础', 6); + +insert into COURSECLASS(ClassId, CourseId) values (3, 1); +insert into COURSECLASS (ClassId, CourseId) values (3, 2); +insert into COURSECLASS (ClassId, CourseId) values (3, 3); +insert into COURSECLASS (ClassId, CourseId) values (3, 5); +insert into Score (StudentId, CourseId, Score) values (1, 1, 80); +insert into Score (StudentId, CourseId, Score) values (1, 2, 78); +insert into Score (StudentId, CourseId, Score) values (1, 3, 65); +insert into Score (StudentId, CourseId, Score) values (1, 4, 90); + +insert into Score (StudentId, CourseId, Score) values (2, 1, 60); +insert into Score (StudentId, CourseId, Score) values (2, 2, 77); +insert into Score (StudentId, CourseId, Score) values (2, 3, 68); +insert into Score (StudentId, CourseId, Score) values (2, 4, 88); + +insert into Score (StudentId, CourseId, Score) values (3, 1, 88); +insert into Score (StudentId, CourseId, Score) values (3, 2, 45); +insert into Score (StudentId, CourseId, Score) values (3, 3, 66); +insert into Score (StudentId, CourseId, Score) values (3, 4, 75); +go +insert into Score (StudentId, CourseId, Score) values (4, 1, 56); +insert into Score (StudentId, CourseId, Score) values (4, 2, 80); +insert into Score (StudentId, CourseId, Score) values (4, 3, 75); +insert into Score (StudentId, CourseId, Score) values (4, 4, 66); + +insert into Score (StudentId, CourseId, Score) values (5, 1, 88); +insert into Score (StudentId, CourseId, Score) values (5, 2, 79); +insert into Score (StudentId, CourseId, Score) values (5, 3, 72); +insert into Score (StudentId, CourseId, Score) values (5, 4, 85); + + +insert into Score (StudentId, CourseId, Score) values (6, 1, 68); +insert into Score (StudentId, CourseId, Score) values (6, 2, 88); +insert into Score (StudentId, CourseId, Score) values (6, 3, 73); +insert into Score (StudentId, CourseId, Score) values (6, 5, 63); + +insert into Score (StudentId, CourseId, Score) values (7, 1, 84); +insert into Score (StudentId, CourseId, Score) values (7, 2, 90); +insert into Score (StudentId, CourseId, Score) values (7, 3, 92); +insert into Score (StudentId, CourseId, Score) values (7, 5, 78); + +insert into Score (StudentId, CourseId, Score) values (8, 1, 58); +insert into Score (StudentId, CourseId, Score) values (8, 2, 59); +insert into Score (StudentId, CourseId, Score) values (8, 3, 65); +insert into Score (StudentId, CourseId, Score) values (8, 5, 75); + +insert into Score (StudentId, CourseId, Score) values (9, 1, 48); +insert into Score (StudentId, CourseId, Score) values (9, 2, 67); +insert into Score (StudentId, CourseId, Score) values (9, 3, 71); +insert into Score (StudentId, CourseId, Score) values (9, 5, 56); +insert into Score (StudentId, CourseId, Score) values (9, 5, 56); +go + +update STUDENT set studentsex=3 where studentid=1; +/*1. 计算机应用技术班 的 欧阳天天 生日写错了,正确的生日应该是:2000-04-06,请用sql进行修改。 +2. */ +select * from STUDENT; +update STUDENT set studentbirth='2000-04-06' where studentid=7; +/*1. 查询所有的班级 Class 信息。 +2. 查询所有的学生 Student 信息。 +3. 查询所有的课程 Course 信息。 +4. 查询所有的班级课程 ClassCourse 信息。 +5. 查询所有的分数 Score 信息。 +6. 查询所有的课程 Course 信息,并且按照学分从大到小排列。 +7. 查询所有的分数 Score 信息,并且按照分数从小到大排列。 +8. 查询所有的学生 Student 信息,并且按照年龄从小到大排列。 +9. 查询软件一班所有的学生信息,显示学生id,姓名、性别、生日、住址。 +10. 查询所有的女生,显示学生id,姓名、性别、生日、住址。 +11. 查询2000年出生的所有学生,显示学生id,姓名、性别、生日、住址。*/ +select * from CLASS; +select * from STUDENT; +select * from COURSE; +select * from COURSECLASS; +select * from SCORE; +select * from COURSE order by coursecredit desc; +select * from SCORE order by score ASC; +select * from STUDENT order by studentbirth ASC ; + + +select * from STUDENT where classid=1; +select * from STUDENT where studentsex=2 +/*1. 查询姓是欧阳的学生。 +2. 询地址是桂林市的学生。 +3. 查询姓李的学生,并且是三个字的。 +4. 查询 软件一班 有几个学生。 +5. 查询 软件一班 有几门课程。 +6. 查询 刘正(学生编号为1) 的总分。 +7. 查询所有学生 数据库高级应用 的平均分。 +8. 查询 所有学生 的总分。 +9. 查询 所有学生 的平均分。 +10. 查询 所有学生 的平均分,并且按照平均分从高到低排列。 +11. 查询 所有学生中 平均分 大于80分的学生。(聚合查询 + 分组 + having)*/ + +select * from Student where StudentBirth >= '2000-01-01' and StudentBirth < '2001-01-01'; +select * from Student where studentadress like '%桂林市%'; +select * from Student where StudentName like '%欧阳%'; +select * from Student where StudentName like '李__'; +select count(0) from Student where ClassId = 1; +select count(0) from COURSECLASS where ClassId = 1; +select sum(score) from Score where StudentId = 1; +select * from Score where CourseId = 1; +select sum(score) as 总分,count(0) as 学生总数 from Score where CourseId = 1; +select avg(score) from Score where CourseId = 1; +select * from Score; +select StudentId, sum(Score) as TotalScore from Score group by StudentId; +select * from Score; +select StudentId, avg(Score) as TotalScore from Score group by StudentId; +select * from Score; +select StudentId, avg(Score) as AvgScore from Score group by StudentId order by AvgScore desc; + +select * from Score; +select StudentId, avg(Score) as AvgScore from Score group by StudentId having avg(Score) > 80 ; +--1. 查询 李逍遥(编号id为9) 所在的班级名称(连接查询 2表) +/*2. 查询 李逍遥(学生编号id为9) 学习的课程有哪几门,需要姓名、课程名称、课程学分(连接查询) +3. 查询 李逍遥(学生编号id为9) 学习的课程考试得分,需要姓名、课程名称、课程学分、得分(连接查询) +4. 使用子查询查询 软件一班的每个学生 的平均分(聚合查询 + 子查询 + 分组) +5. 使用连接查询 软件二班的每个学生 的平均分(聚合查询 + 连接查询 + 分组) +6. 按照班级查询所有课程的平均分,并且按照平均分高低进行排序。(聚合查询 + 连接查询 + 分组)*/ +select * from CLASS inner join STUDENT on CLASS.CLASSID=STUDENT.classid where STUDENT.studentid=9; +select studentname,coursename ,coursecredit from STUDENT join COURSECLASS on COURSECLASS.classid=STUDENT.classid + inner join COURSE on COURSE.Courseid=COURSECLASS.courseid where STUDENT.studentid=9 ; + + + select studentname,coursename ,coursecredit ,score from STUDENT join COURSECLASS on COURSECLASS.classid=STUDENT.classid + inner join COURSE on COURSE.Courseid=COURSECLASS.courseid + join SCORE on SCORE.courseid=COURSECLASS.courseid where STUDENT.studentid=9 ; + + + select StudentId, avg(Score) as TotalScore from Score join COURSECLASS on SCORE.courseid=COURSECLASS.courseid + join CLASS on CLASS.CLASSID=COURSECLASS.classid where CLASS.CLASSID=1 + group by StudentId; + + + select StudentId, avg(Score) as TotalScore from Score join COURSECLASS on SCORE.courseid=COURSECLASS.courseid + join CLASS on CLASS.CLASSID=COURSECLASS.classid where CLASS.CLASSID=2 + group by StudentId; + + select CLASS.CLASSID, avg(Score) as TotalScore from Score join COURSECLASS on SCORE.courseid=COURSECLASS.courseid + join CLASS on CLASS.CLASSID=COURSECLASS.classid + group by CLASS.CLASSID; + + diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..4eefaf9c639babcb75693b2ef8f2665febf54cc8 --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" @@ -0,0 +1,90 @@ +create database bqm +use bqm +create table stuinfo( +stuid int primary key identity, +stuname varchar(10), +stuage tinyint, +stusex tinyint, +tine datetime +) + +insert into stuinfo(stuname,stuage,stusex,tine) +values('Tom',19,1,null) +insert into stuinfo(stuname,stuage,stusex,tine) +values('Jack',20,0,null), + ('Rose',21,1,null), + ('Rulu',19,1,null), + ('Lili',21,0,null) + + +create table courseinfo( +courseid int primary key identity, +coursename nvarchar(20), +coursemarks tinyint +) + +insert into courseinfo(coursename,coursemarks) +values('Javabase',4), + ('Html',2), + ('Javascript',2), + ('Sqlbase',2) + +create table scoreinfo( +scoreid int primary key identity, +stuid tinyint, +courseid tinyint, +score tinyint +) + +insert into scoreinfo(stuid,courseid,score) +values(1,1,80), + (1,2,85), + (1,4,50), + (2,1,75), + (2,3,45), + (2,4,75), + (3,1,45), + (4,1,95), + (4,2,75), + (4,3,90), + (4,4,45) + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuid, count(0)数量,avg(score)平均分 from scoreinfo +group by stuid +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseid 课程名称,count(stuid)学生个数,sum(score) 总分 from scoreinfo +group by courseid + +--3.查询出性别一样并且年龄一样的学生的信息 +select * from stuinfo +select one.* from stuinfo one +inner join stuinfo two +on one.stuage=two.stuage and one.stusex=two.stusex +where one.stuid=two.stuid + +--4.查询出学分一样的课程信息 +select distinct three.* from courseinfo three +inner join courseinfo four +on three.courseid!=four.courseid and three.coursemarks=four.coursemarks + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuinfo.stuid 学号,stuname 姓名,courseid 课程号,score 分数 from stuinfo +join scoreinfo on stuinfo.stuid=scoreinfo.stuid + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuid 学号,scoreinfo.courseid 课程号,coursename 课程名,score 分数 from scoreinfo +join courseinfo on scoreinfo.courseid=courseinfo.courseid + +--7.查询出没有参加考试的学生的学号和姓名 +select stuinfo.stuid 学号,stuname 姓名 from stuinfo +join scoreinfo on stuinfo.stuid=scoreinfo.stuid +where score is null +--8.查询出是周六周天来报到的学生 +select * from stuinfo +--9.查询出姓名中有字母a的学生的信息 +select * from stuinfo where stuname like '%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuid 学号,avg(score)平均分,courseid 课程数量 from scoreinfo +where courseid>2 and score>70 +group by stuid,score,courseid \ No newline at end of file diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\357\274\214\344\275\234\344\270\2322.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\357\274\214\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000000000000000000000000000000000000..2d977d0854dbf4cc42478449dd1db6f28f85a4f2 --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\344\272\214\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\357\274\214\344\275\234\344\270\2322.sql" @@ -0,0 +1,89 @@ +create database bgm +use bgm +create table tbl_card( +ID varchar(10) primary key , +PassWord char(50), +Balance int, +Username varchar(10) +) + +/*insert into tbl_card(ID,PassWord,Balance,Username) +values('0023_ABC','555',98,'张军'), + ('0025_bbd','abe',300,'朱俊'), + ('0036_CCD','何柳',100,'何柳'), + ('0045_YGR','0045_YGR',58,'证验'), + ('0078_RJV','55885fj',600,'校庆'), + ('0089_EDE','zhang',134,'张峻')*/ + +create table tbl_computer( +id int primary key, +onuse tinyint, +note tinyint +) + +create table tbl_record( +id int primary key identity, +cardid nvarchar(10), +computerid nvarchar(10), +begintime datetime, +endtime datetime, +fee int + +) + + + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额, +--并按消费金额降序排列 +select tbl_card.ID 卡号,Username 用户名,tbl_computer.id 机器编号,begintime 开始时间,endtime 结束时间,fee 消费金额 from tbl_card +join tbl_computer on tbl_card.ID=tbl_computer.id +join tbl_record on tbl_card.id=tbl_record.id +group by tbl_card.ID ,Username,tbl_computer.id ,begintime ,endtime ,fee +order by tbl_record.fee desc + +--2. 查询出每台机器上的上网次数和消费的总金额 +select sum(fee)总金额,count(onuse)上网次数 from tbl_record +join tbl_computer on tbl_computer.id=tbl_record.computerid +group by fee,onuse + +--3. 查询出所有已经使用过的上网卡的消费总金额 +select sum(fee)消费总金额 from tbl_record + +--4. 查询出从未消费过的上网卡的卡号和用户名 +select tbl_record.id,username from tbl_card +join tbl_record on tbl_card.id=tbl_record.id +where username is null + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card +select one.* from tbl_card one +inner join tbl_card two +on one.ID!=two.ID and one.Username=two.Username +where one.id=two.id + +--6. 查询出使用次数最多的机器号和使用次数 +select max(id),count(onuse)使用次数 from tbl_computer where onuse=1 +group by id,onuse +order by onuse + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select tbl_card.id,username,computerid,fee from tbl_card +join tbl_record on tbl_card.id=tbl_record.id +where tbl_card.id like '%ABC' +group by tbl_card.id,username,computerid,fee +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select datediff(weekday,1,getdate())记录,tbl_record.id,username,computerid,begintime,endtime,fee from tbl_record +join tbl_card on tbl_record.id=tbl_card.id +group by tbl_record.id,username,computerid,begintime,endtime,fee + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select tbl_record.id,username,computerid,begintime,endtime,fee from tbl_record +join tbl_card on tbl_record.id=tbl_card.id +where begintime+endtime>12 +group by tbl_record.id,username,computerid,begintime,endtime,fee + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 tbl_record.id,username,computerid,begintime,endtime,fee from tbl_record +join tbl_card on tbl_record.id=tbl_card.id +group by tbl_record.id,username,computerid,begintime,endtime,fee +order by id \ No newline at end of file diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.sql" new file mode 100644 index 0000000000000000000000000000000000000000..f4ee9bca626f515bd05425293bd5b6ff8bd9f036 --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\270\200.sql" @@ -0,0 +1,111 @@ +create database student6 +go +use student6 + +create table student ( +stuno nvarchar(10) primary key, +stuname nvarchar(20) not null, +stuage int not null, +stuaddress nvarchar(20) not null, +stuseat int identity, +stusex nvarchar(1) not null +); + +insert into student(stuno, stuname, stuage, stuaddress, stusex) +values('s2501','张秋利',20,'美国硅谷',1) +insert into student(stuno, stuname, stuage, stuaddress, stusex) +values('s2502','李斯文',18,'湖北武汉',0), +('s2503','马文才',22,'湖南长沙',1), +('s2504','欧阳俊雄',21,'湖北武汉',0), +('s2505','梅超风',20,'湖北武汉',1), +('s2506','陈旋风',19,'美国硅谷',1), +('s2507','陈风',20,'美国硅谷',0) + +create table exam( +examno int primary key identity, +stuno nvarchar(10) references student (stuno), +writtenexam int not null, +labexam int not null +); + +insert into exam(stuno,writtenexam,labexam) +values('s2501',50,70), +('s2502',60,65), +('s2503',86,85), +('s2504',40,80), +('s2505',70,90), +('s2506',85,90) + +select * from exam +select * from student + +select stuno as 学生编号, stuname as 学生名, stuage as 学生年龄, stuaddress as 学生地址, stuseat as 学生座位, stusex as 性别 from student +select stuname,stuage,stuaddress from student + +select stuno 学号, writtenexam 笔试, labexam 机试 from exam +select stuno as 学号, writtenexam as 笔试, labexam as 机试 from exam +select 学号= stuno , 笔试= writtenexam,机试= labexam from exam + +select * ,stuname+'@'+stuaddress as 邮箱 from student +select stuno, writtenexam, labexam ,writtenexam+labexam as 总分 from exam + +select distinct stuaddress from student +select distinct stuage as 年龄 from student +select top 3 * from student +select top 4 stuname,stuseat from student +select top 50 percent * from student +select * from student where stuaddress='湖北武汉'and stuage=20 +select * from exam where labexam>60 and labexam<80 order by labexam desc + + +select * from student where stuaddress='湖北武汉'or stuaddress='湖南长沙' +select * from student where not(stuaddress='美国硅谷') + +select * from exam where writtenexam<70 or labexam>90 order by writtenexam asc + +select * from student where stuage=' ' +select * from student where not(stuage=' ') + +----eg:查询学生的成绩信息:学号,姓名、课程名称和成绩 + +--select ClassId,StuInfo.StuId 学号,StuName 姓名,CourseName 课程名称 ,Score 成绩 +--from StuInfo +--join Scores on StuInfo.StuId = Scores.StuId +--join CourseInfo on CourseInfo.CourseId = Scores.CourseId + + + + +--查询学生的姓名,年龄,笔试成绩和机试成绩 +select student.stuname 姓名,stuage 年龄,writtenexam 笔试,labexam 机试 from student +join exam on student.stuno=exam.stuno + +--查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select student.stuname 姓名,stuage 年龄,writtenexam 笔试,labexam 机试 from student +join exam on student.stuno=exam.stuno +where writtenexam>60 and labexam>60 + +--查询所有学生的学号,姓名,笔试成绩,机试成绩,没有参加考试的学生的成绩以NULL值填充 +select student.stuname 姓名,stuage 年龄,writtenexam 笔试,labexam 机试 from student +left join exam on student.stuno=exam.stuno +order by exam.writtenexam,exam.labexam desc + +--查询年龄在20以上(包括20)的学生的姓名,年龄,笔试成绩和机试成绩,并按笔试成绩降序排列 +select student.stuname 姓名,stuage 年龄,writtenexam 笔试,labexam 机试 from student +join exam on student.stuno=exam.stuno +where stuage>=20 +order by exam.writtenexam desc + +--查询男女生的机试平均分 +select stusex,avg(labexam) from student +inner join exam on student.stuno=exam.stuno +group by stusex + +--查询男女生的笔试总分 +select stusex,sum(writtenexam) from student +inner join exam on student.stuno=exam.stuno +group by stusex + +--飞机 + +--三表查询 diff --git "a/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..81b5adacb30a802d0ac1d62f913d05e3f55e429c --- /dev/null +++ "b/15\351\231\210\346\231\223\345\275\244/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" @@ -0,0 +1,46 @@ +create database text; + +use text; + +--班级信息表 +create table Class( + ClassId int primary key identity(1,1),--班级编号,主键,自增 + ClassName nvarchar(50) not null unique,--班级名称,不允许为空,唯一约束 + ); + +--学生信息表 +create table Student( + StudentId int primary key identity(1,1),--班级编号,主键,自增 + StudentName nvarchar(50) not null,--学生姓名,不允许为空 + StudentSex tinyint not null default 3 check(StudentSex=1 or StudentSex=2 or StudentSex=3),--学生性别,不允许为空,默认值为3,check约束 + StudentBirth date, --学生生日 + StudntAddress nvarchar(255) not null,--学生地址,不允许为空 + ClassId int not null default 0 , --所属班级ID,不允许为空,默认值0 + foreign key(ClassId) references Class(ClassId)--外键 +); + +--课程信息表 +create table Course( + CourseId int primary key identity(1,1), --课程编号,自增,主键 + CourseName nvarchar(50) not null unique,--课程名称,不允许为空,唯一约束 + CouseCredit tinyint not null default 0 check(CouseCredit>0)--课程学分,不允许为空,默认值为0 + ); + +--班级课程表 +create table ClassCourse( + ClassCouseId int identity(1,1),--自增编号,主键,自增 + ClassId int not null ,--班级编号,不允许为空 + CourseId int primary key not null, --课程编号,不允许为空 + foreign key(CourseId) references Course(CourseId) --外键 + ); + +--分数信息表 +create table Score( + ScoreId int primary key identity(1,1),--自增编号,主键,自增 + StudentId int not null, --学生编号,不允许为空 + foreign key(StudentId) references Student(StudentId),--外键 + CourseId int not null,--课程编号,不允许为空 + foreign key(CourseId) references ClassCourse(CourseId),--外键 + Score int not null check(Score>=0) --分数,不允许为空,check约束 + ); + diff --git "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243 (2).txt" "b/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243 (2).txt" index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a2b53d272eac08524d6e052692ed7bb1071d4753 100644 --- "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243 (2).txt" +++ "b/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243 (2).txt" @@ -0,0 +1 @@ +dfgfdgd \ No newline at end of file diff --git "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..4a5d6aa8c021a6ece3158a8eb4cb801aaf6363cd 100644 --- "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" +++ "b/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" @@ -0,0 +1 @@ +dfgdfgdf \ No newline at end of file