当前位置: 代码迷 >> SQL >> 容易sql的题
  详细解决方案

容易sql的题

热度:74   发布时间:2016-05-05 11:05:23.0
简单sql的题

insert into stuinfo (stuName,stuNo,stuAge,stuAddress)
values('张秋丽', 's25301',18, '北京海淀')
insert into stuinfo (stuName,stuNo,stuSex,stuAge,stuAddress)
values('李斯文','s25303','女',22, '河南洛阳')
insert into stuinfo (stuName,stuNo,stuAge)
values('李文才', 's25302',31)
insert stuinfo(stuName,stuNo,stuAge,stuAddress)
values('欧阳俊雄', 's25304',28, '新疆威武哈')

insert into stumarks(examNo,stuNo,writtenExam,labExam)
values('E200507001','s25301',80,58)
insert into stumarks(examno,stuno,writtenexam)
values('E200507002','s25302',50)
insert into stumarks(examno,stuno,writtenexam,labexam)
values('E200507003','s25303',97,82)
--查询:查询表
select * from stuinfo
select * from stumarks
--第二题:查询男同学名单
select * from stuinfo where stusex='男'

--第三题:查询笔试成绩在75-100分之间的学院,显示学号,笔试成绩
select??? stuno,writtenexam from stumarks where writtenexam between 74 and 100
--第四题:查询参加本次考试的学员成绩,包括学员姓名,笔试成绩和机试成绩。
select??? stuname,writtenexam ,labexam from stuinfo inner join stumarks on stuinfo.stuno=stumarks.stuno
--第五题:统计考试平均分和机试平均分
select avg(writtenexam),avg(labexam) from stumarks
--第六题:统计参加本次考试学员人数
select count(*)from stuinfo
--第七题:查询笔试或者机试成绩60分一下的人数
select count(*)from stumarks where writtenexam<60 or labexam<60
--第八题:查询学员成绩,学员学号,笔试成绩,机试成绩及平均分
select stuno as 学号,writtenexam as 笔试成绩,labexam as 机试成绩,(writtenexam+labexam)/2 as 平均分 from stumarks
--第九题:平均分从高到低排,显示学号,平均分
select stuNo as 学号,(writtenExam+labExam)/2 as 平均分 from stuMarks order by 平均分 desc
--第十题:从高到低排名,显示姓名,笔试成绩,机试成绩和平均分

select??? stuInfo.stuName as 姓名,stuMarks.writtenExam as 笔试成绩, stuMarks.labExam as 上机成绩,(writtenExam+labExam)/2 as 平均分
from stuInfo inner join stuMarks on(stuInfo.stuNo=stuMarks.stuNo) order by 平均分 desc
--第十一题:根据平均分,显示前两名信息,包括姓名,笔试成绩,机试成绩,平均分
select top 2 stuInfo.stuName as 姓名,stuMarks.writtenExam as 笔试成绩, stuMarks.labExam as 上机成绩,(writtenExam+labExam)/2 as 平均分
from stuInfo inner join stuMarks on(stuInfo.stuNo=stuMarks.stuNo) order by 平均分 desc

--修改部分:

--第十三题:
upDate???? stuMarks set writtenExam=writtenExam+5
update stuMarks set writtenExam=100 where writtenExam >100
-----------------------------------------------------------------------------
函数从 SQL Server 返回当前的时间和日期。
select getdate()
ABS(-6)=6 取绝对值
select abs(-34)

select * from stuinfo where stuage>18
select * from stuinfo
select * from stumarks
delete from stuinfo where stuno='s25303

  相关解决方案