sql语句面试题1

上传人:小** 文档编号:89127323 上传时间:2019-05-19 格式:DOC 页数:9 大小:28.50KB
返回 下载 相关 举报
sql语句面试题1_第1页
第1页 / 共9页
sql语句面试题1_第2页
第2页 / 共9页
sql语句面试题1_第3页
第3页 / 共9页
sql语句面试题1_第4页
第4页 / 共9页
sql语句面试题1_第5页
第5页 / 共9页
点击查看更多>>
资源描述

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

1、1.一道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-select rq,shengfu,shengfu from #tmp where rq in(2005-05-09,2005-05-10) -create table #tmp(rq varchar(10),shengfu nchar(1)insert into #t

2、mp values(2005-05-09,胜)insert 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)

3、胜,sum(case when shengfu=负 then 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.rq,a.a1 胜,b.b1 负 from (select rq,count(rq) a1 from

4、 #tmp where shengfu=胜 group by rq) a,(select rq,count(rq) b1 from #tmp where shengfu=负 group by rq) b where a.rq=b.rq2.请教一个面试中遇到的SQL语句的查询问题表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。-create table #tmp(A int,B int,C int)insert into #tmp values(10,20,30)-insert into #tmp values(10,30,20

5、)-insert into #tmp values(40,10,20)select * from #tmpselect (case when ab then a else b end),(case when bc then b else c end ) from #tmp3.面试题:一个日期判断的sql语句?请取出tb_send表中日期(SendTime字段)为当天的所有记录?(SendTime字段为datetime型,包含日期与时间)-select * from #tmp where datediff(dd,rq,getdate()=0select * from #tmp where rq=

6、rtrim(convert(varchar,getdate(),23)4.有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路): 大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。 显示格式: 语文 数学 英语 及格 优秀 不及格 -create table #tmp(语文 int,数学 int ,英语 int)insert into #tmp values(70,80,58)-insert into #tmp values(100,50,60)sele

7、ct * from #tmpselect (case when 语文 =80 then 优秀 when 语文 =60 then 及格 else 不及格 end ) 语文, (case when 数学 =80 then 优秀 when 数学 =60 then 及格 else 不及格 end ) 数学, (case when 英语 =80 then 优秀 when 英语 =60 then 及格 else 不及格 end ) 英语from #tmp5.在sqlserver2000中请用sql创建一张用户临时表和系统临时表,里面包含两个字段ID和IDValues,类型都是int型,并解释下两者的区别?

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

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

10、2中取出如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 null 02 10 8 null 03 null 5 8 04 null null 9-create table #A(mon

11、 varchar(10),dep varchar(10) ,yj int)insert into #A values(一月份,01,10)insert into #A values(一月份,02,10)insert into #A values(一月份,03,5)insert into #A values(二月份,02,8)insert into #A values(二月份,04,9)insert into #A values(三月份,03,8)select * from #Acreate table #B(dep varchar(10),dname varchar(20)insert int

12、o #B values(01,国内业务一部)insert into #B values(02,国内业务二部)insert into #B values(03,国内业务三部)insert into #B values(04,国际业务部)select * from #b-1)select dep,(select SUM(yj) from #A where MON=一月份 and #A.dep=#B.dep) 一月份, (select SUM(yj) from #A where MON=二月份 and #A.dep=#B.dep) 二月份, (select SUM(yj) from #A where MON=三月份 and #A.dep=#B.dep) 三月份 from #B 2)select b.dep,dname, sum(case when a.mon=一月份 then a.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

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