SQL试题某外企SQL Server面试题【2006-04-19 16:09】【IT 专家网】【IT 专家网社区】
SQL试题Question 
1:Can you use a batch SQL or store procedure to calculating the Number of Days in a Month 
SQL试题Answer 
1:找出当月的天数 
SQL试题
select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime)))) 
SQL试题
SQL试题Question2:Can you 
use a SQL statement to calculating it! 
SQL试题How can I 
print "10 to 20for books that sell for between $10 and $20,"unknown" for books whose price is nulland "other" for all other prices? 
SQL试题Answer 
2: 
SQL试题
select bookid,bookname,price=case when price is null then 'unknown' 
SQL试题
when price between 10 and 20 then '10 to 20' else price end 
SQL试题
from books 
SQL试题
SQL试题Question3:Can you 
use a SQL statement to finding duplicate values
SQL试题How can I find authors 
with the same last name? 
SQL试题You can 
use the table authors in datatabase pubs. I want to get the result as below: 
SQL试题Output: 
SQL试题au_lname number_dups 
SQL试题
---------------------------------------- ----------- 
SQL试题
Ringer 2 
SQL试题(
1 row(s) affected) 
SQL试题Answer 
3 
SQL试题
select au_lname,number_dups=count(1from authors group by au_lname 
SQL试题
SQL试题Question4:Can you 
create a cross-tab report in my SQL Server! 
SQL试题How can I get the report about sale quality 
for each store and each quarter and the total sale quality for each quarter at year 1993
SQL试题You can 
use the table sales and stores in datatabase pubs. 
SQL试题
Table Sales record all sale detail item for each store. Column store_id is the id of each store, ord_date is the order date of each sale item, and column qty is the sale qulity. Table stores record all store information. 
SQL试题I want 
to get the result look like as below: 
SQL试题Output: 
SQL试题stor_name Total Qtr1 Qtr2 Qtr3 Qtr4 
SQL试题
---------------------------------------- ----------- ----------- ----------- ----------- ----------- 
SQL试题--
Barnum's 50 0 50 0 0 
SQL试题
Bookbeat 55 25 30 0 0 
SQL试题Doc
-U-Mat: Quality Laundry and Books 85 0 85 0 0 
SQL试题Fricative Bookshop 
60 35 0 0 25 
SQL试题Total 
250 60 165 0 25 
SQL试题
SQL试题Answer 
4:用动态SQL实现 
SQL试题
SQL试题Question5: The Fastest Way 
to Recompile All Stored Procedures 
SQL试题I have a problem 
with a database running in SQL Server 6.5 (Service Pack 4). We moved the database (object transfer) from one
SQL试题
--machine to another last night, and an error (specific to a stored procedure) is cropping up. However, I can't tell which procedure is causing it. Permissions are granted in all of our stored procedures; is there a way from the isql utility to force all stored procedures to recompile? 
SQL试题

SQL试题Tips: sp_recompile can recomplie a store 
procedure each time 
SQL试题Answer 
5:在执行存储过程时,使用 with recompile 选项强制编译新的计划;使用sp_recompile系统存储过程强制在下次运行时进行重新编译 
SQL试题
SQL试题Question6: How can I 
add row numbers to my result set
SQL试题
In database pubs, have a table titles , now I want the result shown as below,each row have a row number, how can you do that? 
SQL试题Result: 
SQL试题line
-no title_id 
SQL试题
----------- -------- 
SQL试题
1 BU1032 
SQL试题
2 BU1111 
SQL试题
3 BU2075 
SQL试题
4 BU7832 
SQL试题
5 MC2222 
SQL试题
6 MC3021 
SQL试题
7 MC3026 
SQL试题
8 PC1035 
SQL试题
9 PC8888 
SQL试题
10 PC9999 
SQL试题
11 PS1372 
SQL试题
12 PS2091 
SQL试题
13 PS2106 
SQL试题
14 PS3333 
SQL试题
15 PS7777 
SQL试题
16 TC3218 
SQL试题
17 TC4203 
SQL试题
18 TC7777 
SQL试题
SQL试题Answer 
6: 
SQL试题
--SQL 2005的写法 
SQL试题
select row_number() as line_no ,title_id from titles 
SQL试题
--SQL 2000的写法 
SQL试题
select line_no identity(int,1,1),title_id into #t from titles 
SQL试题
select * from #t 
SQL试题
drop table #t 
SQL试题
SQL试题Question 
7: Can you tell me what the difference of two SQL statements at performance of execution? 
SQL试题Statement 
1
SQL试题
if NOT EXISTS ( select * from publishers where state = 'NY'
SQL试题
begin 
SQL试题
SELECT 'Sales force needs to penetrate New York market' 
SQL试题
end 
SQL试题
else 
SQL试题
begin 
SQL试题
SELECT 'We have publishers in New York' 
SQL试题
end 
SQL试题Statement 
2
SQL试题
if EXISTS ( select * from publishers where state = 'NY'
SQL试题
begin 
SQL试题
SELECT 'We have publishers in New York' 
SQL试题
end 
SQL试题
else 
SQL试题
begin 
SQL试题
SELECT 'Sales force needs to penetrate New York market' 
SQL试题
end 
SQL试题Answer 
7:不同点:执行时的事务数,处理时间,从客户端到服务器端传送的数据量大小 
SQL试题
SQL试题Question8: How can I list 
all California authors regardless of whether they have written a book? 
SQL试题
In database pubs, have a table authors and titleauthor , table authors has a column state, and titleauhtor have books each author written. 
SQL试题CA behalf 
of california in table authors. 
SQL试题Answer 
8: 
SQL试题
select * from authors where state='CA' 
SQL试题
SQL试题Question9: How can I get a list 
of the stores that have bought both 'bussiness' and 'mod_cook' type books? 
SQL试题
In database pubs, use three table stores,sales and titles to implement this requestment. 
SQL试题Now I want 
to get the result as below: 
SQL试题stor_id stor_name 
SQL试题
------- ---------------------------------------- 
SQL试题
SQL试题 
SQL试题
7896 Fricative Bookshop 
SQL试题SQL试题 
SQL试题SQL试题 
SQL试题SQL试题 
SQL试题Answer 
9: 
SQL试题
select distinct a.stor_id, a.stor_name from stores a,sales b,titles c 
SQL试题
where a.stor_id=b.stor_id and b.title_id=c.title_id and c.type='business' and 
SQL试题
exists(select 1 from sales k,titles g where stor_id=b.stor_id 
SQL试题
and k.title_id=g.title_id and g.type='mod_cook'
SQL试题
SQL试题
SQL试题
SQL试题Question10: How can I list non
-contignous data? 
SQL试题
In database pubs, I create a table test using statement as below, and I insert several row as below 
SQL试题
create table test 
SQL试题( id 
int primary key ) 
SQL试题
go 
SQL试题
SQL试题
insert into test values (1 ) 
SQL试题
insert into test values (2 ) 
SQL试题
insert into test values (3 ) 
SQL试题
insert into test values (4 ) 
SQL试题
insert into test values (5 ) 
SQL试题
insert into test values (6 ) 
SQL试题
insert into test values (8 ) 
SQL试题
insert into test values (9 ) 
SQL试题
insert into test values (11
SQL试题
insert into test values (12
SQL试题
insert into test values (13
SQL试题
insert into test values (14
SQL试题
insert into test values (18
SQL试题
insert into test values (19
SQL试题
go 
SQL试题
SQL试题Now I want 
to list the result of the non-contignous row as below,how can I do it? 
SQL试题Missing after Missing before 
SQL试题
------------- -------------- 
SQL试题
6 8 
SQL试题
9 11 
SQL试题SQL试题 
SQL试题
SQL试题
SQL试题
SQL试题
SQL试题Answer 
10: 
SQL试题
select id from test t where not exists(select 1 from test where id=t.id+1
SQL试题
or not exists(select 1 from test where id=t.id-1
SQL试题
SQL试题Question11: How can I list 
all book with prices greather than the average price of books of the same type? 
SQL试题
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. 
SQL试题Now I want 
to get the result as below: 
SQL试题type title price 
SQL试题
------------ -------------------------------------------------------------------------------- --------------------- 
SQL试题--
business The Busy Executive's Database Guide 19.9900 
SQL试题
SQL试题 
SQL试题SQL试题 
SQL试题SQL试题 
SQL试题SQL试题 
SQL试题
SQL试题Answer 
11: 
SQL试题
select a.type,a.title,a.price from titles a, 
SQL试题(
select type,price=avg(price) from titles group by type)b 
SQL试题
where a.type=b.type and a.price>b.price 
SQL试题
SQL试题试题点评:通览整个试题,我们不难发现,这份试题是针对SQL Server数据库人员的。而从难度分析上来看,这份试题也属于同类试题中比较难的了。之所以说它难,首先是限定时间的全英文试题;其次,尽管这份试题主要是考核开发能力,但却涉及到了算法的选择和性能的调优;最后,这份试题还夹进了SQL Server数据库的升级问题。因此,综上所述,我们估计这是一家从事程序外包工作的外企招聘后台开发或与后台开发相关的SQL Server高级程序员的试题。

相关文章: