当前位置: 首页 > 图文教程 > 数据库 > MSSQL > 某外企SQL Server面试题

MSSQL
如何取得一个表的所有字段名用逗号分割
Sql Server下数据库链接的使用方法
修改SQL SERVER内置存储过程
oracle中解决汉字无法显示、输入问题
两台SQL Server数据同步解决方案
SQL服务器内存有两种基本管理方法:动态分配和静态分配
SQL Server里函数的两种用法(可以代替游标)
sql server的cube操作符使用详解
SQL中HAVING从句的用法
使用T_SQL脚本创建SQLServer2000后台计划作业任务
SQL Server中合并用户日志表的方法
SQL Server 本机 Web 服务的使用方案
Windows XP下安装SQL2000企业版
三步堵死SQL注入漏洞
HOW TO:使用 Osql 工具管理 SQL Server 桌面引擎 (MSDE 2000
如何获取SQL Server数据库里表的占用容量大小
查询表主键外键信息的SQL
SQL Server根据查询结果,生成XML文件
SQL Server2005 Analysis服务实践之起步
关于对sql2000查询结果进行相关度排序的测试

MSSQL 中的 某外企SQL Server面试题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 67 ::
收藏到网摘: n/a

Question 1:Can you use a batch SQL or store procedure to calculating the Number of Days in a Month
Answer 1:
找出当月的天数
selectdatepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) asvarchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))

Question2:Can you use a SQL statement to calculating it!
Howcan 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 otherprices?
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!
Howcan I get the report about sale quality for each store and each quarterand the total sale quality for each quarter at year 1993?
You can use the table sales and stores in datatabase pubs.
TableSales record all sale detail item for each store. Column store_id isthe id of each store, ord_date is the order date of each sale item, andcolumn qty is the sale qulity. Table stores record all storeinformation.
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