【正文】
price is null, and “other” for all other prices?select bookid,bookname,price=case when price is null then ‘unknown’when price between 10 and 20 then ’10 to 20′ else price endfrom books21. Question3:Can you use a SQL statement to finding duplicate values!How can I find authors with the same last name?You can use the table authors in datatabase pubs. I want to get the result as below:Output:au_lname number_dups————————————— ———–Ringer 2(1 row(s) affected)Answer 3select au_lname,number_dups=count(1) from authors group by au_lname22. Question4:Can you create a crosstab report in my SQL Server!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?You can use the table sales and stores in datatabase pubs.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.I want to get the result look like as below:Output:stor_name Total Qtr1 Qtr2 Qtr3 Qtr4————————————— ———– ———– ———– ———– ———–Barnum’s 50 0 50 0 0Bookbeat 55 25 30 0 0DocUMat: Quality Laundry and Books 85 0 85 0 0Fricative Bookshop 60 35 0 0 25Total 250 60 165 0 25Answer 4:用動(dòng)態(tài)SQL實(shí)現(xiàn)23. Question5: The Fastest Way to Repile All Stored ProceduresI have a problem with a database running in SQL Server (Service Pack 4). We moved the database (object transfer) from one 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 repile?Tips: sp_repile can replie a store procedure each timeAnswer 5:在執(zhí)行存儲(chǔ)過(guò)程時(shí),使用 with repile 選項(xiàng)強(qiáng)制編譯新的計(jì)劃;使用sp_repile系統(tǒng)存儲(chǔ)過(guò)程強(qiáng)制在下次運(yùn)行時(shí)進(jìn)行重新編譯24. Question6: How can I add row numbers to my result set?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?Result:lineno title_id———– ——–1 BU10322 BU11113 BU20754 BU78325 MC22226 MC30217 MC30268 PC10359 PC888810 PC999911 PS137212 PS209113 PS210614 PS333315 PS777716 TC321817 TC420318 TC7777Answer 6:–SQL 2005的寫(xiě)法select row_number() as line_no ,title_id from titles–SQL 2000的寫(xiě)法select line_no identity(int,1,1),title_id into t from titlesselect * from tdrop table t25. Question 7: Can you tell me what the difference of two SQL statements at performance of execution?Statement 1:if NOT EXISTS ( select * from publishers where state = ‘NY’)beginSELECT ‘Sales force needs to penetrate New York market’endelsebeginSELECT ‘We have publishers in New York’endStatement 2:if EXISTS ( select * from publishers where state = ‘NY’)beginSELECT ‘We have publishers in New York’endelsebeginSELECT ‘Sales force needs to penetrate New York market’endAnswer 7:不同點(diǎn):執(zhí)行時(shí)的事務(wù)數(shù),處理時(shí)間,從客戶端到服務(wù)器端傳送的數(shù)據(jù)量大小26. Question8: How can I list all California authors regardless of whether they have written a book?In database pubs, have a table authors and titleauthor , table authors has a column state, and titleauhtor have books each author written.CA behalf of california in table authors.Answer 8:select * from authors where state=’CA’27. Question9: How can I get a list of the stores that have bought both ‘bussiness’ and ‘mod_cook’ type books?In database pubs, use three table stores,sales and titles to implement this requestment. Now I want to get the result as below:stor_id stor_name—— —————————————…7896 Fricative Bookshop………Answer 9:select distinct , from stores a,sales b,titles cwhere = and = and =’business’ andexists(select 1 from sales k,titles g where stor_id=and = and =’mod_cook’)28. Question10: How can I list noncontignous data?In database pubs, I create a table test using statement as below, and I insert several row as belowcreate table test( id int primary key )goinsert 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)goNow I want to list the result of the noncontignous row as below,how can I do it?Missing after Missing before———— ————–6 89 11…Answer 10:select id from test t where not exists(select 1 from test where id=+1)or not exists(select 1 from test where id=)29. Question11: 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 …………Answer 11:select , from titles a,(select type,price=avg(price) from titles group by type)bwhere = and 試題點(diǎn)評(píng):通覽整個(gè)試題,我們不難發(fā)現(xiàn),這份試題是針對(duì)SQL Server數(shù)據(jù)庫(kù)人員的。而從難度分析上來(lái)看,這份試題也屬于同類試題中比較難的了。之所以說(shuō)它難,首先是限定時(shí)間的全英文試題;其次,盡管這份試題主要是考核開(kāi)發(fā)能力,但卻涉及到了算法的選擇和性能的調(diào)優(yōu);最后,這份試題還夾進(jìn)了SQL Server數(shù)據(jù)庫(kù)的升級(jí)問(wèn)題。因此,綜上所述,我們估計(jì)這是一家從事程序外包工作的外企招聘后臺(tái)開(kāi)發(fā)或與后臺(tái)開(kāi)發(fā)相關(guān)的SQL Server高級(jí)程序員的試題。