文档介绍:SQL题
明源面试,笔试题目如下
一、SQL测试题
1 有两张表
根据给出的SQL语句,写出返回的行数分别是多少?为了形象直观的显示,我给出了sql语句执行结果。
A 学生表 B分数表
新题目
select a.* from a inner join b on =;
select a.* from a,b where =
select a.* from a left join b on =;
select a.* from a right join b on =;
select a.* from a right join b on = and <7;
select a.* from a right join b on = where <7
老题目
select b.* from a left join b on =;
select b.* from a left join b on =;
select b.* from a right join b on =;
以上语句返回的行数分别是多少?
答案:见图就知道了
(1)删除age为18-30的成绩
delete from b where in
(select id from a
where age between 18 and 35)
(2)统计每门功课前两名学生的ID,name ,subject ,score ?(很经典的,花了我很长时间)
select ,,a.* from b b1 left join a on =
where in(
select id from b where score in
(select distinct top 2 score from b where subject = order by score desc))
order by , desc
(3)实现如下格式
这是一个行转列
select ID,
sum(case when ='语文' then score end)语文,
sum(case when ='数学' then score end)数学
from b group by
注:打下划线的是要填的内容
(4)新建一个视图查询 ID,name,age,subject ,score ,如果一个学生对应有多个记录则全部显示出来?
if exists (select * from sysobjects where name='get_score')
drop view get_score;
create view get_score
as
select ,,, from a left join b on =;
(5)新建一个存储过程, 实现输入学生ID(存储过程的输入参数) , 显示学生姓名以及平均分,格式如下:李4:45
create procedure get_avgScore(***@id int)
as
declare ***@name varchar(50)
declare ***@avg float
begin
select ***@name=+':',***@avg=avg(score) from a left join b on =
where =***@id group by (+':')
print(***@name+cast(***@avg as varchar(4)))
end;
exec get_avgScore 4
题
(1)请列举有哪几种页面重定向的方法,并解释(至少两种以上)
(2)页面传值的集中方法,并分析其利弊(至少两种以上)
(3)说说URL传值应注意的问题(至少两点以上)
这是经典的传值方式, ?id=1&name=c; 不过所传递的值是会显示在浏览器的地址栏上的,而且不能传递对象。所以这种方法一般用于传递的值少且安全性要求不高的情况下。
这种方法将每份数据存储于服务器变量中,可以传递比较多的数据,并且安全性较高,所以常用于用户身份的验证功能中。不过,Session变量如果存储过多的数