sql面试题集汇总

上传人:xzh****18 文档编号:34576181 上传时间:2018-02-25 格式:DOC 页数:5 大小:32.50KB
返回 下载 相关 举报
sql面试题集汇总_第1页
第1页 / 共5页
sql面试题集汇总_第2页
第2页 / 共5页
sql面试题集汇总_第3页
第3页 / 共5页
sql面试题集汇总_第4页
第4页 / 共5页
sql面试题集汇总_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《sql面试题集汇总》由会员分享,可在线阅读,更多相关《sql面试题集汇总(5页珍藏版)》请在金锄头文库上搜索。

1、SQL 经典面试题及答案2007 年 07 月 27 日 星期五 上午 08:421.一道 SQL 语句面试题,关于 group by表内容:2005-05-09 胜2005-05-09 胜2005-05-09 负2005-05-09 负2005-05-10 胜2005-05-10 负2005-05-10 负如果要生成下列结果, 该如何写 sql 语句?胜 负2005-05-09 2 22005-05-10 1 2-create table #tmp(rq varchar(10),shengfu nchar(1)insert into #tmp values(2005-05-09,胜)inse

2、rt into #tmp values(2005-05-09,胜)insert into #tmp values(2005-05-09,负)insert into #tmp values(2005-05-09,负)insert into #tmp values(2005-05-10,胜)insert into #tmp values(2005-05-10,负)insert into #tmp values(2005-05-10,负)1)select rq, sum(case when shengfu=胜 then 1 else 0 end)胜,sum(case when shengfu=负 t

3、hen 1 else 0 end)负 from #tmp group by rq2) select N.rq,N.勝,M. 負 from (select rq,勝=count(*) from #tmp where shengfu=胜group by rq)N inner join(select rq,負=count(*) from #tmp where shengfu=负group by rq)M on N.rq=M.rq3)select a.col001,a.a1 胜,b.b1 负 from(select col001,count(col001) a1 from temp1 where co

4、l002=胜 group by col001) a,(select col001,count(col001) b1 from temp1 where col002=负 group by col001) bwhere a.col001=b.col0012.请教一个面试中遇到的 SQL 语句的查询问题表中有 A B C 三列, 用 SQL 语句实现:当 A 列大于 B 列时选择 A 列否则选择 B列,当 B 列大于 C 列时选择 B 列否则选择 C 列。-select (case when ab then a else b end ),(case when bc then b esle c end

5、)from table_name3.面试题:一个日期判断的 sql 语句?请取出 tb_send 表中日期 (SendTime 字段)为当天的所有记录 ?(SendTime字段为 datetime 型,包含日期与时间 )-select * from tb where datediff(dd,SendTime,getdate()=04.有一张表,里面有 3 个字段:语文,数学,英语。其中有 3 条记录分别表示语文 70 分,数学 80 分,英语 58 分,请用一条 sql 语句查询出这三条记录并按以下条件显示出来(并写出您的思路): 大于或等于 80 表示优秀,大于或等于 60 表示及格,小于

6、60 分表示不及格。显示格式: 语文 数学 英语 及格 优秀 不及格 -select(case when 语文=80 then 优秀when 语文=60 then 及格else 不及格) as 语文,(case when 数学=80 then 优秀when 数学=60 then 及格else 不及格) as 数学,(case when 英语=80 then 优秀when 英语=60 then 及格else 不及格) as 英语,from table5.在 sqlserver2000 中请用 sql 创建一张用户临时表和系统临时表,里面包含两个字段 ID 和 IDValues,类型都是 int

7、型,并解释下两者的区别 ?-用户临时表:create table #xx(ID int, IDValues int)系统临时表:create table #xx(ID int, IDValues int)区别:用户临时表只对创建这个表的用户的 Session 可见 ,对其他进程是不可见的.当创建它的进程消失时这个临时表就自动删除.全局临时表对整个 SQL Server 实例都可见,但是所有访问它的 Session 都消失的时候,它也自动删除 .6.sqlserver2000 是一种大型数据库,他的存储容量只受存储介质的限制,请问它是通过什么方式实现这种无限容量机制的。-它的所有数据都存储在数据

8、文件中(*.dbf), 所以只要文件够大,SQL Server 的存储容量是可以扩大的.SQL Server 2000 数据库有三种类型的文件:主要数据文件主要数据文件是数据库的起点,指向数据库中文件的其它部分。每个数据库都有一个主要数据文件。主要数据文件的推荐文件扩展名是 .mdf。次要数据文件次要数据文件包含除主要数据文件外的所有数据文件。有些数据库可能没有次要数据文件,而有些数据库则有多个次要数据文件。次要数据文件的推荐文件扩展名是 .ndf。日志文件日志文件包含恢复数据库所需的所有日志信息。每个数据库必须至少有一个日志文件,但可以不止一个。日志文件的推荐文件扩展名是 .ldf。7.请用

9、一个 sql 语句得出结果从 table1,table2 中取出如 table3 所列格式数据,注意提供的数据及结果不准确,只是作为一个格式向大家请教。如使用存储过程也可以。table1月份 mon 部门 dep 业绩 yj-一月份 01 10一月份 02 10一月份 03 5二月份 02 8二月份 04 9三月份 03 8table2部门 dep 部门名称 dname- 01 国内业务一部02 国内业务二部03 国内业务三部04 国际业务部table3 (result)部门 dep 一月份 二月份 三月份-01 10 null null02 10 8 null03 null 5 804 nu

10、ll null 9-1)select a.部门名称 dname,b.业绩 yj as 一月份,c. 业绩 yj as 二月份,d.业绩 yj as 三月份from table1 a,table2 b,table2 c,table2 dwhere a.部门 dep = b.部门 dep and b.月份 mon = 一月份 anda.部门 dep = c.部门 dep and c.月份 mon = 二月份 anda.部门 dep = d.部门 dep and d.月份 mon = 三月份 and2)select a.dep,sum(case when b.mon=1 then b.yj else

11、 0 end) as 一月份,sum(case when b.mon=2 then b.yj else 0 end) as 二月份,sum(case when b.mon=3 then b.yj else 0 end) as 三月份,sum(case when b.mon=4 then b.yj else 0 end) as 四月份,sum(case when b.mon=5 then b.yj else 0 end) as 五月份,sum(case when b.mon=6 then b.yj else 0 end) as 六月份,sum(case when b.mon=7 then b.y

12、j else 0 end) as 七月份,sum(case when b.mon=8 then b.yj else 0 end) as 八月份,sum(case when b.mon=9 then b.yj else 0 end) as 九月份,sum(case when b.mon=10 then b.yj else 0 end) as 十月份,sum(case when b.mon=11 then b.yj else 0 end) as 十一月份,sum(case when b.mon=12 then b.yj else 0 end) as 十二月份,from table2 a left join table1 b on a.dep=b.dep8.华为一道面试题一个表中的 Id 有多个记录,把所有这个 id 的记录查出来,并显示共有多少条记录数。-select id, Count(*) from tb group by id having count(*)1select * from(select count(ID) as count from table group by ID)T where T.count1

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 试题/考题 > 高中试题/考题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号