我在这里: 首页 ? 面试试题 ? 浏览文章: SQL Server面试题
« 面试时如何用英语自我介绍 东软java面试题 »

SQL Server面试题




内容摘要:这是一家从事程序外包工作的外企招聘后台开发或与后台开发相关的SQL Server高级程序员的试题。
关键词:SqlServer面试题  数据库面试题  
本文地址:http://www.teecool.com/post/2008071001.html
内容正文:

Question: How can I list non-contignous data?
In database pubs, I create a table test using statement as below, and I insert several row as below

 程序代码
create table test
( id int primary key )
go

insert into test values (1 )
insert into test values (2 )
insert into test values (3 )
insert into test values (4 )
insert into test values (5 )
insert into test values (6 )
insert into test values (8 )
insert into test values (9 )
insert into test values (11)
insert into test values (12)
insert into test values (13)
insert into test values (14)
insert into test values (18)
insert into test values (19)
go


Now I want to list the result of the non-contignous row as below,how can I do it?

 程序代码
Missing after Missing before
------------- --------------
6             8
9             11

 


Answer :
select id from test t where not exists(select 1 from test where id=t.id+1)
or not exists(select 1 from test where id=t.id-1)

Question: How can I list all book with prices greather than the average price of books of the same type?
In database pubs, have a table named titles , its column named price mean the price of the book, and another named type mean the type of books.
Now I want to get the result as below:

 程序代码
type         title                                                                            price                
------------ -------------------------------------------------------------------------------- ---------------------
business     The Busy Executive's Database Guide                                              19.9900




Answer :

 程序代码
select a.type,a.title,a.price from titles a,
(select type,price=avg(price) from titles group by type)b
where a.type=b.type and a.price>b.price

SQL Server面试题一文有面试题库网收集自互联网,并非本站原创,如原作者发现SQL Server面试题一文,请及时告知本站,本站会作出相关处理,谢谢!!!(联系方式:百度空间留言)

最近发表