程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 某外企SQL Server面試題

某外企SQL Server面試題

編輯:關於SqlServer

Question 1:Can you use a batch SQL or store procedure to calculating the Number of Days in a Month

Answer 1:找出當月的天數

select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))

Question2:Can you use a SQL statement to calculating it!

How can I print "10 to 20" for books that sell for between $10 and $20,"unknown" for books whose price is null, and "other" for all other prices?

Answer 2:

select bookid,bookname,price=case when price is null then   'unknown'

when price between 10 and 20 then '10 to 20' else price end

from books

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 3

select au_lname,number_dups=count(1) from authors group by au_lname

Question4:Can you create a cross-tab 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      0
Bookbeat                 55     25     30     0      0
Doc-U-Mat: Quality Laundry and Books   85     0      85     0      0
Fricative Bookshop            60     35     0      0      25
Total                  250     60     165     0      25

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved