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/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\267.PNG" "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\267.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..db62d2eb6db37eed8abaed56ef84c45c126a542b Binary files /dev/null and "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\267.PNG" differ diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2672.PNG" "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2672.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..7b5f8fbc9f6c758dd85a5dd27dda8964a5aca2da Binary files /dev/null and "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2672.PNG" differ diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2673.PNG" "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2673.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..8d9edc7f009c5d4dcb31f4fb84d9c2efdba466fc Binary files /dev/null and "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2673.PNG" differ diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2674.PNG" "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2674.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..78e2c2c9251c0ddfe54209e154e30c50b0ab48a1 Binary files /dev/null and "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2674.PNG" differ diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2675.PNG" "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2675.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..e0ef8cc4031328098f0f11d976035a56fdff8649 Binary files /dev/null and "b/39\350\256\270\346\231\250/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\346\215\225\350\216\2675.PNG" differ diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\347\254\2544\347\253\240\344\275\234\344\270\232.sql" "b/39\350\256\270\346\231\250/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\347\254\2544\347\253\240\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..09b1f89a8dde35159f15f384f863f569f05bae37 --- /dev/null +++ "b/39\350\256\270\346\231\250/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\347\254\2544\347\253\240\344\275\234\344\270\232.sql" @@ -0,0 +1,122 @@ +create database xc +go +use xc +go +create table stuinfo( +stuNo nvarchar(10), +stuName nvarchar(10), +stuAge int, +stuAddress nvarchar(10), +stuSeat int, +stuSex tinyint, +); +create table stuexam( +examNo int identity, +stuNo nvarchar(10), +writtenExam int, +labExam int +); + +insert into stuinfo(stuNo,stuName,stuAge,stuAddress,stuSeat,stuSex) +values ('s2501','张秋利',20,'美国硅谷',1,1), + ('s2502','李斯文',18,'湖北武汉',2,0), + ('s2503','马文才',22,'湖南长沙',3,1), + ('s2504','欧阳俊雄',21,'湖北武汉',4,0), + ('s2505','梅超风',20,'湖北武汉',5,1), + ('s2506','陈旋风',19,'美国硅谷',6,1), + ('s2507','陈风',20,'美国硅谷',7,0); + +insert into stuexam(stuNo,writtenExam,labExam) +values ('s2501',50,70), + ('s2502',60,65), + ('s2503',86,85), + ('s2504',40,80), + ('s2505',70,90), + ('s2506',85,90); + +--1.查询学生信息表(stuinfo)中所有列信息,给每列取上中文名称 +select stuNo as 学号,stuName as 姓名, stuAge as 年龄,stuAddress as 地址,stuSeat as 座位,stuSex as 性别 from stuinfo; + +--2.查询学生信息表(stuinfo)中的姓名,年龄和地址三列的信息 +select stuName,stuAge,stuAddress from stuinfo; + +--3.查询学生分数表(stuexam)中的学号,笔试和机试三列的信息,并为这三列取中文名字 +--注意:要用三种方法 +select stuNo as 学号,writtenExam 笔试, 机试=labExam from stuexam; + +--4.查询学生信息表(stuInfo)中的学号,姓名,地址,以及将:姓名+@+地址 组成新列 “邮箱” +select stuNo as 学号,stuName as 姓名,stuAddress as 地址,cast(stuName+'@'+stuAddress as varchar(40))as 邮箱 from stuinfo; + + --5.查询学生分数表(stuexam)中的学生的学号,笔试,机试以及总分这四列的信息 + select stuNo as 学号,writtenExam 笔试, 机试=labExam,cast(writtenExam+labExam as int) as 总分 from stuexam + + --6.查询学生信息表(stuInfo)中学生来自哪几个地方 + select distinct stuAddress from stuinfo; + + --7.查询学生信息表(stuInfo)中学生有哪几种年龄,并为该列取对应的中文列名 + select distinct stuAge as 年龄 from stuInfo; + + --8.查询学生信息表(stuInfo)中前3行记录 + select top 3 *from stuinfo; + + --9.查询学生信息表(stuInfo)中前4个学生的姓名和座位号 + select top 4 stuName,stuSeat from stuinfo; + + --10.查询学生信息表(stuInfo)中一半学生的信息 + select top 50 percent *from stuinfo; + + --11.将地址是湖北武汉,年龄是20的学生的所有信息查询出来 + select*from stuinfo where stuAddress='湖北武汉' and stuAge=20; + + --12.将机试成绩在60-80之间的信息查询出来,并按照机试成绩降序排列(用两种方法实现) + select * from stuexam where labExam between 60 and 80 order by labExam desc; + select * from stuexam where labExam>=60 or labExam<=80 order by labExam desc; + + --13.查询来自湖北武汉或者湖南长沙的学生的所有信息(用两种方法实现) + select *from stuinfo where stuAddress='湖北武汉' or stuAddress='湖南长沙'; + select * from stuinfo where stuAddress in('湖北武汉','湖南长沙'); + + --14.查询出笔试成绩不在70-90之间的信息,并按照笔试成绩升序排列(用两种方法实现) + select * from stuexam where writtenExam not between 70 and 90 order by writtenExam asc; + select * from stuexam where writtenExam<70 or writtenExam>90 order by writtenExam asc; + +--15.查询年龄没有写的学生所有信息 +select * from stuinfo where stuAge is null; + +--16.查询年龄写了的学生所有信息 +select * from stuinfo where stuAge is not null; + +--17.查询姓张的学生信息 +select * from stuinfo where stuName like '张%'; + +--18.查询学生地址中有‘湖’字的信息 +select * from stuinfo where stuAddress like'%湖%'; + +--19.查询姓张但名为一个字的学生信息 +select * from stuinfo where stuName like '张_'; + +--20.查询姓名中第三个字为‘俊’的学生的信息,‘俊’后面有多少个字不限制 +select* from stuinfo where stuName like '__俊%'; + +--21.按学生的年龄降序显示所有学生信息 +select * from stuinfo order by stuAge desc; + +--22.按学生的年龄降序和座位号升序来显示所有学生的信息 +select * from stuinfo order by stuAge desc ,stuSeat asc; + +--23.显示笔试第一名的学生的考试号,学号,笔试成绩和机试成绩 +select stuNo,examNo,writtenExam,labExam from stuexam where writtenExam in(select max(writtenExam) from stuexam); +select top 1 * from stuexam order by writtenExam desc; + +--24.显示机试倒数第一名的学生的考试号,学号,笔试成绩和机试成绩 +select stuNo,examNo,writtenExam,labExam from stuexam where labExam in(select min(labExam) from stuexam); +select top 1 * from stuexam order by labExam asc; + +--25.查询每个地方的学生的平均年龄 +select stuAddress,avg(stuAge) 平均年龄 from stuinfo group by stuAddress + +--26.查询男女生的分别的年龄总和 +select stuSex,sum (stuAge)年龄总和 from stuinfo group by stuSex + +--27.查询每个地方的男女生的平均年龄和年龄的总和 +select stuAddress,avg(stuAge)平均年龄,sum(stuAge)年龄的总和 from stuinfo group by stuAddress,stuSex \ No newline at end of file diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\345\244\226\351\224\256.sql" "b/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\345\244\226\351\224\256.sql" new file mode 100644 index 0000000000000000000000000000000000000000..5139d1c40e4485c4a7351b60910047bec02f675f --- /dev/null +++ "b/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\345\244\226\351\224\256.sql" @@ -0,0 +1,33 @@ +create database Student1; +use Student1; +create table Class( +ClassId int identity primary key not null, +ClassName nvarchar(50) not null unique, +); +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, +ClssId int not null default 0, +StudenttityCard varchar(20) not null default''); +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)); +create table ClassCourse( +ClassCourseld int identity not null primary key, +ClassId int not null, +CourseId int not null, +foreign key (ClassId) references Class (ClassId), +); +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)); \ No newline at end of file diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\345\261\236\346\200\247.sql" "b/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\345\261\236\346\200\247.sql" new file mode 100644 index 0000000000000000000000000000000000000000..d8cac7af4a2c1d0ad7ddf05b357e6761d935fd6f --- /dev/null +++ "b/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\345\261\236\346\200\247.sql" @@ -0,0 +1,28 @@ +create database zuoye; +use zuoye; +create table Class( +Classld int identity primary key not null, +ClassName nvarchar(50) not null unique, +); +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, +ClssId int not null default 0, +StudenttityCard varchar(20) not null default''); +create table Course( +Courseld int identity not null primary key, +CourseName nvarchar(50) not null unique, +CourseCredit tinyint not null default 0 check(CourseCredit>0)); +create table ClassCourse( +ClassCourseld int identity not null primary key, +ClassId int not null, +CourseId int not null); +create table Score( +Scoreld int identity not null primary key, +StudentId int not null, +Courseld int not null, +Score int not null check(Score>=0), +IsResit tinyint not null default 0); \ No newline at end of file diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232\346\210\252\345\233\276.PNG" "b/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232\346\210\252\345\233\276.PNG" new file mode 100644 index 0000000000000000000000000000000000000000..91ba4af8b2983e9a4707ef8a9fcc254b689ef594 Binary files /dev/null and "b/39\350\256\270\346\231\250/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232\346\210\252\345\233\276.PNG" differ diff --git "a/39\350\256\270\346\231\250/\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\2322.sql" "b/39\350\256\270\346\231\250/\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\2322.sql" new file mode 100644 index 0000000000000000000000000000000000000000..c571211b7b1a11fb9c0347b1d28c89de102793f9 --- /dev/null +++ "b/39\350\256\270\346\231\250/\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\2322.sql" @@ -0,0 +1,88 @@ +create database xuchen8; +go +use xuchen8; +go + +--创建订单表 +create table orders( +orderId int primary key identity, +orderDate datetime +); + +--创建订购项目表 +create table orderItem( +itemId int identity, +orderid int references orders(orderId), +itemType nvarchar(10), +itemName nvarchar(10), +theNumber int, +theMoney money +); + +insert into orders(orderDate) +values ('2008-01-12 00:00:00.000'),('2008-02-10 00:00:00.000'),('2008-02-15 00:00:00.000'),('2008-03-10 00:00:00.000'); + + +insert into orderItem(orderid,itemType,itemName,theNumber,theMoney) +values (1,'文具','笔',72,2), +(1,'文具','尺',10,1), +(1,'体育用品','篮球',1,56), +(2,'文具','笔',36,2), +(2,'文具','固体胶',20,3), +(2,'日常用品','透明胶',2,1), +(2,'体育用品','羽毛球',20,3), +(3,'文具','订书机',20,3), +(3,'文具','订书机',10,3), +(3,'文具','裁纸刀',5,5), +(4,'文具','笔',20,2), +(4,'文具','信纸',50,1), +(4,'日常用品','毛巾',4,5), +(4,'日常用品','透明胶',30,1), +(4,'体育用品','羽毛球',20,3); + + +select * from orderItem +select * from orders + + +--订单表(orders)列为:订单编号(orderId 主键) 订购日期(orderDate) + +--订购项目表(orderItem),列为: +--项目编号(ItemiD)订单编号(orderId)产品类别(itemType) +--产品名称(itemName) 订购数量(theNumber) 订购单价(theMoney) + + +--1.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价 + +select orders.orderID 订单编号,orderDate 订购日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价 from orders inner join orderItem on orders.orderId=orderItem.orderid + +--2.查询订购数量大于50的订单的编号,订单日期,订购产品的类别和订购的产品名称 +select orders.orderID 订单编号,orderDate 订购日期,itemType 产品类别,itemName 产品名称 from orders inner join orderItem on orders.orderId=orderItem.orderid where theNumber>50 + + +--3.查询所有的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderID 订单编号,orderDate 订购日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价, theNumber*theMoney 订购总价 from orders inner join orderItem on orders.orderId=orderItem.orderid + +--4.查询单价大于等于5并且数量大于等于50的订单的订单的编号,订单日期,订购产品的类别和订购的产品名称,订购数量和订购单价以及订购总价 +select orders.orderID 订单编号,orderDate 订购日期,itemType 产品类别,itemName 产品名称,theNumber 订购数量,theMoney 订购单价, theNumber*theMoney 订购总价 from orders inner join orderItem on orders.orderId=orderItem.orderid +where theMoney>=5 and theNumber>=50 + +--5.查询每个订单分别订购了几个产品,例如: + --编号 订购产品数 + -- 1 3 + -- 2 4 +select orderid 订单编号, count(itemName) 订购产品数 from orderItem group by orderid + + + +--6.查询每个订单里的每个类别的产品分别订购了几次和总数量,例如: + + --订单编号 产品类别 订购次数 总数量 + + --1 文具 2 82 + --1 体育用品 1 1 + --2 文具 2 56 + --2 体育用品 1 2 + --2 日常用品 1 20 + + select orderid 订单编号, itemType 产品类别 ,count(theNumber) 订购次数,sum(theNumber) 总数量 from orderItem group by orderid,itemType \ No newline at end of file diff --git "a/39\350\256\270\346\231\250/\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\2323SQLQuery1.sql" "b/39\350\256\270\346\231\250/\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\2323SQLQuery1.sql" new file mode 100644 index 0000000000000000000000000000000000000000..3f128ee6007947a63a09825a962eb0ef78b7382c --- /dev/null +++ "b/39\350\256\270\346\231\250/\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\2323SQLQuery1.sql" @@ -0,0 +1,129 @@ +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 + +--1. 查询 李逍遥(编号id为9) 所在的班级名称(连接查询 2表) +select StudentName 姓名 ,ClassName 班级名称 from Student inner join Class on Student.ClassId=Class.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 diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\347\273\203\344\271\2401.sql" "b/39\350\256\270\346\231\250/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\347\273\203\344\271\2401.sql" new file mode 100644 index 0000000000000000000000000000000000000000..bc27e59a7862b367b9e5190599b1012046bf5db1 --- /dev/null +++ "b/39\350\256\270\346\231\250/\347\254\254\344\271\235\346\254\241\344\275\234\344\270\232/\350\277\236\346\216\245\346\237\245\350\257\242\347\273\203\344\271\2401.sql" @@ -0,0 +1,58 @@ +create database xc2 +go +use xc2 +go +create table stuinfo( +stuNo nvarchar(10), +stuName nvarchar(10), +stuAge int, +stuAddress nvarchar(10), +stuSeat int, +stuSex tinyint, +); +create table stuexam( +examNo int identity, +stuNo nvarchar(10), +writtenExam int, +labExam int +); + +insert into stuinfo(stuNo,stuName,stuAge,stuAddress,stuSeat,stuSex) +values ('s2501','张秋利',20,'美国硅谷',1,1), + ('s2502','李斯文',18,'湖北武汉',2,0), + ('s2503','马文才',22,'湖南长沙',3,1), + ('s2504','欧阳俊雄',21,'湖北武汉',4,0), + ('s2505','梅超风',20,'湖北武汉',5,1), + ('s2506','陈旋风',19,'美国硅谷',6,1), + ('s2507','陈风',20,'美国硅谷',7,0); + +insert into stuexam(stuNo,writtenExam,labExam) +values ('s2501',50,70), + ('s2502',60,65), + ('s2503',86,85), + ('s2504',40,80), + ('s2505',70,90), + ('s2506',85,90); + +select * from stuinfo +select * from stuexam + +--1.查询学生的姓名,年龄,笔试成绩和机试成绩 +select stuName 姓名,stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from stuinfo inner join stuexam on stuinfo.stuNo=stuexam.stuNo + +--2.查询笔试和机试成绩都在60分以上的学生的学号,姓名,笔试成绩和机试成绩 +select stuinfo.stuNo 学号,stuName 姓名,stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from stuinfo inner 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 stuName 姓名,stuAge 年龄, writtenExam 笔试成绩, labExam 机试成绩 from stuinfo inner join stuexam on stuinfo.stuNo=stuexam.stuNo where stuAge>=20 order by writtenExam desc + +--5.查询男女生的机试平均分 +select stuSex 性别,avg(labExam) 机试平均分 from stuinfo inner join stuexam on stuinfo.stuNo=stuexam.stuNo group by stuSex + +--6.查询男女生的笔试总分 +select stuSex 性别, sum(writtenExam) 笔试成绩 from stuinfo inner join stuexam on stuinfo.stuNo=stuexam.stuNo group by stuSex + + diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\256\344\277\241\345\233\276\347\211\2071_20230218143911.png" "b/39\350\256\270\346\231\250/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\256\344\277\241\345\233\276\347\211\2071_20230218143911.png" new file mode 100644 index 0000000000000000000000000000000000000000..9453c80784ecd9f184a10b9bf63038ca75bf57f6 Binary files /dev/null and "b/39\350\256\270\346\231\250/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\256\344\277\241\345\233\276\347\211\2071_20230218143911.png" differ diff --git "a/39\350\256\270\346\231\250/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\256\344\277\241\345\233\276\347\211\2072_20230218143847.png" "b/39\350\256\270\346\231\250/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\256\344\277\241\345\233\276\347\211\2072_20230218143847.png" new file mode 100644 index 0000000000000000000000000000000000000000..d4a60dd536f29ef1fc55cc2fb8a13fb4a48428d6 Binary files /dev/null and "b/39\350\256\270\346\231\250/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\345\276\256\344\277\241\345\233\276\347\211\2072_20230218143847.png" differ diff --git "a/39\350\256\270\346\231\250/\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/39\350\256\270\346\231\250/\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..412ba67c47a389e44f2721201cf8bfab974a2fdc --- /dev/null +++ "b/39\350\256\270\346\231\250/\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,104 @@ +create database zuoye5; +go +use zuoye5; +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 +update Student set StudentBirth='2000-04-06' where StudentId=7; +update Score set Score=61 where StudentId=8 and CourseId=2; + + + +select StudentName 学生姓名,ClassName 班级名称 from Student inner join Class on Student.ClassId=Class.ClassId +select StudentName 学生姓名,count(CourseId) 课程数量 from Student inner join Course on \ No newline at end of file diff --git "a/39\350\256\270\346\231\250/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214SQLQuery2.sql" "b/39\350\256\270\346\231\250/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214SQLQuery2.sql" new file mode 100644 index 0000000000000000000000000000000000000000..9a56979074ee2f40ef98e3164ea0d71e8859d91b --- /dev/null +++ "b/39\350\256\270\346\231\250/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232\344\272\214SQLQuery2.sql" @@ -0,0 +1,69 @@ +create database xuchen2; +go +use xuchen2; +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, +theMoney money +); + +insert into orders(orderId,orderDate) +values (1,'2008-01-12 00:00:00.000'),(2,'2008-02-10 00:00:00.000'),(3,'2008-02-15 00:00:00.000'),(4,'2008-03-10 00:00:00.000'); +select * from orders + +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); +select * from orderItem + +--1.查询所有订单订购的所有物品数量总和 +select sum (theNumber)物品数量总和 from orderItem + + +--2.查询订单编号小于3的,平均单价小于10 每个订单订购的所有物品的数量和以及平均单价 +select orderId,sum(theNumber)所有物品的数量和,avg (theMoney) 平均单价 from orderItem group by orderId having orderId<3 and avg(theMoney)<10 + +--3.查询平均单价小于10并且总数量大于 50 每个订单订购的所有物品数量和以及平均单价 +select orderId,sum(theNumber)所有物品数量和,avg (theMoney)平均单价 from orderItem group by orderId having sum(theNumber)>50 and avg (theMoney)<10 + +--4.查询每种类别的产品分别订购了几次,例如: +--文具 9 +--体育用品 3 +--日常用品 3 +select itemType,count(itemType)订购次数 from orderItem group by itemType + + +--5.查询每种类别的产品的订购总数量在100以上的订购总数量和平均单价 +select itemType 产品名称,sum(theNumber) 订购总数量,avg (theMoney) 平均单价 from orderItem group by itemType having sum (theNumber)>100 + +--6.查询每种产品的订购次数,订购总数量和订购的平均单价,例如: + + --产品名称 订购次数 总数量 平均单价 + --笔 3 120 2 + select itemName 产品名称,count(itemName)订购次数, sum(theNumber) 订购总数量,avg (theMoney) 平均单价 from orderItem group by itemName ; + diff --git "a/39\350\256\270\346\231\250/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\344\277\256\346\224\271\343\200\201\345\210\240\351\231\244\345\222\214\346\237\245\350\257\242\346\225\260\346\215\256.sql" "b/39\350\256\270\346\231\250/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\344\277\256\346\224\271\343\200\201\345\210\240\351\231\244\345\222\214\346\237\245\350\257\242\346\225\260\346\215\256.sql" new file mode 100644 index 0000000000000000000000000000000000000000..00004ddd412af13f711949b9a4b62d59b92bbfb6 --- /dev/null +++ "b/39\350\256\270\346\231\250/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\344\277\256\346\224\271\343\200\201\345\210\240\351\231\244\345\222\214\346\237\245\350\257\242\346\225\260\346\215\256.sql" @@ -0,0 +1,152 @@ +create database zuoye7; +go +use zuoye7; +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 + + +update Student set StudentBirth='2000-04-06' where StudentId=7; +update Score set Score=61 where StudentId=8 and CourseId=2; +update Student set StudentSex=2, ClassId=1 where StudentId=4; +update Student set ClassId=2 where StudentId=8 or StudentId=9; +update Course set CourseCredit=CourseCredit+1; +delete from Score where Scoreld=73; + + + +select StudentName,StudentAddress from Student; +select top 20 percent * from Student; +select distinct ClassId from Student; +select distinct StudentId from Score; +select StudentName,StudentAddress from Student; +select top 20 percent * from Student; +select distinct ClassId from Student; +select distinct StudentId 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; + +select * 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; + +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 StudentId, sum(Score) as TotalScore from Score group by StudentId; + +select StudentId, avg(Score) as TotalScore from Score group by StudentId; + +select StudentId, avg(Score) as TotalScore from Score group by StudentId order by TotalScore desc ; + +select StudentId, avg(Score) as AvgScore from Score group by StudentId having avg(Score) > 80 ; \ No newline at end of file diff --git "a/39\350\256\270\346\231\250/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\346\237\245\350\257\242\346\225\260\346\215\2561-26\351\242\230\347\273\203\344\271\240.sql" "b/39\350\256\270\346\231\250/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\346\237\245\350\257\242\346\225\260\346\215\2561-26\351\242\230\347\273\203\344\271\240.sql" new file mode 100644 index 0000000000000000000000000000000000000000..00004ddd412af13f711949b9a4b62d59b92bbfb6 --- /dev/null +++ "b/39\350\256\270\346\231\250/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\346\237\245\350\257\242\346\225\260\346\215\2561-26\351\242\230\347\273\203\344\271\240.sql" @@ -0,0 +1,152 @@ +create database zuoye7; +go +use zuoye7; +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 + + +update Student set StudentBirth='2000-04-06' where StudentId=7; +update Score set Score=61 where StudentId=8 and CourseId=2; +update Student set StudentSex=2, ClassId=1 where StudentId=4; +update Student set ClassId=2 where StudentId=8 or StudentId=9; +update Course set CourseCredit=CourseCredit+1; +delete from Score where Scoreld=73; + + + +select StudentName,StudentAddress from Student; +select top 20 percent * from Student; +select distinct ClassId from Student; +select distinct StudentId from Score; +select StudentName,StudentAddress from Student; +select top 20 percent * from Student; +select distinct ClassId from Student; +select distinct StudentId 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; + +select * 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; + +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 StudentId, sum(Score) as TotalScore from Score group by StudentId; + +select StudentId, avg(Score) as TotalScore from Score group by StudentId; + +select StudentId, avg(Score) as TotalScore from Score group by StudentId order by TotalScore desc ; + +select StudentId, avg(Score) as AvgScore from Score group by StudentId having avg(Score) > 80 ; \ No newline at end of file diff --git "a/39\350\256\270\346\231\250/\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/39\350\256\270\346\231\250/\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..976f3edc3c92ac323865328b3a88d6fb46ba5a16 --- /dev/null +++ "b/39\350\256\270\346\231\250/\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,78 @@ +----------------------- +create database 日期函数练习; +go +use 日期函数练习; +go + +--学生信息表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','陕西省渭南市华阴市玉泉路南段'); + +select * from Student + +--日期函数练习 +---------------------- +--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(WEEKDAY,DATEDIFF(weekday,0,GETDATE()),-7) 本周的第一天 + +--5.获取本周的最后一天 +select DATEADD(WEEKDAY,DATEDIFF(weekday,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(StudentBirth)=month(getdate()) + + +--9.查询下个月生日的学生信息 +select StudentID 学号,StudentName 姓名, StudentBirth 出生日期,年龄=(year(getdate())-year(StudentBirth)) from Student where month(dateadd(month,1,getdate()))=month(StudentBirth) + + + diff --git "a/39\350\256\270\346\231\250/\347\254\254\345\215\201\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/39\350\256\270\346\231\250/\347\254\254\345\215\201\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..976f3edc3c92ac323865328b3a88d6fb46ba5a16 --- /dev/null +++ "b/39\350\256\270\346\231\250/\347\254\254\345\215\201\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,78 @@ +----------------------- +create database 日期函数练习; +go +use 日期函数练习; +go + +--学生信息表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','陕西省渭南市华阴市玉泉路南段'); + +select * from Student + +--日期函数练习 +---------------------- +--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(WEEKDAY,DATEDIFF(weekday,0,GETDATE()),-7) 本周的第一天 + +--5.获取本周的最后一天 +select DATEADD(WEEKDAY,DATEDIFF(weekday,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(StudentBirth)=month(getdate()) + + +--9.查询下个月生日的学生信息 +select StudentID 学号,StudentName 姓名, StudentBirth 出生日期,年龄=(year(getdate())-year(StudentBirth)) from Student where month(dateadd(month,1,getdate()))=month(StudentBirth) + + + diff --git "a/39\350\256\270\346\231\250/\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/39\350\256\270\346\231\250/\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..1292d1b8d5176ebbb351e6f1d8b2593d3158c38a --- /dev/null +++ "b/39\350\256\270\346\231\250/\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,96 @@ +create database 作业一; +go +use 作业一; +go + +--创建学生信息表 +create table stuInfo( +stuID int identity, +stuName nvarchar(10), +stuAge int, +stuSex tinyint, +time nvarchar(10), +); + +--创建课程信息表 +create table courseInfo( +courseID int identity, +courseName nvarchar(10), +courseMarks int ); + +--创建分数信息表 +create table scoreInfo( +scoreID int identity, +stuID int, +courseID int, +score int +); +insert into stuInfo(stuName ,stuAge ,stuSex ,time ) +values('Tom',19,1,NULL), + ('Jack',20,0,NULL), + ('Rose',21,1,NULL), + ('Lulu',19,1,NULL), + ('Lili',21,0,NULL), + ('abc',20,1,'2007-01-07 01:11:36.590'); + +insert into courseInfo(courseName,courseMarks) +values('JavaBase',4), + ('HTML',2), + ('JavaScript',2), + ('SqlBase',2); + +insert into scoreInfo(stuID,courseID,score) +values(1,1,80), + (1,2,85), + (1,4,50), + (2,1,75), + (2,3,45), + (2,4,75), + (3,1,45), + (4,1,95), + (4,2,75), + (4,3,90), + (4,4,45); +select * from stuInfo +select * from courseInfo +select * from scoreInfo + + +--1.查询出每个学生所选修的课程的数量和所选修的课程的考试的平均分 +select stuID 学生编号,count(courseName)选修的课程的数量, avg(score)平均分 from courseInfo inner join scoreInfo on courseInfo.courseID=scoreInfo.courseID group by stuID + +--2.查询出每门课程的选修的学生的个数和学生考试的总分 +select courseInfo.courseID 课程编号 ,count(stuID)学生个数,sum(Score) 总分 from scoreInfo inner join courseInfo on scoreInfo.courseID=courseInfo.courseID group by courseInfo.courseID + +--3.查询出性别一样并且年龄一样的学生的信息 +select son.* from stuInfo son inner join stuInfo father on son.stuAge=father.stuSex where son.stuID=father.stuID + +--4.查询出学分一样的课程信息 +select distinct son.* from courseInfo son inner join courseInfo father on son.courseMarks=father.courseMarks where son.courseID=father.courseID + +--5.查询出参加了考试的学生的学号,姓名,课程号和分数 +select stuInfo.stuID 学号,stuName 姓名,courseInfo.courseID 课程号,score 分数 from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID + +--6.查询出参加了考试的学生的学号,课程号,课程名,课程学分和分数 +select stuInfo.stuID 学号,courseInfo.courseID 课程号,courseMarks 课程学分,score 分数 from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID + + +--7.查询出没有参加考试的学生的学号和姓名 +select stuID 学号,stuName 姓名 from stuInfo son where not exists (select * from scoreInfo father where son.stuID=father.stuID) + +--8.查询出是周六周天来报到的学生 +select stuName 学生姓名 from stuInfo where DATEPART(WEEKDAY,time)=1 or DATEPART(WEEKDAY,time)=7 + +--9.查询出姓名中有字母a的学生的信息 +select * from stuInfo where stuName like'%a%' + +--10.查询出选修了2门课程以上的并且考试平均分在70以上的学生的学号和考试平均分以及选修课程的数量 + +select stuInfo.stuID 学号,avg(score) 平均分, count(courseName)选修的课程的数量 from stuInfo inner join scoreInfo on stuInfo.stuID=scoreInfo.stuID +inner join courseInfo on scoreInfo.courseID=courseInfo.courseID +group by stuInfo.stuID +having avg(score)>70 and count(courseName)>2 + + diff --git "a/39\350\256\270\346\231\250/\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/39\350\256\270\346\231\250/\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..7b44821a6212e20e535c7f5677f18ab71497a1b8 --- /dev/null +++ "b/39\350\256\270\346\231\250/\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,102 @@ +create database 阶段二作业二; +go +use 阶段二作业二; +go +--创建上网卡信息表tbl_card +create table tbl_card( +ID nvarchar(50) primary key, --卡号 +PassWard nvarchar(50) , --密码 +Balance int, --卡上的余额 +UseName nvarchar(50) --该上网卡所属的用户名 +); + +--创建网吧机器说明表tbl_computer +create table tbl_computer( +ID nvarchar(50) primary key, --机器编号 +OnUse tinyint, --该机器是否正在使用 +Note int --该机器的说明 +); + +--创建上网记录表 +create table tbl_record( +ID nvarchar(50) primary key, --记录编号 +CardID nvarchar(50) references tbl_card(id), --本次上网的卡号 +ComputerID nvarchar(50) references tbl_computer(id), --本次上网记录所使用的机器号 +BeginTime datetime, --本次上网记录的开始时间 +EndTime datetime, --本次上网记录的结束时间 +Fee money --本次上网的费用 +); + +insert into tbl_card(ID,PassWard,Balance,UseName) +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-07-15 19:00:00','2007-07-15 21:00:00',20), +(34,'0025_bbd','02','2006-12-25 18:00:00','2006-12-25 22:00:00',23), +(45,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(46,'0023_ABC','03','2006-12-22 15:26:00','2006-12-22 22:55:00',6), +(47,'0023_ABC','03','2006-12-23 15:26:00','2006-12-23 22:55:00',50), +(48,'0023_ABC','03','2007-01-06 15:26:00','2007-01-06 22:55:00',6), +(55,'0023_ABC','03','2006-07-21 15:26:00','2006-07-21 22:55:00',50), +(64,'0045_YGR','04','2006-12-24 18:00:00','2006-12-24 22:00:00',3), +(65,'0025_bbd','02','2006-12-28 18:00:00','2006-12-28 22:00:00',23), +(98,'0025_bbd','02','2006-12-26 18:00:00','2006-12-26 22:00:00',23); + +select * from tbl_card +select * from tbl_computer +select * from tbl_record + +--1. 查询出用户名为'张军'的上网卡的上网记录,要求显示卡号,用户名,机器编号、开始时间、结束时间,和消费金额,并按消费金额降序排列 +select CardID 卡号,UseName 用户名,ComputerID 机器编号,BeginTime 开始时间,EndTime 结束时间,Fee 消费金额 +from tbl_card inner join tbl_record on +tbl_card.ID=tbl_record.CardID +where UseName='张军' 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 * from tbl_card left join tbl_record on tbl_card.ID=tbl_record.CardID where Fee is null + +--5. 将密码与用户名一样的上网卡信息查询出来 +select * from tbl_card where PassWard=UseName + +--6. 查询出使用次数最多的机器号和使用次数 +select top 1 ComputerID 机器号, count(*) 使用次数 from tbl_record group by ComputerID order by count(*) desc + +--7. 查询出卡号是以'ABC'结尾的卡号,用户名,上网的机器号和消费金额 +select CardID 卡号, UseName 用户名, ComputerID 机器号, Fee 消费金额 from tbl_card inner join tbl_record on tbl_card.ID=tbl_record.CardID +where CardID like '%ABC' + +--8. 查询出是周六、周天上网的记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select CardID 卡号, UseName 用户名, ComputerID 机器号, Fee 消费金额,BeginTime 开始时间,EndTime 结束时间 from tbl_card inner join tbl_record on tbl_card.ID=tbl_record.CardID +where DATEPART(WEEKDAY,BeginTime)=1 or DATEPART(WEEKDAY,BeginTime)=7 + +--9. 查询成一次上网时间超过12小时的的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select CardID 卡号, UseName 用户名, ComputerID 机器号, Fee 消费金额,BeginTime 开始时间,EndTime 结束时间 from tbl_card inner join tbl_record on tbl_card.ID=tbl_record.CardID +where EndTime-BeginTime>12 + +--10. 查询除消费金额排列前三名(最高)的上网记录,要求显示上网的卡号,用户名,机器号,开始时间、结束时间和消费金额 +select top 3 CardID 卡号, UseName 用户名, ComputerID 机器号, Fee 消费金额,BeginTime 开始时间,EndTime 结束时间 from tbl_card inner join tbl_record on tbl_card.ID=tbl_record.CardID +where Fee not in( +select top 3 Fee from tbl_record order by Fee desc) + + diff --git "a/39\350\256\270\346\231\250/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/98.\347\273\203\344\271\2402.sql" "b/39\350\256\270\346\231\250/\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..75c3b40df262bcaa9a25e2fc99ea11ddcd368ab3 --- /dev/null +++ "b/39\350\256\270\346\231\250/\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,26 @@ +create database Bank; +use Bank; +create table AccountInfo( +AccountId int identity not null primary key, +AccountCode varchar(20) not null unique, +AccountPhone varchar(20) not null, +RealName varchar(20) not null, +OpenTime smalldatetime not null default getdate(),); +create table BankCard( +CardNo varchar(30) primary key, +AccountId int not null, +foreign key (AccountId) references AccountInfo(AccountId), +CardPwd varchar(30) not null, +CardBalance money not null default 0.00, +CardState tinyint not null default 1, +CardTime varchar(30) not null default getdate(), +); +alter table BankCard alter column CardTime smalldatetime not null; +create table CardExchange( +ExchangeId int identity primary key, +CardNo varchar(30) not null, +MoneyInBank money not null check(MoneyInBank>=0), +MoneyOutBank money not null check(MoneyOutBank>=0), +ExchangeTime smalldatetime not null, +foreign key (CardNo) references BankCard(CardNo), +);