某外企SQL Server面試題
--> Title : 某外企SQL Server面試題
--> Author : wufeng4552
--> Date : 2010-1-15
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 cro
相关文档:
ch02
--3-4
select * from orders
where 'México D.F.' in
(select City
from Customers
where Orders.CustomerID = Customers.CustomerID )
--3-5
select * from orders
where 'usa' =
(select Country
from Customers
where Orders.CustomerID = Customers.CustomerID )
--4-1
select * from or ......
最近用到日期范围的查询,用到了between,但是发现如果日期带时间的话,BETWEEN '2010-1-4' AND
'2010-1-4'这样的语句是查不到数据的,后来想到了一种改进方法,供大家参考。
如下:
BETWEEN '2010-1-4' AND DATEADD(day, 1, '2010-1-4')
用了DATEADD以后,效果很不错 ......
你是否遇到过 想在 字符串里面写 SQL语句,但是总是遇到 某些符号不会写.
比如说在字符串里面写个变量.
like: str sql="select * from abc where id= ' "++" ' "
id的变量应 先用单引号然后“+”号。
今天遇到个很长的SQL语句,而且SQL语句里面嵌套了字符串。当时根本不会写 ......
1、表操作。
1.1 现有表增加字段
alter table TableName add
columnName1 varchar(2) NULL,
columnName2 varchar(2) NULL,
columnName3 varchar(2) NULL
注意:不用加Colu ......
转自:http://tech.ddvip.com/2007-05/117955341625057.html
检查各种变化
我在设计数据库的时候会考虑到哪些数据字段将来可能会发生变更。比方说,姓氏就是如此(注意是西方人的姓氏,比如女性结婚后从夫姓等)。所以,在建立系统存储客户信息时,我倾向于在单独的一个数据表里存储姓氏字段,而且还附加起始日和终止 ......