diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\344\270\212\344\274\240\345\210\206\346\224\257.jpg" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\344\270\212\344\274\240\345\210\206\346\224\257.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..78dbeded6c7e98c6de189b13e5a8842a34a5c2ff Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\344\270\212\344\274\240\345\210\206\346\224\257.jpg" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\345\205\213\351\232\206.jpg" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\345\205\213\351\232\206.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..86e79c3ee920a700e24a5602dcd12a390b41a0bb Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\345\205\213\351\232\206.jpg" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\346\267\273\345\212\240\346\232\202\347\274\223.jpg" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\346\267\273\345\212\240\346\232\202\347\274\223.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..0c4b079f1307dedce1e6b602c31ea8314560af5a Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Git\345\237\272\346\234\254\345\221\275\344\273\244/\346\267\273\345\212\240\346\232\202\347\274\223.jpg" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/SQL sever\345\256\211\350\243\205/SQL\344\270\213\350\275\275\346\210\252\345\233\276.jpg" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/SQL sever\345\256\211\350\243\205/SQL\344\270\213\350\275\275\346\210\252\345\233\276.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..cd78e72cbd3206b11e0db497ab49f16d4185779f Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/SQL sever\345\256\211\350\243\205/SQL\344\270\213\350\275\275\346\210\252\345\233\276.jpg" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/SQL sever\345\256\211\350\243\205/SQL\344\270\213\350\275\275\346\210\252\345\233\2762.jpg" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/SQL sever\345\256\211\350\243\205/SQL\344\270\213\350\275\275\346\210\252\345\233\2762.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..224842850372df00641daf3ecf8b0e52a61d4754 Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/SQL sever\345\256\211\350\243\205/SQL\344\270\213\350\275\275\346\210\252\345\233\2762.jpg" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\347\254\254\345\233\233\347\253\240\344\275\234\344\270\2321\346\234\200\347\273\210.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\347\254\254\345\233\233\347\253\240\344\275\234\344\270\2321\346\234\200\347\273\210.sql" new file mode 100644 index 0000000000000000000000000000000000000000..d1dc700e8c538fdadce7cd57ed08953aba4afdc3 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\347\254\254\345\233\233\347\253\240\344\275\234\344\270\2321\346\234\200\347\273\210.sql" @@ -0,0 +1,86 @@ +create database IU; +go +use IU; +create table stuinfo( +stuNO nvarchar(10) unique, +stuName nvarchar(10), +stuAge int, +stuAddress nvarchar(10), +stuSeat int, +stuSex tinyint, +); +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); +create table stuexam( +examNO int identity, +stuNO nvarchar(10), +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); +--查询学生信息表(stuinfo)中所有列信息,给每列取上中文名称 +select stuNO as 学号,stuName as 名字,stuAge as 年龄,stuAddress as 地址,stuSeat as 座号,stuSex as 性别 from stuinfo; +--查询学生信息表(stuinfo)中的姓名,年龄和地址三列的信息 +select stuName as 名字,stuAge as 年龄,stuAddress as 地址 from stuinfo; +--查询学生分数表(stuexam)中的学号,笔试和机试三列的信息,并为这三列取中文名字-注意:要用三种方法 +select stuNO as 学号,writtenExam as 笔试,labExam as 机试 from stuexam; +select stuNO 学号,writtenExam 笔试,labExam 机试 from stuexam; +select 学号=stuNO,笔试=writtenExam,机试=labExam from stuexam; +--查询学生信息表(stuInfo)中的学号,姓名,地址,以及将:姓名+@+地址 组成新列 “邮箱” +select stuNO as 学号,stuName as 名字,stuAddress as 地址,cast(stuName+'@'+stuAddress as varchar(40)) as 邮箱 from stuinfo; +--查询学生分数表(stuexam)中的学生的学号,笔试,机试以及总分这四列的信息 +select stuNO as 学号,writtenExam as 笔试,labExam as 机试,cast(writtenExam+labExam as int)as 总分 from stuexam; +--查询学生信息表(stuInfo)中学生来自哪几个地方 +select distinct stuAddress from stuinfo; +--查询学生信息表(stuInfo)中学生有哪几种年龄,并为该列取对应的中文列名 +select distinct stuage as 哪几种年龄 from stuinfo; +--查询学生信息表(stuInfo)中前3行记录 +select top 3 * from stuinfo; +--查询学生信息表(stuInfo)中前4个学生的姓名和座位号 +select top 4 stuName as 姓名,stuseat as 座号 from stuinfo; +--查询学生信息表(stuInfo)中一半学生的信息 +select top 50percent * from stuinfo; +--将地址是湖北武汉,年龄是20的学生的所有信息查询出来 +select * from stuinfo where stuAddress='湖北武汉' and stuAge=20; +--将机试成绩在60-80之间的信息查询出来,并按照机试成绩降序排列(用两种方法实现) +select * from stuexam where labExam between 60 and 80 order by labExam desc; +select * from stuexam where labExam >= 60 and labExam<=80 order by labExam desc; +--查询来自湖北武汉或者湖南长沙的学生的所有信息(用两种方法实现) +select * from stuinfo where stuAddress='湖北武汉' or stuAddress='湖南长沙'; +select * from stuinfo where stuAddress in ('湖北武汉','湖南长沙'); +--查询出笔试成绩不在70-90之间的信息,并按照笔试成绩升序排列(用两种方法实现) +select * from stuexam where writtenExam<=70 or writtenExam>=90 order by writtenExam asc; +select * from stuexam where writtenExam not between 71 and 89 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 stuNo,examNO,writtenExam,labExam from stuexam where writtenExam in(select max(writtenExam) from stuexam); +select top 1 * from stuexam order by writtenExam desc; +--显示机试倒数第一名的学生的考试号,学号,笔试成绩和机试成绩 +select stuNo,examNO,writtenExam,labExam from stuexam where labExam in(select min(labExam) from stuexam) +select top 1 * from stuexam order by labExam asc; +--查询每个地方的学生的平均年龄 +select stuAddress, avg(stuAge) as 平均年龄 from stuinfo group by stuAddress; +--查询男女生的分别的年龄总和 +select stuSex,sum(stuAge) as 年龄总和 from stuinfo group by stuSex; +--查询每个地方的男女生的平均年龄和年龄的总和 +select stuAddress,stuSex,avg(stuAge) as 平均年龄,sum(stuAge) as 年龄总和 from stuinfo group by stuAddress,stuSex; \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\240\351\242\230\345\210\26013.jpg" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\240\351\242\230\345\210\26013.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..5b6677f0b43901f5ff757742b1aa3eda9717a555 Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\240\351\242\230\345\210\26013.jpg" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\240\351\242\230\345\210\26013.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\240\351\242\230\345\210\26013.sql" new file mode 100644 index 0000000000000000000000000000000000000000..20ae008465653c3747ed82a48eec820127d8cf7e --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\240\351\242\230\345\210\26013.sql" @@ -0,0 +1,68 @@ +create database name; + +use name; + +create table Class( +--班级编号 +Classld int identity primary key not null, +--班级名称 +ClassName nvarchar(50) not null unique, +); + +create table Student( +--学生编号 +Studentld int identity primary key not null, +--学生姓名 +StudentName nvarchar(50) not null, +--学生性别 +StudentSex tinyint default 3 not null +check(StudentSex=1 or StudentSex=2 or StudentSex=3), +--学生生日 +StudentBirth date , +--学生地址 +StudentAddress nvarchar(255) not null, +--所属班级id +Classld int not null, +--身份证 +StudentldentityCard varchar(20) not null default' ', +); + +create table Course( +--课程编号 +Courseld int identity primary key not null, +--课程名称 +CourseName nvarchar(50) not null unique, +--课程学分 +CourseCredit tinyint not null default 0 +check(CourseCredit>0), +); + +create table ClassCourse( +--自增编号 +ClassCourseld int identity primary key not null, +--班级编号 +Classld int not null default 0, +--课程编号 +Courseld int not null, +); + +create table Score( +--自增编号 +Scoreld int identity primary key not null, +--学生编号 +Studentld int not null, +--课程编号 +Courseld int not null, +--分数 +Score int not null check(Score>=0), +--是否补考(0:不是,1:是) +lsResit tinyint not null default 0, +); + + +--identity(自增) +--primary key(主键) +--not null(非空) +--default (默认值) +--check(只能输入) +--unique(唯一) \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321\357\274\210\350\277\236\350\241\250\346\237\245\350\257\242\357\274\211.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321\357\274\210\350\277\236\350\241\250\346\237\245\350\257\242\357\274\211.sql" new file mode 100644 index 0000000000000000000000000000000000000000..b97c26d170319950c57d6ca3f9c78a3c17893927 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2321\357\274\210\350\277\236\350\241\250\346\237\245\350\257\242\357\274\211.sql" @@ -0,0 +1,98 @@ +create database OO; +go +use OO; +create table stuinfo( +stuNO nvarchar(10) unique, +stuName nvarchar(10), +stuAge int, +stuAddress nvarchar(10), +stuSeat int, +stuSex tinyint, +); +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); +create table stuexam( +examNO int identity, +stuNO nvarchar(10), +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); +--查询学生信息表(stuinfo)中所有列信息,给每列取上中文名称 +select stuNO as 学号,stuName as 名字,stuAge as 年龄,stuAddress as 地址,stuSeat as 座号,stuSex as 性别 from stuinfo; +--查询学生信息表(stuinfo)中的姓名,年龄和地址三列的信息 +select stuName as 名字,stuAge as 年龄,stuAddress as 地址 from stuinfo; +--查询学生分数表(stuexam)中的学号,笔试和机试三列的信息,并为这三列取中文名字-注意:要用三种方法 +select stuNO as 学号,writtenExam as 笔试,labExam as 机试 from stuexam; +select stuNO 学号,writtenExam 笔试,labExam 机试 from stuexam; +select 学号=stuNO,笔试=writtenExam,机试=labExam from stuexam; +--查询学生信息表(stuInfo)中的学号,姓名,地址,以及将:姓名+@+地址 组成新列 “邮箱” +select stuNO as 学号,stuName as 名字,stuAddress as 地址,cast(stuName+'@'+stuAddress as varchar(40)) as 邮箱 from stuinfo; +--查询学生分数表(stuexam)中的学生的学号,笔试,机试以及总分这四列的信息 +select stuNO as 学号,writtenExam as 笔试,labExam as 机试,cast(writtenExam+labExam as int)as 总分 from stuexam; +--查询学生信息表(stuInfo)中学生来自哪几个地方 +select distinct stuAddress from stuinfo; +--查询学生信息表(stuInfo)中学生有哪几种年龄,并为该列取对应的中文列名 +select distinct stuage as 哪几种年龄 from stuinfo; +--查询学生信息表(stuInfo)中前3行记录 +select top 3 * from stuinfo; +--查询学生信息表(stuInfo)中前4个学生的姓名和座位号 +select top 4 stuName as 姓名,stuseat as 座号 from stuinfo; +--查询学生信息表(stuInfo)中一半学生的信息 +select top 50percent * from stuinfo; +--将地址是湖北武汉,年龄是20的学生的所有信息查询出来 +select * from stuinfo where stuAddress='湖北武汉' and stuAge=20; +--将机试成绩在60-80之间的信息查询出来,并按照机试成绩降序排列(用两种方法实现) +select * from stuexam where labExam between 60 and 80 order by labExam desc; +select * from stuexam where labExam >= 60 and labExam<=80 order by labExam desc; +--查询来自湖北武汉或者湖南长沙的学生的所有信息(用两种方法实现) +select * from stuinfo where stuAddress='湖北武汉' or stuAddress='湖南长沙'; +select * from stuinfo where stuAddress in ('湖北武汉','湖南长沙'); +--查询出笔试成绩不在70-90之间的信息,并按照笔试成绩升序排列(用两种方法实现) +select * from stuexam where writtenExam<=70 or writtenExam>=90 order by writtenExam asc; +select * from stuexam where writtenExam not between 71 and 89 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 stuNo,examNO,writtenExam,labExam from stuexam where writtenExam in(select max(writtenExam) from stuexam); +select top 1 * from stuexam order by writtenExam desc; +--显示机试倒数第一名的学生的考试号,学号,笔试成绩和机试成绩 +select stuNo,examNO,writtenExam,labExam from stuexam where labExam in(select min(labExam) from stuexam) +select top 1 * from stuexam order by labExam asc; +--查询每个地方的学生的平均年龄 +select stuAddress, avg(stuAge) as 平均年龄 from stuinfo group by stuAddress; +--查询男女生的分别的年龄总和 +select stuSex,sum(stuAge) as 年龄总和 from stuinfo group by stuSex; +--查询每个地方的男女生的平均年龄和年龄的总和 +select stuAddress,stuSex,avg(stuAge) as 平均年龄,sum(stuAge) as 年龄总和 from stuinfo group by stuAddress,stuSex; +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName,StuAge,writtenExam,labExam from stuinfo join stuexam on stuinfo.stuNO=stuexam.stuNO; +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuinfo.stuNO,stuName,writtenExam,labExam from stuinfo join stuexam on stuinfo.stuNO=stuexam.stuNO where writtenExam>60 and 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 labExam desc +--5.查询男女生的机试平均分 +select stuSex 性别,avg(labExam) 平均分 from stuinfo join stuexam on stuinfo.stuNO=stuexam.stuNO group by stuSex; +--6.查询男女生的笔试总分 +select stuSex 性别,sum(labExam)总分 from stuinfo join stuexam on stuinfo.stuNO=stuexam.stuNO group by stuSex; \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322\357\274\210\350\277\236\350\241\250\346\237\245\350\257\242\357\274\211.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322\357\274\210\350\277\236\350\241\250\346\237\245\350\257\242\357\274\211.sql" new file mode 100644 index 0000000000000000000000000000000000000000..1bf084b613e27c304f9bdc210d8d28a393d1b5bc --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322\357\274\210\350\277\236\350\241\250\346\237\245\350\257\242\357\274\211.sql" @@ -0,0 +1,72 @@ +create database SS +go +use SS +go +create table orders( +orderId int primary key identity, +orderDate datetime +); +create table orderItem( +itemId int, +orderid int references orders(orderId), +itemType nvarchar(10), +itemName nvarchar(10), +theNumber int check(theNumber>0), +themoney money check(themoney>0) +); +insert into orders(orderDate) +values +(2008-01-12), +(2008-02-10), +(2008-02-15), +(2008-03-10); +insert into orderItem(itemId,orderid,itemType,itemName,theNumber,themoney) +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); +--1.查询所有订单订购的所有物品数量总和 +select sum(theNumber) as 数量总和 from orderItem +--2.查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select orderId, sum(theNumber)as 物品数量,avg(theMoney) as 平均单价 from orderItem +where orderid<3 +group by orderid +having avg(theMoney)<10; +--3.查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select orderId ,sum(theNumber) as 物品数量,avg(theMoney)as 平均单价 from orderItem +group by orderId +having avg(themoney)<10 and sum(theNumber)>10; +--4.查询每种类别的产品分别订购了几次 +select itemType,count(itemType) as 订购次数 from orderItem group by itemType; +--5.查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select itemType,sum(theNumber),avg(theMoney) from orderItem group by itemType +having sum(theNumber)>100; +--6.查询每种产品的订购次数,订购总数量和订购的平均单价 +select itemName,count(itemName) as 订购次数 ,sum(theNumber) as 订购总数,avg(theMoney) as 平均单价 from orderItem group by itemName; +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 +select orders.orderId,orderDate,itemType,itemName,theNumber,theMoney from orders join orderItem on orders.orderId=orderItem.orderid +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderId,orderDate,itemType,itemName from orders join orderItem on orders.orderId=orderItem.orderid where theNumber>50; +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderId,orderDate,itemType,itemName,theNumber,theMoney,sum(theNumber*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(theNumber*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.查询每个订单分别订购了几个产品 +select orderId 编号,count(itemName)订购了产品数 from orderItem group by orderId +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量 +select orderId 订单编号,itemType 产品类别,count(itemName)订购次数,sum(theNumber) 总数量 from orderItem group by orderId,itemType \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\345\221\250\346\234\253\344\275\234\344\270\232\357\274\210\344\275\234\344\270\232\345\233\233\357\274\211.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\345\221\250\346\234\253\344\275\234\344\270\232\357\274\210\344\275\234\344\270\232\345\233\233\357\274\211.sql" new file mode 100644 index 0000000000000000000000000000000000000000..f33104e37e65779f691dfde118684274930439ec --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\345\221\250\346\234\253\344\275\234\344\270\232\357\274\210\344\275\234\344\270\232\345\233\233\357\274\211.sql" @@ -0,0 +1,123 @@ +create database zuoye9; +go +use zuoye9; +go +--班级信息表Class +create table Class( +ClassId int identity primary key not null, +ClassName nvarchar(50) not null unique,); +insert into Class (ClassName) +values ('软件一班'); +insert into Class (ClassName) +values ('软件二班'); +insert into Class (ClassName) +values ('计算机应用技术班'); + + + +--学生信息表Student +create table Student( +StudentId int identity not null primary key, +StudentName nvarchar(50) not null, +StudentSex tinyint not null default 3 check(StudentSex=1 or StudentSex=2 or StudentSex=3), +StudentBirth date, +StudentAddress nvarchar(255) not null, +ClassId int not null default 0 , +StudenttityCard varchar(20) not null default'',); +insert into Student(StudentName,StudentSex,StudentBirth,StudentAddress,ClassId) +values ('刘正','1','2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), + + ('黄贵','1','2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), + + ('陈美','2','2000-07-08','福建省龙岩市新罗区曹溪街道万达小区',1); +insert into Student(StudentName,StudentSex,StudentBirth,StudentAddress ,ClassId) +values ('江文','1','2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), + + ('钟琪','2','2001-03-21','湖南省长沙市雨花区红花坡社区',2); +insert into Student(StudentName,StudentSex,StudentBirth,StudentAddress ,ClassId) +values ('曾小林','1','1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), + + ('欧阳天天','2','2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), + + ('徐长卿','1','2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), + + ('李逍遥','1','1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3); + +insert into Student(StudentName,StudentSex,StudentBirth,StudentAddress ) +values('东方不败',3,'1999-12-11','河北省平定州西北四十余里的猩猩滩'), + ('令狐冲','1','2000-08-11','陕西省渭南市华阴市玉泉路南段'); + + +--课程信息表 Course +create table Course( +CourseId int identity not null primary key, +CourseName nvarchar(50) not null unique, +CourseCredit tinyint not null default 0 check(CourseCredit>0), +foreign key (CourseId) references Course (CourseId)); +insert into Course(CourseName,CourseCredit) +values ('数据库高级应用',3), +('javascript编程基础',3), +('web前端程序设计基础',4), +('动态网页设计.net基础',6), +('动态网页设计php基础',6); + + + + +--班级课程表ClassCourse +create table ClassCourse( +ClassCourseld int identity not null primary key, +ClassId int not null, +CourseId int not null, +foreign key (ClassId) references Class (ClassId), +); +insert into ClassCourse(ClassId, CourseId) +values(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(2,4),(3,1),(3,2),(3,3),(3,5); + + +--分数信息表Score +create table Score( +Scoreld int identity not null primary key, +StudentId int not null, +CourseId int not null, +Score int not null check(Score>=0), +IsResit tinyint not null default 0, +foreign key (StudentId) references Student(StudentId), +foreign key (CourseId) references Course(CourseId)); + +insert into Score(StudentId, CourseId, Score) +values(1,1,80),(1,2,78),(1,3,65),(1,4,90),(2,1,60),(2,2,77),(2,3,68),(2,4,88),(3,1,88), +(3,2,45),(3,3,66),(3,4,75),(4,1,56),(4,2,80),(4,3,75),(4,4,66),(5,1,88),(5,2,79),(5,3,72), +(5,4,85),(6,1,68),(6,2,88),(6,3,73),(6,5,63),(7,1,84),(7,2,90),(7,3,92),(7,5,78),(8,1,58), +(8,2,59),(8,3,65),(8,5,75),(9,1,48),(9,2,67),(9,3,71),(9,4,56),(9,1,48); +select*from Class +select*from ClassCourse +select*from Course +select*from Score +select*from Student + + + +--在第4章80练习题的基础上完成连接查询: +--1. 查询 李逍遥(编号id为9) 所在的班级名称(连接查询 2表) +select StudentName,ClassName from Class join Student on Class.ClassId=Student.ClassId where studentId=9; +--2. 查询 李逍遥(学生编号id为9) 学习的课程有哪几门,需要姓名、课程名称、课程学分(连接查询) +select StudentName 姓名, Course.CourseName 课程名称, CourseCredit 课程学分 from Student inner join ClassCourse on Student.ClassId=ClassCourse.ClassId +inner join Course on ClassCourse.CourseId=Course.CourseId +where StudentId=9 +--3. 查询 李逍遥(学生编号id为9) 学习的课程考试得分,需要姓名、课程名称、课程学分、得分(连接查询) +select StudentName 姓名, Course.CourseName 课程名称, CourseCredit 课程学分,Score 得分 from Student inner join ClassCourse on Student.ClassId=ClassCourse.ClassId +inner join Course on ClassCourse.CourseId=Course.CourseId +inner join Score on Course.CourseId=Score.CourseId +where Student.StudentId=9 +--4. 使用子查询查询 软件一班的每个学生 的平均分(聚合查询 + 子查询 + 分组) +select StudentName 姓名, avg(Score) 平均分 from Student inner join Score on Student.StudentId=Score.StudentId +where ClassId in(select ClassId from Class where ClassName='软件一班') +group by StudentName +--5. 使用连接查询 软件二班的每个学生 的平均分(聚合查询 + 连接查询 + 分组) +select StudentName 姓名, avg(Score) 平均分 from Student inner join Score on Student.StudentId=Score.StudentId where ClassId in(select ClassId from Class where ClassName='软件一班') +group by StudentName +--6. 按照班级查询所有课程的平均分,并且按照平均分高低进行排序。(聚合查询 + 连接查询 + 分组) +select ClassName 班级, avg(Score) 所有课程的平均分 from ClassCourse inner join Score on ClassCourse.CourseId=Score.CourseId +inner join Class on Class.ClassId=ClassCourse.ClassId +group by ClassName order by avg(Score) desc \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\274\226\350\276\221\350\241\250.jpg" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\274\226\350\276\221\350\241\250.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..16d1d9a6a18d9659d5bf95555432694da1d18465 Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\274\226\350\276\221\350\241\250.jpg" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\350\256\276\350\256\241\350\241\250.jpg" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\350\256\276\350\256\241\350\241\250.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..36e23d07b0042dc8378c97a0aa8d6ea7d40596a6 Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\350\256\276\350\256\241\350\241\250.jpg" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230.sql" new file mode 100644 index 0000000000000000000000000000000000000000..9a43b5ce90e43cf4fd5da26f7fee29dff6c5d246 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230.sql" @@ -0,0 +1,146 @@ +-------------------- +-- 建库部分 +-------------------- +-- 创建学生管理系统数据库,名称为Student +use master; +go +-- 检测原库是否存在,如果存在则删除 +if exists (select * from sys.databases where name = 'Student') + drop database Student; +go +-- 创建一个库 +create database Student; +go +-- 使用这个库 +use Student; +go + + +-------------------- +-- 建表部分 +-------------------- +-- 创建班级表,存储班级信息,其中字段包含:班级id、班级名称 +create table Class( + ClassId int not null identity(1,1), + ClassName nvarchar(50) not null +); +go + +-- 创建学生表,存储学生信息,其中字段保护:学生id、姓名、性别、生日、家庭住址,所属班级id +create table Student ( + StudentId int not null identity(1, 1), + StudentName nvarchar(50), + StudentSex tinyint not null, + StudentBirth date, + StudentAddress nvarchar(255) not null +); +go + +-- 创建课程表,存储课程信息,其中字段包含:课程id、课程名称、课程学分 +create table Course( + CourseId int identity(1,1), + CourseName nvarchar(50), + CourseCredit int +); +go + +-- 创建班级课程表,存储班级课程信息,其中字段包含:自增id、班级id、课程id +create table ClassCourse( + ClassCourseId int identity(1,1), + ClassId int, + CourseId int +); +go + +-- 创建分数表,存储学生每个课程分数信息,其中字段包含:分数id、学生id、课程id、分数 +create table Score( + ScoreId int identity(1,1), + StudentId int, + CourseId int, + Score int +); +go + + +-- 学生表建好了,细想一下少了一个所属班级的字段 +-- 给学生表 Student 增加一个所属班级id字段 +alter table Student add ClassId int not null; +go + +---------------------------------------- +-- 创建约束部分,使用alter进行修改 +---------------------------------------- +-- 班级表 ClassId 字段需要设置为主键(主键约束) +alter table Class add constraint PK_Class_ClassId primary key (ClassId); +-- 学生表 StudentId 字段需要设置为主键(主键约束) +alter table Student add constraint PK_Student_StudentId primary key (StudentId); +-- 课程表 CourseId 字段需要设置为主键(主键约束) +alter table Course add constraint PK_Course_CourseId primary key (CourseId); +-- 班级课程表 ClassCourseId 字段需要设置为主键(主键约束) +alter table ClassCourse add constraint PK_ClassCourse_ClassCourseId primary key (ClassCourseId); +-- 分数表 ScoreId 字段需要设置为主键(主键约束) +alter table Score add constraint PK_Score_ScoreId primary key (ScoreId); + +-- 学生表 StudentName 不允许为空(非空约束) +alter table Student alter column StudentName nvarchar(50) not null; + +-- 班级表 ClassName 需要唯一(唯一约束) +alter table Class add constraint UQ_Class_ClassName unique(ClassName); +-- 课程表 CourseName 需要唯一(唯一约束) +alter table Course add constraint UQ_Course_CourseName unique(CourseName); + +-- 学生表 ClassId 增加默认值为0(默认值约束) +alter table Student add constraint DF_Student_ClassId default(0) for ClassId; + +-- 学生表 StudentSex 只能为1或者2(Check约束) +alter table Student add constraint CK_Student_StudentSex check(StudentSex=1 or StudentSex=2 or StudentSex=3); +-- 分数表 Score 字段只能大于等于0(check约束) +alter table Score add constraint CK_Score_Score check(Score>=0); +-- 课程表 CourseCredit 字段只能大于0(check约束) +alter table Course add constraint CK_Course_CourseCredit check(CourseCredit>=0); + +-- 班级课程表ClassId 对应是 班级表ClassId 的外键 (外键约束) +alter table ClassCourse add constraint FK_ClassCourse_ClassId foreign key (ClassId) references Class(ClassId); +-- 班级课程表CourseId 对应是 课程表CourseId 的外键 (外键约束) +alter table ClassCourse add constraint FK_ClassCourse_CourseId foreign key (CourseId) references Course(CourseId); +-- 分数表StudentId 对应是 学生表StudentId 的外键 (外键约束) +alter table Score add constraint FK_Score_StudentId foreign key (StudentId) references Student(StudentId); +-- 分数表CourseId 对应是 课程表CourseId 的外键 (外键约束) +alter table Score add constraint FK_Score_CourseId foreign key (CourseId) references Course(CourseId); + +--学校开设了3个班级:软件一班、软件二班、计算机应用技术班。请插入班级表相关数据 +insert into Class(ClassName) +values('软件一班'),('软件二班'),('计算机应用技术班') +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','1. - 福建省龙岩市新罗区曹溪街道万达小区',1) +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +('钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2) +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3) +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress) +values('东方不败',3,'1999-12-11','河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1,'2000-08-11','陕西省渭南市华阴市玉泉路南段'); +insert into Course(CourseName, CourseCredit) +values('数据库高级应用',3), +('javascript编程基础',3), +('web前端程序设计基础',4), +('动态网页设计.net基础',6), +('动态网页设计php基础',6); +insert into ClassCourse(ClassId, CourseId) +values(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(2,4),(3,1),(3,2),(3,3),(3,5); +insert into Score(StudentId, CourseId, Score) +values(1,1,80),(1,2,78),(1,3,65),(1,4,90),(2,1,60),(2,2,77),(2,3,68),(2,4,88),(3,1,88), +(3,2,45),(3,3,66),(3,4,75),(4,1,56),(4,2,80),(4,3,75),(4,4,66),(5,1,88),(5,2,79),(5,3,72), +(5,4,85),(6,1,68),(6,2,88),(6,3,73),(6,5,63),(7,1,84),(7,2,90),(7,3,92),(7,5,78),(8,1,58), +(8,2,59),(8,3,65),(8,5,75),(9,1,48),(9,2,67),(9,3,71),(9,4,56); +select*from Class +select*from ClassCourse +select*from Course +select*from Score +select*from Student \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/98 80.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/98 80.sql" new file mode 100644 index 0000000000000000000000000000000000000000..499b9ef08b21b7313f213031d3d5caf5bc428c73 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/98 80.sql" @@ -0,0 +1,86 @@ +create database SSSS +go +use SSSS +go +create table Class( +ClassId int identity not null primary key, +ClassName nvarchar(50) not null, +); +create table Student( +StudentId int identity not null primary key, +StudentName nvarchar(50) not null, +StudentSex tinyint not null default 3, +StudentBirth date, +StudentAddress nvarchar(255) not null, +ClassId int not null, +); +create table Course( +CourseId int identity not null primary key, +CourseName nvarchar(50) not null, +CourseCredit tinyint not null default 0, +); +create table ClassCourse( +ClassCourseId int identity not null primary key, +ClassId int not null, +CourseId int not null, +); +create table Score( +ScoreId int identity not null primary key, +StudentId int not null, +CourseId int not null, +Score int not null, +); +alter table Student add StudentIdentityCard varchar(20) not null default ''; +alter table Score add IsResit tinyint not null default 0; +alter table Class add constraint Class_ClassName unique(ClassName); +alter table Course add constraint Course_CourseName unique(CourseName); +alter table Student add constraint Student_ClassId default(0) for ClassId; +alter table Student add constraint Student_StudentSex check(StudentSex=1 or StudentSex=2 or StudentSex=3); +alter table Score add constraint Score_Score check(Score>=0); +alter table Course add constraint Course_CourseCredit check(CourseCredit>0); +alter table ClassCourse add constraint ClassCourse_ClassId foreign key(ClassId) references Class(ClassId); +alter table ClassCourse add constraint ClassCourse_CourseId foreign key (CourseId) references Course(CourseId); +alter table Score add constraint Score_StudentId foreign key (StudentId) references Student(StudentId); +alter table Score add constraint Score_CourseId foreign key (CourseId) references Course(CourseId); +--学校开设了3个班级:软件一班、软件二班、计算机应用技术班 +insert into Class(ClassName) +values('软件一班'),('软件二班'),('计算机应用技术班') +--软件一班有3个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','1. - 福建省龙岩市新罗区曹溪街道万达小区',1) +--软件二班有2个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +('钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2) +--计算机应用技术班有4个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3) +--有2个学生尚未分配班级,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress) +values('东方不败',3,'1999-12-11','河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1,'2000-08-11','陕西省渭南市华阴市玉泉路南段'); +--创建课程学分 +insert into Course(CourseName, CourseCredit) +values('数据库高级应用',3), +('javascript编程基础',3), +('web前端程序设计基础',4), +('动态网页设计.net基础',6), +('动态网页设计php基础',6); + +insert into ClassCourse(ClassId, CourseId) +values(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(2,4),(3,1),(3,2),(3,3),(3,5); +insert into Score(StudentId, CourseId, Score) +values(1,1,80),(1,2,78),(1,3,65),(1,4,90),(2,1,60),(2,2,77),(2,3,68),(2,4,88),(3,1,88), +(3,2,45),(3,3,66),(3,4,75),(4,1,56),(4,2,80),(4,3,75),(4,4,66),(5,1,88),(5,2,79),(5,3,72), +(5,4,85),(6,1,68),(6,2,88),(6,3,73),(6,5,63),(7,1,84),(7,2,90),(7,3,92),(7,5,78),(8,1,58), +(8,2,59),(8,3,65),(8,5,75),(9,1,48),(9,2,67),(9,3,71),(9,4,56); +select*from Class +select*from ClassCourse +select*from Course +select*from Score +select*from Student \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322.sql" new file mode 100644 index 0000000000000000000000000000000000000000..66329a6b259cc6e8e3115fb689db9b9d8962a786 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\2322.sql" @@ -0,0 +1,57 @@ +create database SS +go +use SS +go +create table orders( +orderId int primary key identity, +orderDate datetime +); +create table orderItem( +itemId int, +orderid int references orders(orderId), +itemType nvarchar(10), +itemName nvarchar(10), +theNumber int check(theNumber>0), +themoney money check(themoney>0) +); +insert into orders(orderDate) +values +(2008-01-12), +(2008-02-10), +(2008-02-15), +(2008-03-10); +insert into orderItem(itemId,orderid,itemType,itemName,theNumber,themoney) +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); +--1.查询所有订单订购的所有物品数量总和 +select sum(theNumber) as 数量总和 from orderItem +--2.查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select orderId, sum(theNumber)as 物品数量,avg(theMoney) as 平均单价 from orderItem +where orderid<3 +group by orderid +having avg(theMoney)<10; +--3.查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select orderId ,sum(theNumber) as 物品数量,avg(theMoney)as 平均单价 from orderItem +group by orderId +having avg(themoney)<10 and sum(theNumber)>10; +--4.查询每种类别的产品分别订购了几次 +select itemType,count(itemType) as 订购次数 from orderItem group by itemType; +--5.查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select itemType,sum(theNumber),avg(theMoney) from orderItem group by itemType +having sum(theNumber)>100; +--6.查询每种产品的订购次数,订购总数量和订购的平均单价 +select itemName,count(itemName) as 订购次数 ,sum(theNumber) as 订购总数,avg(theMoney) as 平均单价 from orderItem group by itemName; \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230(\345\210\240\346\224\271).sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230(\345\210\240\346\224\271).sql" new file mode 100644 index 0000000000000000000000000000000000000000..ccd75891f30f455438656d6510a37993d98a283d --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230(\345\210\240\346\224\271).sql" @@ -0,0 +1,93 @@ +create database SSSS +go +use SSSS +go +create table Class( +ClassId int identity not null primary key, +ClassName nvarchar(50) not null, +); +create table Student( +StudentId int identity not null primary key, +StudentName nvarchar(50) not null, +StudentSex tinyint not null default 3, +StudentBirth date, +StudentAddress nvarchar(255) not null, +ClassId int not null, +); +create table Course( +CourseId int identity not null primary key, +CourseName nvarchar(50) not null, +CourseCredit tinyint not null default 0, +); +create table ClassCourse( +ClassCourseId int identity not null primary key, +ClassId int not null, +CourseId int not null, +); +create table Score( +ScoreId int identity not null primary key, +StudentId int not null, +CourseId int not null, +Score int not null, +); +alter table Student add StudentIdentityCard varchar(20) not null default ''; +alter table Score add IsResit tinyint not null default 0; +alter table Class add constraint Class_ClassName unique(ClassName); +alter table Course add constraint Course_CourseName unique(CourseName); +alter table Student add constraint Student_ClassId default(0) for ClassId; +alter table Student add constraint Student_StudentSex check(StudentSex=1 or StudentSex=2 or StudentSex=3); +alter table Score add constraint Score_Score check(Score>=0); +alter table Course add constraint Course_CourseCredit check(CourseCredit>0); +alter table ClassCourse add constraint ClassCourse_ClassId foreign key(ClassId) references Class(ClassId); +alter table ClassCourse add constraint ClassCourse_CourseId foreign key (CourseId) references Course(CourseId); +alter table Score add constraint Score_StudentId foreign key (StudentId) references Student(StudentId); +alter table Score add constraint Score_CourseId foreign key (CourseId) references Course(CourseId); +--学校开设了3个班级:软件一班、软件二班、计算机应用技术班 +insert into Class(ClassName) +values('软件一班'),('软件二班'),('计算机应用技术班') +--软件一班有3个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','1. - 福建省龙岩市新罗区曹溪街道万达小区',1) +--软件二班有2个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +('钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2) +--计算机应用技术班有4个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3) +--有2个学生尚未分配班级,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress) +values('东方不败',3,'1999-12-11','河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1,'2000-08-11','陕西省渭南市华阴市玉泉路南段'); +--创建课程学分 +insert into Course(CourseName, CourseCredit) +values('数据库高级应用',3), +('javascript编程基础',3), +('web前端程序设计基础',4), +('动态网页设计.net基础',6), +('动态网页设计php基础',6); + +insert into ClassCourse(ClassId, CourseId) +values(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(2,4),(3,1),(3,2),(3,3),(3,5); +insert into Score(StudentId, CourseId, Score) +values(1,1,80),(1,2,78),(1,3,65),(1,4,90),(2,1,60),(2,2,77),(2,3,68),(2,4,88),(3,1,88), +(3,2,45),(3,3,66),(3,4,75),(4,1,56),(4,2,80),(4,3,75),(4,4,66),(5,1,88),(5,2,79),(5,3,72), +(5,4,85),(6,1,68),(6,2,88),(6,3,73),(6,5,63),(7,1,84),(7,2,90),(7,3,92),(7,5,78),(8,1,58), +(8,2,59),(8,3,65),(8,5,75),(9,1,48),(9,2,67),(9,3,71),(9,4,56),(9,1,48); + +update Student set StudentBirth='2000-04-06' where StudentId=7; +update Score set Score=61 where ScoreId=30; +update Student set StudentSex=2,ClassId=1 where StudentId=4; +update Student set ClassId=2 where StudentId=8; +update Student set ClassId=2 where StudentId=9; +update Course set CourseCredit=4 where CourseId=1; +update Course set CourseCredit=4 where CourseId=2; +update Course set CourseCredit=5 where CourseId=3; +update Course set CourseCredit=7 where CourseId=4; +update Course set CourseCredit=7 where CourseId=5; +delete from Score where ScoreId=37; \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230(\346\237\245\350\257\242).sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230(\346\237\245\350\257\242).sql" new file mode 100644 index 0000000000000000000000000000000000000000..042e83932cd797d9cd1b895d440c177f7cc63111 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/80\347\273\203\344\271\240\351\242\230(\346\237\245\350\257\242).sql" @@ -0,0 +1,138 @@ +create database SSSS +go +use SSSS +go +create table Class( +ClassId int identity not null primary key, +ClassName nvarchar(50) not null, +); +create table Student( +StudentId int identity not null primary key, +StudentName nvarchar(50) not null, +StudentSex tinyint not null default 3, +StudentBirth date, +StudentAddress nvarchar(255) not null, +ClassId int not null, +); +create table Course( +CourseId int identity not null primary key, +CourseName nvarchar(50) not null, +CourseCredit tinyint not null default 0, +); +create table ClassCourse( +ClassCourseId int identity not null primary key, +ClassId int not null, +CourseId int not null, +); +create table Score( +ScoreId int identity not null primary key, +StudentId int not null, +CourseId int not null, +Score int not null, +); +alter table Student add StudentIdentityCard varchar(20) not null default ''; +alter table Score add IsResit tinyint not null default 0; +alter table Class add constraint Class_ClassName unique(ClassName); +alter table Course add constraint Course_CourseName unique(CourseName); +alter table Student add constraint Student_ClassId default(0) for ClassId; +alter table Student add constraint Student_StudentSex check(StudentSex=1 or StudentSex=2 or StudentSex=3); +alter table Score add constraint Score_Score check(Score>=0); +alter table Course add constraint Course_CourseCredit check(CourseCredit>0); +alter table ClassCourse add constraint ClassCourse_ClassId foreign key(ClassId) references Class(ClassId); +alter table ClassCourse add constraint ClassCourse_CourseId foreign key (CourseId) references Course(CourseId); +alter table Score add constraint Score_StudentId foreign key (StudentId) references Student(StudentId); +alter table Score add constraint Score_CourseId foreign key (CourseId) references Course(CourseId); +--学校开设了3个班级:软件一班、软件二班、计算机应用技术班 +insert into Class(ClassName) +values('软件一班'),('软件二班'),('计算机应用技术班') +--软件一班有3个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('刘正',1,'2000-01-01','广西省桂林市七星区空明西路10号鸾东小区',1), +('黄贵',1,'2001-03-20','江西省南昌市青山湖区艾溪湖南路南150米广阳小区',1), +('陈美',2,'2000-07-08','1. - 福建省龙岩市新罗区曹溪街道万达小区',1) +--软件二班有2个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('江文',1,'2000-08-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',2), +('钟琪',2,'2001-03-21','湖南省长沙市雨花区红花坡社区',2) +--计算机应用技术班有4个同学,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress, ClassId) +values('曾小林',1,'1999-12-10','安徽省合肥市庐阳区四里河路与潜山路交汇处万科城市之光',3), +('欧阳天天',2,'2000-04-05','湖北省武汉市洪山区友谊大道与二环线交汇处融侨悦府',3), +('徐长卿',1,'2001-01-30','江苏省苏州市苏州工业园区独墅湖社区',3), +('李逍遥',1,'1999-11-11','广东省广州市白云区金沙洲岛御洲三街恒大绿洲',3) +--有2个学生尚未分配班级,姓名、性别、生日、家庭住址 分别是 +insert into Student(StudentName, StudentSex, StudentBirth, StudentAddress) +values('东方不败',3,'1999-12-11','河北省平定州西北四十余里的猩猩滩'), +('令狐冲',1,'2000-08-11','陕西省渭南市华阴市玉泉路南段'); +--创建课程学分 +insert into Course(CourseName, CourseCredit) +values('数据库高级应用',3), +('javascript编程基础',3), +('web前端程序设计基础',4), +('动态网页设计.net基础',6), +('动态网页设计php基础',6); + +insert into ClassCourse(ClassId, CourseId) +values(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(2,4),(3,1),(3,2),(3,3),(3,5); +insert into Score(StudentId, CourseId, Score) +values(1,1,80),(1,2,78),(1,3,65),(1,4,90),(2,1,60),(2,2,77),(2,3,68),(2,4,88),(3,1,88), +(3,2,45),(3,3,66),(3,4,75),(4,1,56),(4,2,80),(4,3,75),(4,4,66),(5,1,88),(5,2,79),(5,3,72), +(5,4,85),(6,1,68),(6,2,88),(6,3,73),(6,5,63),(7,1,84),(7,2,90),(7,3,92),(7,5,78),(8,1,58), +(8,2,59),(8,3,65),(8,5,75),(9,1,48),(9,2,67),(9,3,71),(9,4,56),(9,1,48); + +update Student set StudentBirth='2000-04-06' where StudentId=7; +update Score set Score=61 where ScoreId=30; +update Student set StudentSex=2,ClassId=1 where StudentId=4; +update Student set ClassId=2 where StudentId=8; +update Student set ClassId=2 where StudentId=9; +update Course set CourseCredit=4 where CourseId=1; +update Course set CourseCredit=4 where CourseId=2; +update Course set CourseCredit=5 where CourseId=3; +update Course set CourseCredit=7 where CourseId=4; +update Course set CourseCredit=7 where CourseId=5; +delete from Score where ScoreId=37; + +--班级 +select * from class ; +--学生 +select * from Student; +--课程 +select * from course; +--班级课程 +select * from ClassCourse; +--分数 +select * from score; +--课程--学分大小 +select * from course order by CourseCredit desc; +--分数--分数小大 +select * from score order by score asc; +--学生--年龄小大 +select * from student order by StudentBirth asc; +--查询软件一班所有的学生信息,显示学生id,姓名、性别、生日、住址 +select StudentId,studentName,StudentSex,StudentBirth,studentAddress from Student where ClassId=1; +--询所有的女生,显示学生id,姓名、性别、生日、住址 +select studentId,studentName,StudentSex,studentBirth,studentAddress from Student where studentsex=2; +--查询2000年出生的所有学生,显示学生id,姓名、性别、生日、住址 +select studentId,studentName,StudentSex,studentBirth,studentAddress from student where studentBirth between '2000-01-01' and '2000-12-31'; +--查询姓是欧阳的学生 +select * from student where studentName like '%欧阳%'; +--询地址是桂林市的学生 +select * from student where studentAddress like '%桂林市%'; +--查询姓李的学生,并且是三个字的 +select * from student where studentName like '李__' +--查询 软件一班 有几个学生 +select count(0) from Student where ClassId = 1 +--查询 软件一班 有几门课程 +select count(0) from ClassCourse where ClassId = 1 +--查询 刘正(学生编号为1) 的总分 +select sum(score) from Score where StudentId = 1 +--查询所有学生 数据库高级应用 的平均分 +select avg(Score)from Score where CourseId=1 +--查询 所有学生 的总分 +select StudentId, sum(Score) from Score group by StudentId; +--查询 所有学生 的平均分 +select StudentId, avg(Score) from Score group by StudentId; +--查询 所有学生 的平均分,并且按照平均分从高到低排列 +select StudentId, avg(Score) as AvgScore from Score group by StudentId order by AvgScore desc; +--查询 所有学生中 平均分 大于80分的学生。(聚合查询 + 分组 + having) +select StudentId, avg(Score) from Score group by StudentId having avg(Score)>80 \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\227\245\346\234\237\345\207\275\346\225\260\347\273\203\344\271\240.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\227\245\346\234\237\345\207\275\346\225\260\347\273\203\344\271\240.sql" new file mode 100644 index 0000000000000000000000000000000000000000..9d51415cb54c6784d9c187ac1fc35459b0dc4225 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\346\227\245\346\234\237\345\207\275\346\225\260\347\273\203\344\271\240.sql" @@ -0,0 +1,23 @@ +----------------------- +--日期函数练习 +---------------------- +--1.获取当前系统时间 +select getdate() +--2.获取本月的第一天 +select dateadd(MONTH,datediff(month,0,GETDATE()),0) +--3.获取本月的最后一天 +select dateadd(MONTH,datediff(month,0,GETDATE())+1,0)-1 +--3.获取下个月的第一天 +select dateadd(month,1,dateadd(month,datediff(month,0,GETDATE()),0)) +--4.获取本周的 第一天 +SELECT DATEADD(wk,DATEDIFF(wk, 0, GETDATE()), -6) +--5.获取本周的最后一天 +SELECT DATEADD(wk,DATEDIFF(wk, 0, GETDATE()), -1) +--6.查询学生的出生年份信息 +select distinct year(StudentBirth) 年份 from Student +--7.查询学生信息:姓名,年龄(年龄用datediff函数进行计算) +select StudentName,年龄=(year(getdate())-year(StudentBirth)) from Student +--8.查询本月生日的学生信息:学号,姓名,出生日期,年龄 +select StudentId,StudentName,StudentBirth,年龄=(year(getdate())-year(StudentBirth)) from Student where month(getdate())=month(StudentBirth) +--9.查询下个月生日的学生信息 +select StudentId,StudentName,StudentBirth,年龄=(year(getdate())-year(StudentBirth)) from Student where month(dateadd(month,1,getdate()))=month(StudentBirth) diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\237\255\350\247\206\351\242\221\346\225\260\346\215\256\345\272\223.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\237\255\350\247\206\351\242\221\346\225\260\346\215\256\345\272\223.sql" new file mode 100644 index 0000000000000000000000000000000000000000..08cc1ecfdd0daae1198e3e307f3d28f8c94855f6 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\344\270\200\346\254\241\344\275\234\344\270\232/\347\237\255\350\247\206\351\242\221\346\225\260\346\215\256\345\272\223.sql" @@ -0,0 +1,345 @@ +--组成员:占翊军,郑家炜,唐孝坚,许晨 +use master +go +if exists (select * from sys.databases where name = 'video') +drop database video +go +create database video +go +use video +go +--创建类别表 +create table Videos_Class( +Class_ID int identity primary key, --类别ID +Class_Name nvarchar(20) not null, --类别名字 +) +go +--创建标签表 +create table Tga( +Tga_ID int identity primary key, --标签ID +Tga_Name nvarchar(20) not null --标签名字 +) +go + +--创建用户表 +create table TB_User( +User_ID int identity primary key, --用户ID +Account nvarchar(20) not null, --账户名 +PassWord nvarchar(20) not null, --密码 +Sex tinyint check(Sex=0 or Sex=1 or Sex=2) default 0, --性别--0(未知)1(男)2(女) +User_Mail nvarchar(40) not null, --邮箱 +User_Age int default 0, --年龄--0(未知) +Ph_Number varchar(12) not null, --手机号 +) +go +--关注表 +create table User_Concern( +User_ID int references TB_User(User_ID), --用户ID +C_Time datetime not null, --关注时间 +C_User_ID int references TB_User(User_ID) --被关注用户ID +) +go +--视频表 +create table Videos( +Video_ID int identity primary key, --视频ID +User_ID int references TB_User(User_ID), --上传用户ID +Video_Title nvarchar(50) not null, --视频标题 +Re_Time datetime not null, --上传时间 +Class_ID int references Videos_Class(Class_ID), --所属类别 +Video_Address nvarchar(100) not null --视频地址 +) +go +--视频信息表 +create table Videos_Mag( +Like_YN tinyint check(Like_YN=0 or Like_YN=1), --视频点赞信息--0=未点赞,1=点赞 +Videos_Collect tinyint check(Videos_collect=0 or Videos_collect=1), --视频收藏信息--0=未收藏,1=已收藏 +User_ID int references TB_User(User_ID), --视频观看用户 +Video_ID int references Videos(Video_ID), --关联视频ID +) +go +--视频标签关系表 +create table Videos_Tga( +Videos_ID int references Videos(Video_ID), --视频ID +Tga_ID int references Tga(Tga_ID) --标签ID +) +go +--评论表 +create table Commet( +Commet_ID int identity primary key, --评论ID +Video_ID int references Videos(Video_ID), --关联视频ID +User_ID int references TB_User(User_ID), --关联用户ID +Rel_Time datetime, --发表时间 +Content nvarchar(200) not null --评论内容 +) +go +--弹幕表 +create table Barrage( +Barrage_ID int identity primary key, --弹幕ID +Video_ID int references Videos(Video_ID), --关联视频ID +User_ID int references TB_User(User_ID), --关联用户ID +Barrage_Time datetime, --发表时间 +Content nvarchar(20) --弹幕内容 +) +go +--插入类别数据 +insert into Videos_Class(Class_Name) +values +('游戏'), +('汽车'), +('搞笑'), +('生活'), +('科技') +go +--插入标签数据 +insert into Tga(Tga_Name) +values +('王者荣耀'), +('风景'), +('RTX4090'), +('CS:GO2'), +('Steam游戏'), +('手游'), +('我的世界'), +('BUG'), +('每日一笑'), +('科技资讯'), +('Vlog') +--插入用户信息数据 +insert into TB_user(Account,PassWord,Sex,User_Mail,User_Age,Ph_Number) +values +('小笼包','45688Abc',2,'45688Abc@qq.com',18,15859487621), +('传说中的狗蛋','cszdgd123',1,'cszdgd123@qq.com',18,18564924820), +('急速拍档','jspd123',0,'jspd123@qq.com',25,15854893210), +('阿宝搞笑','abgx123',1,'abgx123@qq.com',23,14632587940), +('无聊科技','wlkj123',0,'wlkj123@qq.com',21,18845975216) +go +--插入视频数据 +insert into Videos(User_ID,Video_Title,Re_Time,Class_ID,Video_Address) +values +(2,'来啊,对视啊!','2018-3-21',1,'https://www.douyin.com/来啊,对视啊!'), --1 +(2,'游戏时间','2023-2-21',1,'https://www.douyin.com/游戏时间'), --2 +(2,'游戏实况','2023-3-19',1,'https://www.douyin.com/游戏实况'), --3 +(2,'王者怎么玩?','2018-3-21',1,'https://www.douyin.com/王者怎么玩'), --4 +(3,'一台30年前的丰田皇冠是如何焕发青春的','2023-3-18',2,'https://www.douyin.com/一台30年前的丰田皇冠是如何焕发青春的'), --5 +(3,'第一人称视角沉浸式试驾-理想L9','2018-7-21',2,'https://www.douyin.com/第一人称视角沉浸式试驾-理想L9'), --6 +(3,'年轻人的第一辆二手车—购车指南+车型推荐','2023-3-17',2,'https://www.douyin.com/年轻人的第一辆二手车—购车指南+车型推荐'), --7 +(4,'如果把迪克和浦西全都拟人化.........','2023-3-28',3,'https://www.douyin.com/如果把迪克和浦西都拟人化.........'), --8 +(3,'生活小窍门','2023-3-21',2,'https://www.douyin.com/生活小窍门'), --9 +(5,'【无聊科技】爱Q艺弹幕塞广告?!红米手机充满仅需5分钟!','2023-3-21',5,'https://www.douyin.com/【无聊科技】爱Q艺弹幕塞广告?!红米手机充满仅需5分钟!'), --10 +(5,'【无聊科技】AirPods甩头调音量?是人性化还是鸡肋?','2023-3-15',5,'https://www.douyin.com/【无聊科技】AirPods甩头调音量?是人性化还是鸡肋?'), --11 +(2,'三十六计,吃为上计','2023-3-11',4,'https://www.douyin.com/三十六计,吃为上计') --12 +go +--用户关注表数据 +insert into User_Concern(User_ID, C_Time, C_User_ID) +values +(1,'2019-7-7',2),(1,'2020-3-5',3),(1,'2022-7-5',4),(2,'2018-7-7',1),(2,'2019-5-4',3),(2,'2017-6-6',5),(3,'2023-8-4',1),(3,'2023-3-6',2), +(3,'2023-2-3',3),(3,'2016-4-8',4),(3,'2023-3-7',5),(4,'2022-8-5',1),(4,'2021-6-8',5),(4,'2018-4-7',2),(5,'2022-5-6',3),(5,'2019-8-4',2), +(5,'2020-6-9',1) +go +--视频信息表数据 +insert into Videos_Mag(Like_YN,Videos_Collect,User_ID,Video_ID) +values +(1,1,1,1),(1,1,1,2),(1,1,1,3),(1,1,2,4),(1,0,1,5),(1,0,1,6),(1,1,1,7),(1,0,1,8),(1,0,1,9),(1,1,1,10),(1,1,1,11), +(1,1,1,12),(1,1,2,1),(1,1,2,2),(1,1,2,3),(1,0,2,4),(1,0,3,4),(1,0,3,12),(1,0,3,1),(1,0,3,10),(1,1,3,9),(1,1,4,1), +(0,1,3,2),(0,1,3,3),(0,0,3,5),(0,0,3,7),(0,1,3,11),(0,1,2,6),(0,1,2,7),(0,0,2,8),(0,0,2,9),(0,0,4,1),(0,0,4,2), +(0,1,4,3),(0,0,5,1),(0,1,5,2),(0,1,5,3),(0,1,5,4),(0,1,5,5),(0,1,5,6) +go +--视频评论数据 +insert into Commet(Content,Video_ID,User_ID,Rel_Time) +values +('火钳刘明',1,1,'2018-3-21'),('感觉要火',1,2,'2018-3-22'),('火钳刘明',1,3,'2018-3-21'),('感觉要火',1,4,'2018-3-22'), +('火钳刘明',2,1,'2023-2-21'),('感觉要火',2,2,'2023-2-21'),('火钳刘明',2,3,'2023-2-23'),('火钳刘明',2,3,'2023-2-22'), +('火钳刘明',3,4,'2023-3-19'),('感觉要火',3,4,'2023-3-19'),('火钳刘明',4,3,'2018-3-21'),('火钳刘明',4,3,'2018-3-21'), +('火钳刘明',5,5,'2023-3-18'),('感觉要火',5,5,'2023-3-18'),('火钳刘明',6,3,'2018-7-21'),('火钳刘明',6,3,'2018-7-21'), +('火钳刘明',7,5,'2023-3-17'),('感觉要火',7,4,'2023-3-17'),('火钳刘明',8,3,'2023-3-28'),('火钳刘明',8,3,'2023-3-28'), +('火钳刘明',9,1,'2023-3-21'),('感觉要火',9,2,'2023-3-21'),('火钳刘明',10,3,'2023-3-21'),('火钳刘明',10,3,'2023-3-21'), +('火钳刘明',11,1,'2023-3-15'),('感觉要火',11,2,'2023-3-15'),('火钳刘明',12,3,'2023-3-11'),('火钳刘明',12,3,'2023-3-11') +go +insert into Barrage(Content,Video_ID,User_ID,Barrage_Time) +values +('火钳刘明',2,1,'2018-3-21'),('感觉要火',8,2,'2018-3-22'),('火钳刘明',1,3,'2018-3-21'),('感觉要火',7,4,'2018-3-22'), +('火钳刘明',3,1,'2023-2-21'),('感觉要火',4,2,'2023-2-21'),('火钳刘明',8,3,'2023-2-23'),('火钳刘明',7,3,'2023-2-22'), +('火钳刘明',4,4,'2023-3-19'),('感觉要火',5,4,'2023-3-19'),('火钳刘明',5,3,'2018-3-21'),('火钳刘明',6,3,'2018-3-21'), +('火钳刘明',5,5,'2023-3-18'),('感觉要火',6,5,'2023-3-18'),('火钳刘明',6,3,'2018-7-21'),('火钳刘明',6,3,'2018-7-21'), +('火钳刘明',7,5,'2023-3-17'),('感觉要火',5,4,'2023-3-17'),('火钳刘明',8,3,'2023-3-28'),('火钳刘明',6,3,'2023-3-28'), +('火钳刘明',9,1,'2023-3-21'),('感觉要火',8,2,'2023-3-21'),('火钳刘明',10,3,'2023-3-21'),('火钳刘明',11,3,'2023-3-21'), +('火钳刘明',11,1,'2023-3-15'),('感觉要火',1,2,'2023-3-15'),('火钳刘明',12,3,'2023-3-11'),('火钳刘明',5,3,'2023-3-11') +go +--视频标签数据 +insert into Videos_Tga(Videos_ID, Tga_ID) +values +(1,4),(1,5),(2,6),(2,7),(2,2),(3,4),(3,5), +(4,1),(4,6),(6,11),(7,11),(8,9),(8,2),(10,10), +(10,11),(11,10),(12,8),(12,9) +go +--查询 +select * from Commet --评论 +select * from TB_user --用户 +select * from User_Concern --关注 +select * from Videos_Class --类别 +select * from Videos --视频 +select * from Videos_Mag --视频信息 +select * from Tga --标签 +select * from Videos_Tga --标签信息 +select * from Barrage --弹幕 + +--查询急速拍档(ID=2)发布的所有视频ID,视频标题,发布时间 + +select Video_ID,Video_title,Re_Time from Videos where User_ID=2 + +--查询无聊科技(ID=5)发布的所有视频ID,视频标题,发布时间 + +select Video_ID,Video_title,Re_Time from Videos where User_ID=5 + +--查询无聊科技(ID=5)发布了几条视频 + +select User_ID,count(Video_ID)视频条数 from Videos where User_ID=5 group by User_ID + +--查询阿宝搞笑(ID=4)发布了几条视频 + +select User_ID,count(Video_ID)视频条数 from Videos where User_ID=4 group by User_ID + +--查询生活小窍门(ID=9)的点赞数,评论数 + +select DISTINCT Video_ID,点赞数=(select count(Like_YN) from Videos_Mag +where Video_ID=9 and Like_YN=1),评论数=(select count(Content) from Commet where Video_ID=9) +from Videos_Mag where Video_ID=9 + +--查询游戏时间(ID=2)的点赞数,评论 + +select DISTINCT Video_ID,点赞数=(select count(Like_YN) from Videos_Mag +where Video_ID=2 and Like_YN=1),评论数=(select count(Content) from Commet where Video_ID=2) +from Videos_Mag where Video_ID=2 + +--查询游戏时间(ID=2)有多少条弹幕 + +select Video_ID,弹幕数=(select count(Content) from Barrage where Video_ID=2) from Videos where Video_ID=2 + +select Video_ID,弹幕数=count(Content) from Barrage where Video_ID=2 group by Video_ID + +--查询ID=6视频有多少条弹幕 + +select Video_ID,弹幕数=(select count(Content) from Barrage where Video_ID=6) from Videos where Video_ID=6 + +select Videos.Video_ID,弹幕数=count(Content) from Barrage join Videos on Barrage.Video_ID=Videos.Video_ID where Videos.Video_ID=6 group by Videos.Video_ID + + +--查询ID=6视频发送的弹幕 + +select Video_ID,Content from Barrage where Video_ID=6 + +--查询谁关注了小笼包 + +select User_Concern.User_ID,Account from User_Concern join TB_User on User_Concern.User_ID=TB_User.User_ID where C_User_ID=1 + +--查询小笼包(ID=1)的互关 + +select User_ID,Account from TB_User +where User_ID in(select C_User_ID from User_Concern where User_ID=1) and +User_ID in(select User_Concern.User_ID from User_Concern join TB_User on User_Concern.User_ID=TB_User.User_ID where C_User_ID=1) + +--查询点赞最高的视频 + +select top 1 Videos.Video_ID,Video_Title,点赞数=count(Like_YN) from Videos join Videos_Mag on Videos.Video_ID=Videos_Mag.Video_ID +where Like_YN=1 group by Videos.Video_ID,Video_Title order by Count(Like_YN) desc + +--查询点赞最高的两条视频 + +select top 2 Videos.Video_ID,Video_Title,点赞数=count(Like_YN) from Videos join Videos_Mag on Videos.Video_ID=Videos_Mag.Video_ID +where Like_YN=1 group by Videos.Video_ID,Video_Title order by Count(Like_YN) desc + +--查询收藏最高的视频 + +select top 1 Videos.Video_ID,Video_Title,收藏数=count(Videos_Collect) from Videos join Videos_Mag on Videos.Video_ID=Videos_Mag.Video_ID +where Videos_Collect=1 group by Videos.Video_ID,Video_Title order by Count(Videos_Collect) desc + +--查询播放最高的视频 + +select top 1 Videos.Video_ID,播放量=count(Videos_Mag.User_ID) from Videos join Videos_Mag on Videos.Video_ID=Videos_Mag.Video_ID +group by Videos.Video_ID order by Count(Videos_Mag.User_ID) desc + +--以播放量降序排序视频播放量 + +select Videos.Video_ID,播放量=count(Videos_Mag.User_ID) from Videos join Videos_Mag on Videos.Video_ID=Videos_Mag.Video_ID +group by Videos.Video_ID order by Count(Videos_Mag.User_ID) desc + +--视频ID=1的点赞数 + +select Video_ID,点赞数=count(Like_YN) from Videos_Mag +where Video_ID=1 and Like_YN=1 group by Video_ID + +--查询用户小笼包(ID=1)的关注数和粉丝数 + +select User_ID,count(C_User_ID)关注数,粉丝数=(select COUNT(User_ID) from User_Concern where C_User_ID=1) from User_Concern where User_ID=1 group by User_ID + +--查询用户无聊科技(ID=5)视频总点赞数 + +select count(Like_YN) from Videos_Mag where USER_ID=5 and Like_YN=1 +select * from Videos_Mag where User_ID=5 + +--查询用户传说中的狗蛋(ID=2)视频总点赞数 + +select 点赞数=count(Like_YN) from Videos_Mag where USER_ID=2 and Like_YN=1 +select * from Videos_Mag where User_ID=2 + +--查询2018年发布了几条弹幕 + +select year('2018') +select count(Barrage_ID)弹幕数 from Barrage where year(Barrage_Time)=year('2018') + + + + + + + + + + + + + + + + + + + + + + + + + + +--测试 +select count(Like_YN) from Videos_Mag where Video_ID=2 and Like_YN=1 +select count(Content) from Commet where Video_ID=2 + + + + + + + + + + + + + + + + + + +--select DISTINCT VideosID,count(Like_YN)点赞数,count(CommetID)评论数 +--from TB_Videos_Mag join TB_commet on TB_Videos_Mag.VideosID=TB_commet.VideoID +--where VideosID=2 +--group by VideosID + +--select count(Like_YN) from TB_Videos_Mag where VideosID=4 and Like_YN=1 + +--select DISTINCT * +--from TB_Videos_Mag join TB_commet on TB_Videos_Mag.VideosID=TB_commet.VideoID +--where VideosID=2 \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\270\200.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\270\200.sql" new file mode 100644 index 0000000000000000000000000000000000000000..d73eec636f4997a0ba63444747ef5a027b8bcc8c --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\270\200.sql" @@ -0,0 +1,97 @@ +create database 阶段二作业一; +go +use 阶段二作业一; +go + +--创建学生信息表 +create table stuInfo( +stuID int identity primary key, +stuName nvarchar(10), +stuAge int, +stuSex tinyint, +time datetime, +); + +--创建课程信息表 +create table courseInfo( +courseID int identity primary key, +courseName nvarchar(10), +courseMarks int ); + +--创建分数信息表 +create table scoreInfo( +scoreID int identity, +stuID int references stuInfo(stuID), +courseID int references courseInfo(courseID), +score int +); +insert into stuInfo(stuName ,stuAge ,stuSex ,time ) +values('Tom',19,1,NULL), + ('Jack',20,0,NULL), + ('Rose',21,1,NULL), + ('Lulu',19,1,NULL), + ('Lili',21,0,NULL), + ('abc',20,1,'2007-01-07 01:11:36.590'); + +insert into courseInfo(courseName,courseMarks) +values('JavaBase',4), + ('HTML',2), + ('JavaScript',2), + ('SqlBase',2); + +insert into scoreInfo(stuID,courseID,score) +values(1,1,80), + (1,2,85), + (1,4,50), + (2,1,75), + (2,3,45), + (2,4,75), + (3,1,45), + (4,1,95), + (4,2,75), + (4,3,90), + (4,4,45); +select * from stuInfo +select * from scoreInfo +select * from courseInfo +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID,count(courseName)选修的课程的数量, avg(score)平均分 +from courseInfo inner join scoreInfo +on courseInfo.courseID=scoreInfo.courseID +group by stuID +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseName,count(stuName)学生个数,sum(score) 考试总分 +from stuInfo join scoreInfo +on stuInfo.stuID=scoreInfo.stuID join courseInfo +on courseInfo.courseID=scoreInfo.courseID +group by courseName +--3.查询出性别一样并且年龄一样的学生的信息 +select son.* from stuInfo son join stuInfo father +on son.stuAge=father.stuAge and son.stuSex=father.stuSex +where son.stuID!=father.stuID ; +--4.查询出学分一样的课程信息 +select distinct son.* from courseInfo son join courseInfo father +on son.courseMarks=father.courseMarks +where son.courseID!=father.courseID +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select scoreInfo.stuID,StuName,scoreInfo.courseID,score +from stuInfo s join scoreInfo +on s.stuID=scoreInfo.stuID join courseInfo +on courseInfo.courseID=scoreInfo.courseID +where exists(select 1 from scoreInfo r where r.stuID=s.stuID) +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select scoreInfo.stuID,StuName,scoreInfo.courseID,courseName,courseMarks,score +from stuInfo s join scoreInfo +on s.stuID=scoreInfo.stuID join courseInfo +on courseInfo.courseID=scoreInfo.courseID +where exists(select 1 from scoreInfo r where r.stuID=s.stuID) +--7.查询出没有参加考试的学生的学号和姓名 +select stuID,StuName from stuInfo s where not exists(select 1 from scoreInfo r where r.stuID=s.stuID) +--8.查询出是周六周天来报到的学生 + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like'%a%' +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 +select stuID,avg(Score)平均成绩,count(scoreInfo.courseID)选修课程数量 +from scoreInfo join courseInfo on scoreInfo.courseID=courseInfo.courseID +group by stuID having count(scoreInfo.courseId)>2 and avg(Score)>70 \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\272\214.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\272\214.sql" new file mode 100644 index 0000000000000000000000000000000000000000..4e6589f6d82f875dcdda24fe2aecf6fa6cf6959c --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\215\201\346\254\241\344\275\234\344\270\232/\351\230\266\346\256\265\344\272\214\344\275\234\344\270\232\344\272\214.sql" @@ -0,0 +1,118 @@ +create database 阶段二作业二 +go +use 阶段二作业二 +go +create table tbl_card( +id nvarchar(15) primary key, +passWord nvarchar(15), +balance money, +userName nvarchar(20) +); +create table tbl_computer( +id nvarchar(15) primary key, +onUse tinyint check(onUse=0 or onUse=1), +Note int +); +create table tbl_record( +id int primary key, +cardId nvarchar(15) references tbl_card(id), +ComputerId nvarchar(15) references tbl_computer(id), +beginTime datetime, +endTime datetime, +fee money +); +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','55885fg',600,'校庆'), +('0089_EDE','zhang',134,'张峻') +insert into tbl_computer(id, 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(id, cardId, ComputerId, beginTime, endTime, fee) +values +(23,'0078_RJV','B01','2007-7-15 19:00:00','2007-7-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 cardId,userName,tbl_computer.id,beginTime,endTime,fee +from tbl_record join tbl_computer on tbl_computer.id=tbl_record.ComputerId +join tbl_card on tbl_card.id =tbl_record.cardId +where userName like '张军' +order by fee desc + +--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 id,userName from tbl_card c +where not exists( select 1 from tbl_record r where r.cardid=c.id) + +select id,userName from tbl_card +where id not in (select distinct cardId from tbl_record) + +select * from tbl_card left join tbl_record +on tbl_card.id=tbl_record.cardId +where fee is null + +--5. 将密码与用户名一样的上网卡信息查询出来 + +select * from tbl_card where passWord=userName + +--6. 查询出使用次数最多的机器号和使用次数 + +select top 1 ComputerId,count(cardId)使用次数 from tbl_record group by ComputerId order by count(cardId) desc + +select * from +(select computerId,(count(*))使用次数 from tbl_record group by computerId) 上网次数 +where 使用次数= (select max(使用次数) from (select computerId,count(*) 使用次数 from tbl_record group by computerId) 上网次数) + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 + +select cardId,userName,computerId,fee from tbl_record join tbl_card on tbl_record.cardId=tbl_card.id where cardId like'%abc' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + + select tbl_card.id,tbl_card.userName,tbl_computer.id,beginTime,endTime,tbl_record.fee + from tbl_record join tbl_card on tbl_card.id=tbl_record.cardId join tbl_computer on tbl_computer.id=tbl_record.ComputerId + where datepart(weekday,cast(tbl_record.begintime as date)) in (1,7) + --获取时间的星期数 + select DATEPART(weekday,'2023-03-19') + + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select cardId,userName,computerId,beginTime,endTime,fee from tbl_record join tbl_card on tbl_card.id=tbl_record.cardId where (endTime-beginTime)> '12:00:00' + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 + +select cardId,userName,ComputerId,beginTime,endTime,fee +from tbl_record 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) \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\2402.sql" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\2402.sql" new file mode 100644 index 0000000000000000000000000000000000000000..1737c38f01b71dad8220080a86b1c92e04f9c9f5 --- /dev/null +++ "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/98\347\273\203\344\271\2402.sql" @@ -0,0 +1,66 @@ +create database Bank; +use Bank; + +create table AccountInfo( +--账户编号 +AccountId int identity not null, +--身份证号码 +AccountCode varchar(20) not null, +--电话号码 +AccountPhone varchar(20), +--真实姓名 +RealName varchar(20) not null, +); + +create table BankCard( +--银行卡号 +CardNo varchar(30) primary key, +--账户编号 +AccountId int not null, +--银行密码 +CardPwd varchar(30) not null, +--银行卡余额 +CardBalance money not null, +--银行卡状态 +CardState tinyint not null, +--开卡时间 +CardTime varchar(30) not null , +); + +create table CardExchange( +--交易编号 +ExchangeId int identity primary key, +--银行卡号 +CardNo varchar(30) not null, +--存钱金额 +MoneyInBank money not null, +--取钱金额 +MoneyOUtBank money not null, +--交易时间 +ExchangeTime smalldatetime not null, +); + +--给账户信息表添加字段备注开户时间 +alter table AccountInfo add OpenTime smalldatetime not null; +--银行卡表修改字段默认值为getdate()备注开卡时间 +alter table BankCard add constraint DF_BankCard_CardTime default (getdate()) for CardTime; +--设置AccountInfo.AccountId为主键 +alter table AccountInfo add primary key(AccountId); +--AccountInfo.AccountCode 设置为唯一 +alter table AccountInfo add constraint UNQ_AccountInfo_AccountCode unique(AccountCode); +--AccountInfo.OpenTime 默认值设置为getdate() +alter table AccountInfo add constraint DF_AccountInfo_OpenTime default(getdate()) for OpenTime; +--AccountInfo.AccountPhone 设置为非空 +alter table AccountInfo alter column AccountPhone varchar(20)not null; +--BankCard.CardBalance 默认值设置为0.00 +alter table BankCard add constraint DF_BankCard_CardBalance default(0.00) for CardBalance; +--BankCard.CardState 默认值设置为1 +alter table BankCard add constraint DF_BankCard_CardState default(1) for CardState; +--BankCard.AccountId 设置为 AccountInfo.AccountId 的外键 +alter table BankCard add constraint Fk_BankCard_AccountId foreign key(AccountId) references AccountInfo(AccountId); +--CardExchange.CardNo 设置为 BankCard.CardNo 的外键 +alter table CardExchange add constraint Fk_CardExchange_CardNo foreign key(CardNo) references BankCard (CardNo); +--CardExchange.MoneyInBank 设置要大于等于0 +alter table CardExchange add constraint Ck_CardExchange_MoneyInBank check(MoneyInBank>=0) +--CardExchange.MoneyOutBank 设置要大于等于0 +alter table CardExchange add constraint Ck_CardExchange_MoneyOutBank check(MoneyOutBank>=0) \ No newline at end of file diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\346\210\252\345\233\276.png" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\346\210\252\345\233\276.png" new file mode 100644 index 0000000000000000000000000000000000000000..9fa6759a2ce09b46335e45c3c7e9553e89fbd6a5 Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\346\210\252\345\233\276.png" differ diff --git "a/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\346\210\252\345\233\2762.png" "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\346\210\252\345\233\2762.png" new file mode 100644 index 0000000000000000000000000000000000000000..b50e3b34b13b2fd5628b50f253b060646d7b5ca0 Binary files /dev/null and "b/02\345\215\240\347\277\212\345\206\233/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\346\225\260\346\215\256\345\272\223\346\210\252\345\233\2762.png" differ diff --git "a/02\346\210\230\345\275\271\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/02\346\210\230\345\275\271\345\206\233/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/README.en.md b/README.en.md deleted file mode 100644 index eda3d5b79f71a1de090080089bb70c9125dbc9d3..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# 鏁版嵁搴撶殑浣滀笟 - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md deleted file mode 100644 index e48879534d127bdc0add162e0aaedd8b33e91db4..0000000000000000000000000000000000000000 --- a/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# 鏁版嵁搴撶殑浣滀笟 - -#### 浠嬬粛 -{**浠ヤ笅鏄 Gitee 骞冲彴璇存槑锛屾偍鍙互鏇挎崲姝ょ畝浠** -Gitee 鏄 OSCHINA 鎺ㄥ嚭鐨勫熀浜 Git 鐨勪唬鐮佹墭绠″钩鍙帮紙鍚屾椂鏀寔 SVN锛夈備笓涓哄紑鍙戣呮彁渚涚ǔ瀹氥侀珮鏁堛佸畨鍏ㄧ殑浜戠杞欢寮鍙戝崗浣滃钩鍙 -鏃犺鏄釜浜恒佸洟闃熴佹垨鏄紒涓氾紝閮借兘澶熺敤 Gitee 瀹炵幇浠g爜鎵樼銆侀」鐩鐞嗐佸崗浣滃紑鍙戙備紒涓氶」鐩鐪 [https://gitee.com/enterprises](https://gitee.com/enterprises)} - -#### 杞欢鏋舵瀯 -杞欢鏋舵瀯璇存槑 - - -#### 瀹夎鏁欑▼ - -1. xxxx -2. xxxx -3. xxxx - -#### 浣跨敤璇存槑 - -1. xxxx -2. xxxx -3. xxxx - -#### 鍙備笌璐$尞 - -1. Fork 鏈粨搴 -2. 鏂板缓 Feat_xxx 鍒嗘敮 -3. 鎻愪氦浠g爜 -4. 鏂板缓 Pull Request - - -#### 鐗规妧 - -1. 浣跨敤 Readme\_XXX.md 鏉ユ敮鎸佷笉鍚岀殑璇█锛屼緥濡 Readme\_en.md, Readme\_zh.md -2. Gitee 瀹樻柟鍗氬 [blog.gitee.com](https://blog.gitee.com) -3. 浣犲彲浠 [https://gitee.com/explore](https://gitee.com/explore) 杩欎釜鍦板潃鏉ヤ簡瑙 Gitee 涓婄殑浼樼寮婧愰」鐩 -4. [GVP](https://gitee.com/gvp) 鍏ㄧО鏄 Gitee 鏈鏈変环鍊煎紑婧愰」鐩紝鏄患鍚堣瘎瀹氬嚭鐨勪紭绉寮婧愰」鐩 -5. Gitee 瀹樻柟鎻愪緵鐨勪娇鐢ㄦ墜鍐 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 灏侀潰浜虹墿鏄竴妗g敤鏉ュ睍绀 Gitee 浼氬憳椋庨噰鐨勬爮鐩 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) 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" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000