1 Star 0 Fork 48

段文杰/SQL Server作业仓库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SQLQuery1.1.sql 5.05 KB
一键复制 编辑 原始数据 按行查看 历史
五星好市民.林 提交于 2021-03-23 22:22 . 林程铭第7次作业
create database Student--学生信息数据库
use Student
go
create table student--学生信息表
(
stuNO nvarchar(6) primary key,
stuName nvarchar(5),
stuAge int ,
stuAddress nvarchar(10),
stuSeat int,
stuSex int --(0为女,1为男)
);
go
create table examinfo--考试信息表
(
examNo int identity primary key,
stuNO nvarchar(6),
writtenExam int ,
labExam int
);
go
-----------------
alter table student
drop constraint PK__student__AEC9530057BCBB88
insert into student(stuNO,stuName,stuAge,stuAddress,stuSeat,stuSex)
values('s2501','张秋利',20,'美国硅谷',1,1),
('s2502','李思文',18,'湖北武汉',2,0),
('s2503','马文才',22,'湖南长沙',3,1),
('s2404','欧阳俊雄',21,'湖北武汉',4,0),
('s2505','梅超风',20,'湖北武汉',5,1),
('s2506','陈玄风',19,'美国硅谷',6,1),
('s2507','陈风',20,'美国硅谷',7,0)
set identity_insert examinfo on
insert into examinfo(examNo,stuNO,writtenExam,labExam)
values(1,'s2501',50,70),
(2,'s2502',60,65),
(3,'s2503',86,85),
(4,'s2504',40,80),
(5,'s2505',70,90),
(6,'s2506',85,90)
select *from examinfo
select *from student
--1.查询学生信息表(student)中所有列信息,给每列取上中文名称
select 学生编号=stuNo,学生姓名=stuName,学生年龄=stuAge,学生住址=stuAddress,学生桌位=stuSeat,学生性别=stuSex from student
--2.查询学生信息表(student)中的姓名,年龄和地址三列的信息
select 学生姓名=stuName,学生年龄=stuAge ,学生住址=stuAddress from student
--3.查询学生分数表(examinfo)中的学号,笔试和机试三列的信息,并为这三列取中文名字
-- 注意:要用三种方法
select 学号=examNo,笔试=writtenExam,机试=labExam from examinfo
--4.查询学生信息表(student)中的学号,姓名,地址,以及将:姓名+@+地址 组成新列 “邮箱”
select stuNO,stuName,stuAddress,邮箱=stuName+'@'+stuAddress from student
--5.查询学生分数表(examinfo)中的学生的学号,笔试,机试以及总分这四列的信息
select 学号=examNO ,笔试=writtenExam,机试=labExam from examinfo
--6.查询学生信息表(student)中学生来自哪几个地方
select distinct stuAddress from student
--7.查询学生信息表(student)中学生有哪几种年龄,并为该列取对应的中文列名
select 学生姓名=stuName ,学生年龄=stuAge from student
--8.查询学生信息表(student)中前3行记录
select top 3 * from student
--9.查询学生信息表(student)中前4个学生的姓名和座位号
select top 4 stuNO,stuName from student
--10.查询学生信息表(student)中一半学生的信息
select top 50 percent * from student
--11.将地址是湖北武汉,年龄是20的学生的所有信息查询出来
select stuAge ,stuAddress from student where stuAddress='湖北武汉' and stuAge=20
--12.将机试成绩在60-80之间的信息查询出来,并按照机试成绩降序排列(用两种方法实现)
--1.
select labExam from examinfo where labExam>=60 and labExam<=80 order by labExam desc
--2.
select labExam from examinfo where labExam between 60 and 80 order by labExam desc
--13.查询来自湖北武汉或者湖南长沙的学生的所有信息(用两种方法实现)
--1.
select stuName,stuAddress from student where stuAddress='湖北武汉' or stuAddress='湖南长沙'
--2.
select stuName ,stuAddress from student where stuAddress!='美国硅谷'
--14.查询出笔试成绩不在70-90之间的信息,并按照笔试成绩升序排列(用两种方法实现)
--1.
select writtenExam from examinfo where writtenExam<70 or writtenExam>90 order by writtenExam asc
--2.
select writtenExam from examinfo where writtenExam!>70 and writtenExam!=70 or writtenExam!<90 and writtenExam!=90 order by writtenExam asc
--15.查询年龄没有写的学生所有信息
select stuName,stuAge from student where stuAge is null
--16.查询年龄写了的学生所有信息
select stuName,stuAge from student where stuAge is not null
--17.查询姓张的学生信息
select stuName from student where stuName like'张%'
--18.查询学生地址中有‘湖’字的信息
select stuAddress from student where stuAddress like '%湖%'
--19.查询姓张但名为一个字的学生信息
select * from student where stuName like '张_'
--20.查询姓名中第三个字为‘俊’的学生的信息,‘俊’后面有多少个字不限制
select * from student where stuName like '%俊_'
--21.按学生的年龄降序显示所有学生信息
select * from student order by stuAge desc
--22.按学生的年龄降序和座位号升序来显示所有学生的信息
select * from student order by stuAge desc , stuSeat asc
--23.显示笔试第一名的学生的考试号,学号,笔试成绩和机试成绩
select 考试号=examNO ,学号=stuNO,笔试成绩=writtenExam,机试成绩=labExam from examinfo where writtenExam=
(select max(writtenExam) from examinfo )
--24.显示机试倒数第一名的学生的考试号,学号,笔试成绩和机试成绩
select 考试号=examNO ,学号=stuNO,笔试成绩=writtenExam,机试成绩=labExam from examinfo where writtenExam=
(select min(writtenExam) from examinfo )
--25.查询每个地方的学生的平均年龄
select 学生平均年龄=AVG(stuAge) from student
--26.查询男女生的分别的年龄总和
select 男女生分别平均年龄= AVG(stuAge ) from student group by stuSex
select * from student
--27.查询每个地方的男女生的平均年龄和年龄的总和
select 地址=stuAddress,年龄总和=sum(stuAge),平均年龄=avg(stuAge) from student group by stuAddress
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/duan-wenjie/sql-server-job-warehouse.git
git@gitee.com:duan-wenjie/sql-server-job-warehouse.git
duan-wenjie
sql-server-job-warehouse
SQL Server作业仓库
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385